Skip to content

Commit

Permalink
Merge pull request #230 from mraniki/dev
Browse files Browse the repository at this point in the history
📝  Doc config and  🔧 mapping
  • Loading branch information
mraniki committed Jul 3, 2023
2 parents bf8c3e1 + 0da7314 commit cd9eebe
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 58 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/👷‍♂️Flow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ jobs:
needs: [lint]
uses: mraniki/coding_toolset/.github/workflows/🐍Build.yml@main
secrets: inherit
prerelease:
needs: [build]
uses: mraniki/coding_toolset/.github/workflows/🥷Prerelease.yml@main
secrets: inherit
release:
needs: [build]
uses: mraniki/coding_toolset/.github/workflows/📦Release.yml@main
Expand All @@ -32,7 +36,6 @@ jobs:
needs: [release]
uses: mraniki/coding_toolset/.github/workflows/🐳Docker.yml@main
secrets: inherit
#deploy:
#needs: [docker]
#uses: mraniki/coding_toolset/.github/workflows/☁️Deploy.yml@main
#secrets: inherit
# deploy:
# needs: [docker]
# uses: mraniki/coding_toolset/.github/workflows/☁️Deploy.yml@main
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ Key features:

- Identify an order with word `BUY SELL LONG SHORT` or your own `Bull`, `to the moon`, `pump` via config file
- Parse and return a structured order with action and instrument as mandatory
- Settings for custom option
- Capability to map a given instrument to a new one (e.g BTC to WBTC or ETHUSD to ETH)
- Settings for custom options

## Install

`pip install findmyorder`

## How to use it

```
```python
>>> from findmyorder import FindMyOrder
fmo = FindMyOrder()
msg_order = "buy EURUSD sl=1000 tp=1000 q=1 comment=FOMC"
order = await fmo.get_order(msg_order)
Expand All @@ -29,9 +31,8 @@ order = await fmo.get_order(msg_order)

### Real use case

