Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Commit

Permalink
fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxluigi committed Feb 17, 2021
1 parent 4339ead commit 08eabcc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
7 changes: 3 additions & 4 deletions django_crypto_trading_bot/trading_bot/models/order.py
Expand Up @@ -3,15 +3,13 @@
from typing import Optional

import pytz
from _pytest.mark.structures import Mark
from django.db import models
from django.db.models.manager import BaseManager

from django_crypto_trading_bot.trading_bot.models import market
from django_crypto_trading_bot.trading_bot.models.trade import Trade

from . import Account, Currency, Market
from .choices import OrderSide, OrderStatus, OrderType
from .choices import ExchangesOptions, OrderSide, OrderStatus, OrderType


class Order(models.Model):
Expand Down Expand Up @@ -92,7 +90,8 @@ def get_or_create_by_api_response(cctx_order: dict, account: Account) -> "Order"
amount=Decimal(cctx_order["amount"]),
filled=Decimal(cctx_order["filled"]),
market=Market.get_market(
symbol=cctx_order["symbol"], exchange=account.exchange
symbol=cctx_order["symbol"],
exchange=ExchangesOptions(account.exchange),
),
)

Expand Down
3 changes: 1 addition & 2 deletions django_crypto_trading_bot/trading_bot/models/trade.py
@@ -1,6 +1,5 @@
from datetime import datetime
from decimal import Decimal
from typing import Tuple

import pytz
from django.db import models
Expand Down Expand Up @@ -32,7 +31,7 @@ def cost(self):

@staticmethod
def get_or_create_by_api_response(
cctx_trade: dict, order: "trading_bot.Order"
cctx_trade: dict, order: "trading_bot.Order" # type: ignore
) -> "Trade":
"""
get or create a trade by a api response dict
Expand Down
4 changes: 2 additions & 2 deletions django_crypto_trading_bot/trading_bot/tests/fixtures.py
Expand Up @@ -60,8 +60,8 @@ def order_dict(order_id: str = "12345-67890:09876/54321") -> dict:
"remaining": 0.4, # remaining amount to fill
"cost": 0.076094524, # 'filled' * 'price' (filling price used where available)
"trades": [
trade_dict(trade_id=1),
trade_dict(trade_id=2),
trade_dict(trade_id="1"),
trade_dict(trade_id="2"),
], # a list of order trades/executions
"fee": { # fee info, if available
"currency": "BTC", # which currency the fee is (usually quote)
Expand Down
Expand Up @@ -5,6 +5,7 @@
from ccxt.base.exchange import Exchange

from django_crypto_trading_bot.trading_bot.models import Account, Market
from django_crypto_trading_bot.trading_bot.models.choices import ExchangesOptions

from ..factories import AccountFactory, EthBtcMarketFactory, MarketFactory

Expand Down Expand Up @@ -114,7 +115,8 @@ def test_get_market(self):

# get the market by symbol & exchange
market_get: Market = Market.get_market(
symbol=market_original.symbol, exchange=market_original.exchange
symbol=market_original.symbol,
exchange=ExchangesOptions(market_original.exchange),
)

# check if the right market was get from the database
Expand Down
Expand Up @@ -95,9 +95,9 @@ def test_get_or_create_by_api_response_create_order(self):
)
assert order.order_type == OrderType.LIMIT
assert order.side == OrderSide.BUY
self.assertAlmostEqual(order.price, Decimal.from_float(0.06917684), 8)
self.assertAlmostEqual(order.amount, Decimal.from_float(1.5), 8)
self.assertAlmostEqual(order.filled, Decimal.from_float(1.1), 8)
self.assertAlmostEqual(float(order.price), 0.06917684, 8)
self.assertAlmostEqual(float(order.amount), 1.5, 8)
self.assertAlmostEqual(float(order.filled), 1.1, 8)

# check if there trade was added
assert Trade.objects.filter(order=order).count() == 2
Expand All @@ -114,7 +114,7 @@ def test_get_or_create_by_api_response_update_order(self):
)

# check for updated properties
self.assertAlmostEqual(order_update.filled, Decimal.from_float(1.1), 8)
self.assertAlmostEqual(float(order_update.filled), 1.1, 8)
assert order_update.status == OrderStatus.OPEN

# check if order was updated
Expand Down
Expand Up @@ -78,8 +78,9 @@ def test_get_or_create_by_api_response_update_trade(self):
assert trade_update.taker_or_maker == TakerOrMaker.MAKER
assert trade_update.amount == Decimal.from_float(1)
assert trade_update.fee_currency.short == "BNB"
self.assertAlmostEqual(trade_update.fee_cost, Decimal.from_float(0.01), 8)
self.assertAlmostEqual(trade_update.fee_rate, Decimal.from_float(0.01), 8)
self.assertAlmostEqual(float(trade_update.fee_cost), 0.01, 8)
assert trade_update.fee_rate is not None
self.assertAlmostEqual(float(trade_update.fee_rate), 0.01, 8)

# get trade from database
assert trade_update == Trade.objects.get(pk=trade_update.pk)

0 comments on commit 08eabcc

Please sign in to comment.