diff --git "a/.github/workflows/\360\237\221\267\342\200\215\342\231\202\357\270\217Flow.yml" "b/.github/workflows/\360\237\221\267\342\200\215\342\231\202\357\270\217Flow.yml" index e47c3445..89122ed9 100644 --- "a/.github/workflows/\360\237\221\267\342\200\215\342\231\202\357\270\217Flow.yml" +++ "b/.github/workflows/\360\237\221\267\342\200\215\342\231\202\357\270\217Flow.yml" @@ -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 @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 53cd99e9..44272121 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ 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 @@ -16,7 +17,8 @@ Key features: ## 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) @@ -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/) diff --git a/docs/conf.py b/docs/conf.py index f14621cb..dd63e19d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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'] diff --git a/findmyorder/default_settings.toml b/findmyorder/default_settings.toml index 860e6ce3..4cac03c5 100644 --- a/findmyorder/default_settings.toml +++ b/findmyorder/default_settings.toml @@ -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" @@ -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" }, @@ -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 \ No newline at end of file diff --git a/findmyorder/main.py b/findmyorder/main.py index fb1574f9..939634c4 100644 --- a/findmyorder/main.py +++ b/findmyorder/main.py @@ -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 @@ -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) @@ -111,6 +110,7 @@ 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: @@ -118,6 +118,10 @@ async def replace_instrument(self, order): 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): diff --git a/tests/test_unit.py b/tests/test_unit.py index 1918e679..ee43411d 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -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""" @@ -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, @@ -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): @@ -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