From 4730ba21a440d9e5565b77edefa729760561953c Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Mon, 3 Jul 2023 16:22:51 +0200 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=94=A7=20=20config=20=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- findmyorder/default_settings.toml | 84 +++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 4 deletions(-) diff --git a/findmyorder/default_settings.toml b/findmyorder/default_settings.toml index 860e6ce..64fd996 100644 --- a/findmyorder/default_settings.toml +++ b/findmyorder/default_settings.toml @@ -1,4 +1,20 @@ +########################################### +### 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" @@ -64,9 +80,69 @@ mapping = [ ] -# [mapping] -# BTC = "BTCUSDT" - [testing] -quantity = 10 \ No newline at end of file +VALUE = "On Testing" +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 = "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" }, + { id = "GERMANY40", alt = "DE30" }, + { id = "US500", alt = "US500" }, + { id = "US2000", alt = "US2000" }, + { id = "DOLLARINDEX", alt = "DXY" }, + { id = "VIX", alt = "VIX" }, + { id = "US30", alt = "DJ30" }, + { id = "US100", alt = "USTEC" }, + { id = "EU50", alt = "STOXX50" }, + { id = "UK100", alt = "UK100" }, + { id = "HK50", alt = "HK50" }, + { id = "AU200", alt = "AUS200" }, + { id = "NIKKEI225", alt = "JPN225" }, + { id = "NIFTY50", alt = "IND50" }, + { 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 = "BNB", alt = "BNB/USDT" }, + { id = "MATIC", alt = "MATIC-PERP" } +] From ad5ba39aaa4bd8449f4703a8c05beb60db7cc428 Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Mon, 3 Jul 2023 19:04:03 +0200 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=91=B7=20CI=20Change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\267\342\200\215\342\231\202\357\270\217Flow.yml" | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 e47c344..89122ed 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 From 90915d80f272e0f07c5ea3a0d2f224c43853271e Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Mon, 3 Jul 2023 19:09:32 +0200 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=93=9D=20=20Doc=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/conf.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index f14621c..dd63e19 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'] From 2835f453c434ffd26dcac7e4df22ff4eb64676ae Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Mon, 3 Jul 2023 19:41:31 +0200 Subject: [PATCH 4/7] =?UTF-8?q?=E2=9C=85=20added=20testing=20for=20mapping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 +++---- findmyorder/default_settings.toml | 40 ++++--------------------------- findmyorder/main.py | 4 +++- tests/test_unit.py | 31 ++++++++++++++---------- 4 files changed, 30 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 53cd99e..4427212 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/findmyorder/default_settings.toml b/findmyorder/default_settings.toml index 64fd996..6715f0c 100644 --- a/findmyorder/default_settings.toml +++ b/findmyorder/default_settings.toml @@ -36,22 +36,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" }, @@ -71,10 +57,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" } ] @@ -104,22 +88,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" }, @@ -139,10 +109,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" } ] diff --git a/findmyorder/main.py b/findmyorder/main.py index fb1574f..270b870 100644 --- a/findmyorder/main.py +++ b/findmyorder/main.py @@ -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) @@ -117,6 +116,9 @@ async def replace_instrument(self, order): order["instrument"] = item["alt"] break return order + + async def get_info(self): + return f"{__class__.__name__} {__version__}\n" # Grammar # class TradingGrammar: diff --git a/tests/test_unit.py b/tests/test_unit.py index 1918e67..95a578c 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,13 +175,13 @@ 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) From b0fb029e2931f3aa1894745e759f522f04b7e304 Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Mon, 3 Jul 2023 20:56:09 +0200 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=90=9B=20=20version=20import=20missin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- findmyorder/default_settings.toml | 21 --------------------- findmyorder/main.py | 2 +- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/findmyorder/default_settings.toml b/findmyorder/default_settings.toml index 6715f0c..4cac03c 100644 --- a/findmyorder/default_settings.toml +++ b/findmyorder/default_settings.toml @@ -38,29 +38,8 @@ instrument_mapping = true mapping = [ { id = "GOLD", alt = "XAUUSD" }, { id = "SILVER", alt = "XAGUSD" }, - { id = "BRENTOIL", alt = "UKOil" }, - { id = "CRUDEOIL", alt = "USOil" }, - { id = "NATURALGAS", alt = "NGAS" }, - { id = "GERMANY40", alt = "DE30" }, - { id = "US500", alt = "US500" }, - { id = "US2000", alt = "US2000" }, - { id = "DOLLARINDEX", alt = "DXY" }, - { id = "VIX", alt = "VIX" }, - { id = "US30", alt = "DJ30" }, - { id = "US100", alt = "USTEC" }, - { id = "EU50", alt = "STOXX50" }, - { id = "UK100", alt = "UK100" }, - { id = "HK50", alt = "HK50" }, - { id = "AU200", alt = "AUS200" }, - { id = "NIKKEI225", alt = "JPN225" }, - { id = "NIFTY50", alt = "IND50" }, - { id = "CAC40", alt = "F40" }, - { id = "AAPL", alt = "AAPL" }, - { id = "TSLA", alt = "TSLA" }, { id = "BTC", alt = "WBTC" }, { id = "ETH", alt = "WETH" }, - { id = "BNB", alt = "BNB/USDT" }, - { id = "MATIC", alt = "MATIC-PERP" } ] diff --git a/findmyorder/main.py b/findmyorder/main.py index 270b870..8d1c377 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 From a39429e54b00feb308c097540004be38c6fb08f6 Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Mon, 3 Jul 2023 21:31:51 +0200 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=92=AC=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- findmyorder/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/findmyorder/main.py b/findmyorder/main.py index 8d1c377..939634c 100644 --- a/findmyorder/main.py +++ b/findmyorder/main.py @@ -110,14 +110,16 @@ 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 From 0da731461b55c3c418123bd76683f807decfb474 Mon Sep 17 00:00:00 2001 From: mraniki Date: Mon, 3 Jul 2023 21:42:26 +0200 Subject: [PATCH 7/7] :white_check_mark: added testing for mapping --- tests/test_unit.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_unit.py b/tests/test_unit.py index 95a578c..ee43411 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -183,7 +183,6 @@ async def test_mapping_order( print(result) 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