Skip to content

Commit

Permalink
✅ added testing for mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
mraniki committed Jul 3, 2023
1 parent 90915d8 commit 2835f45
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 54 deletions.
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/)
40 changes: 4 additions & 36 deletions findmyorder/default_settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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" }
]
Expand Down Expand Up @@ -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" },
Expand All @@ -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" }
]
4 changes: 3 additions & 1 deletion findmyorder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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:
Expand Down
31 changes: 18 additions & 13 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,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)
Expand Down

0 comments on commit 2835f45

Please sign in to comment.