[TalkyTrader, submit trading order to CEX & DEX with messaging platform (Telegram, Matrix and Discord)](https://github.com/mraniki/tt)
[TalkyTrader](https://github.com/mraniki/tt)

## Documentation


[![wiki](https://img.shields.io/badge/🪙🗿-wiki-0080ff)](https://talkytrader.gitbook.io/talky/)
13 changes: 5 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon'
'sphinx.ext.napoleon',
'sphinx.ext.intersphinx'
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = []
master_doc = 'index'

language = "en"

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output


html_theme = "furo"
html_static_path = ["_static"]
add_module_names = False
autoapi_python_class_content = "both"
python_use_unqualified_type_names = True
html_static_path = ['_static']
75 changes: 49 additions & 26 deletions findmyorder/default_settings.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,51 @@
###########################################
### DEFAULT SETTINGS ###
###########################################
# Any of those settings can be overwritten
# by the user.
# To overwrite a setting, create a settings.toml
# or load the settings from .env file or vars.
# As an example, to change the port settings:
# settings.toml
# [default]
# port = 8081
# or via ENVVARS
# export TT_PORT=8081


[default]
VALUE = "Production - Default"
findmyorder_enabled = true
action_identifier = "BUY SELL LONG SHORT"
# action_in_identifier = "BUY LONG"
# action_out_identifier = "SELL SHORT"
# actions = [
# { identifier = "BUY", type = "IN" },
# { identifier = "SELL", type = "OUT" },
# { identifier = "LONG", type = "IN" },
# { identifier = "SHORT", type = "OUT" }
# ]
stop_loss_identifier = "sl="
take_profit_identifier = 'tp='
quantity_identifier = 'q='
order_type_identifier = "spot future margin"
leverage_type_identifier = "cross isolated"
comment_identifier = "comment="
stop_loss = 1000
take_profit = 1000
quantity = 1
instrument_mapping = true
mapping = [
{ id = "GOLD", alt = "XAUUSD" },
{ id = "SILVER", alt = "XAGUSD" },
{ id = "BTC", alt = "WBTC" },
{ id = "ETH", alt = "WETH" },
]



[testing]
VALUE = "On Testing"
findmyorder_enabled = true
action_identifier = "BUY SELL LONG SHORT"
# action_in_identifier = "BUY LONG"
Expand All @@ -20,22 +67,8 @@ take_profit = 1000
quantity = 1
instrument_mapping = true
mapping = [
{ id = "EURUSD", alt = "EURUSD" },
{ id = "USDJPY", alt = "USDJPY" },
{ id = "GBPUSD", alt = "GBPUSD" },
{ id = "USDCHF", alt = "USDCHF" },
{ id = "AUDUSD", alt = "AUDUSD" },
{ id = "NZDUSD", alt = "NZDUSD" },
{ id = "USDCAD", alt = "USDCAD" },
{ id = "GBPJPY", alt = "GBPJPY" },
{ id = "EURCAD", alt = "EURCAD" },
{ id = "EURAUD", alt = "EURAUD" },
{ id = "EURGBP", alt = "EURGBP" },
{ id = "EURJPY", alt = "EURJPY" },
{ id = "CADJPY", alt = "CADJPY" },
{ id = "GOLD", alt = "XAUUSD" },
{ id = "SILVER", alt = "XAGUSD" },
{ id = "COPPER", alt = "COPPER" },
{ id = "BRENTOIL", alt = "UKOil" },
{ id = "CRUDEOIL", alt = "USOil" },
{ id = "NATURALGAS", alt = "NGAS" },
Expand All @@ -55,18 +88,8 @@ mapping = [
{ id = "CAC40", alt = "F40" },
{ id = "AAPL", alt = "AAPL" },
{ id = "TSLA", alt = "TSLA" },
{ id = "META", alt = "META" },
{ id = "MSFT", alt = "MSFT" },
{ id = "BTC", alt = "BTCUSDT" },
{ id = "ETH", alt = "ETHUSDT" },
{ id = "BTC", alt = "WBTC" },
{ id = "ETH", alt = "WETH" },
{ id = "BNB", alt = "BNB/USDT" },
{ id = "MATIC", alt = "MATIC-PERP" }
]


# [mapping]
# BTC = "BTCUSDT"


[testing]
quantity = 10
8 changes: 6 additions & 2 deletions findmyorder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pyparsing import (
Combine, Optional, Word, alphas,
nums, one_of, pyparsing_common, Suppress)

from findmyorder import __version__
from .config import settings


Expand All @@ -31,7 +31,6 @@ async def search(
return True
return False


async def contains_emoji(self, input_string: str) -> bool:
"""Check if the input string contains an emoji."""
return any(emoji.is_emoji(character) for character in input_string)
Expand Down Expand Up @@ -111,13 +110,18 @@ async def get_order(
return None

async def replace_instrument(self, order):
""" replace instrument by an alternative instrument """
instrument = order["instrument"]
for item in settings.mapping:
if item["id"] == instrument:
order["instrument"] = item["alt"]
break
return order

async def get_info(self):
""" get info about the class """
return f"{__class__.__name__} {__version__}\n"

# Grammar
# class TradingGrammar:
# def __init__(self):
Expand Down
32 changes: 18 additions & 14 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@
from findmyorder import FindMyOrder, settings


@pytest.fixture


@pytest.fixture(scope="session", autouse=True)
def set_test_settings():
settings.configure(FORCE_ENV_FOR_DYNACONF="testing")


@pytest.fixture(name="fmo")
def fmo():
"""return fmo"""
return FindMyOrder()

@pytest.fixture
def fmo_custom():
"""return custom fmo"""
with patch("findmyorder.config.settings", autospec=True):
settings.instrument_mapping = True
settings.quantity = 10
return FindMyOrder()

@pytest.fixture
def order():
"""return valid order"""
Expand Down Expand Up @@ -62,7 +61,7 @@ def result_crypto_order():
"""return standard expected results"""
return {
"action": "SHORT",
"instrument": "ETHUSDT",
"instrument": "WETH",
"stop_loss": 1000,
"take_profit": 1000,
"quantity": 10,
Expand Down Expand Up @@ -91,6 +90,12 @@ def invalid_order():
"""return fmo"""
return "This is not an order"

@pytest.mark.asyncio
async def test_settings():
"""Search Testing"""
assert settings.VALUE == "On Testing"
assert settings.findmyorder_enabled == True


@pytest.mark.asyncio
async def test_search_valid_order(fmo, crypto_order):
Expand Down Expand Up @@ -170,15 +175,14 @@ async def test_short_valid_get_order(fmo, short_order, result_order):

@pytest.mark.asyncio
async def test_mapping_order(
fmo_custom,
fmo,
crypto_short_order,
result_crypto_order):
"""replace instrument Testing"""
result = await fmo_custom.get_order(crypto_short_order)
result = await fmo.get_order(crypto_short_order)
print(result)
assert settings.instrument_mapping
assert settings.instrument_mapping == True
assert result["instrument"] == result_crypto_order["instrument"]
assert int(result["quantity"]) == 10
assert type(result["timestamp"] is datetime)

@pytest.mark.asyncio
Expand Down

0 comments on commit cd9eebe

Please sign in to comment.