Ruff
This commit is contained in:
parent
c1ae958458
commit
39cee8c601
|
@ -132,6 +132,7 @@ class TradeOrderDetails:
|
||||||
order_id: object
|
order_id: object
|
||||||
raw_order_details: object
|
raw_order_details: object
|
||||||
|
|
||||||
|
|
||||||
@enforce_typing.enforce_types
|
@enforce_typing.enforce_types
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class WithdrawalDetails:
|
class WithdrawalDetails:
|
||||||
|
@ -140,6 +141,7 @@ class WithdrawalDetails:
|
||||||
executed_time: datetime.datetime
|
executed_time: datetime.datetime
|
||||||
raw_details: object
|
raw_details: object
|
||||||
|
|
||||||
|
|
||||||
@enforce_typing.enforce_types
|
@enforce_typing.enforce_types
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class DepositDetails:
|
class DepositDetails:
|
||||||
|
@ -148,6 +150,7 @@ class DepositDetails:
|
||||||
executed_time: datetime.datetime
|
executed_time: datetime.datetime
|
||||||
raw_details: object
|
raw_details: object
|
||||||
|
|
||||||
|
|
||||||
@enforce_typing.enforce_types
|
@enforce_typing.enforce_types
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class DoubleRegister:
|
class DoubleRegister:
|
||||||
|
|
|
@ -7,11 +7,18 @@ from collections.abc import Iterator
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
import fin_defs
|
import fin_defs
|
||||||
from fin_defs import AssetAmount
|
|
||||||
import kucoin.client
|
import kucoin.client
|
||||||
|
from fin_defs import AssetAmount
|
||||||
|
|
||||||
from .data import (DepoFetcher, DepoGroup, DepoSingle, TradeOrderDetails,
|
from .data import (
|
||||||
WithdrawalDetails, DepositDetails, DoubleRegister)
|
DepoFetcher,
|
||||||
|
DepoGroup,
|
||||||
|
DepoSingle,
|
||||||
|
DepositDetails,
|
||||||
|
DoubleRegister,
|
||||||
|
TradeOrderDetails,
|
||||||
|
WithdrawalDetails,
|
||||||
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -21,8 +28,11 @@ def parse_asset_from_ticker(ticker: str) -> fin_defs.Asset:
|
||||||
return fin_defs.CryptoCurrency('KCS', coingecko_id='kucoin-shares')
|
return fin_defs.CryptoCurrency('KCS', coingecko_id='kucoin-shares')
|
||||||
return fin_defs.WELL_KNOWN_SYMBOLS[ticker]
|
return fin_defs.WELL_KNOWN_SYMBOLS[ticker]
|
||||||
|
|
||||||
|
|
||||||
def order_from_json(order_details: dict):
|
def order_from_json(order_details: dict):
|
||||||
(asset, base_asset) = [parse_asset_from_ticker(a) for a in order_details['symbol'].split('-')]
|
(asset, base_asset) = [
|
||||||
|
parse_asset_from_ticker(a) for a in order_details['symbol'].split('-')
|
||||||
|
]
|
||||||
|
|
||||||
# Convert from kucoin results
|
# Convert from kucoin results
|
||||||
if order_details['side'] == 'buy':
|
if order_details['side'] == 'buy':
|
||||||
|
@ -190,10 +200,14 @@ class KucoinDepoFetcher(DepoFetcher):
|
||||||
tz=datetime.UTC,
|
tz=datetime.UTC,
|
||||||
)
|
)
|
||||||
|
|
||||||
withdrawals.append(WithdrawalDetails(AssetAmount(withdrawn_asset, withdrawn_amount),
|
withdrawals.append(
|
||||||
|
WithdrawalDetails(
|
||||||
|
AssetAmount(withdrawn_asset, withdrawn_amount),
|
||||||
AssetAmount(fee_asset, fee_amount),
|
AssetAmount(fee_asset, fee_amount),
|
||||||
executed_time,
|
executed_time,
|
||||||
item))
|
item,
|
||||||
|
),
|
||||||
|
)
|
||||||
del item
|
del item
|
||||||
|
|
||||||
return withdrawals
|
return withdrawals
|
||||||
|
@ -212,9 +226,14 @@ class KucoinDepoFetcher(DepoFetcher):
|
||||||
tz=datetime.UTC,
|
tz=datetime.UTC,
|
||||||
)
|
)
|
||||||
|
|
||||||
deposits.append(DepositDetails(AssetAmount(deposit_asset, deposit_amount),
|
deposits.append(
|
||||||
|
DepositDetails(
|
||||||
|
AssetAmount(deposit_asset, deposit_amount),
|
||||||
AssetAmount(fee_asset, fee_amount),
|
AssetAmount(fee_asset, fee_amount),
|
||||||
executed_time, item))
|
executed_time,
|
||||||
|
item,
|
||||||
|
),
|
||||||
|
)
|
||||||
del item
|
del item
|
||||||
|
|
||||||
return deposits
|
return deposits
|
||||||
|
@ -235,9 +254,15 @@ class KucoinDepoFetcher(DepoFetcher):
|
||||||
spot_trades = self._get_historic_spot_orders()
|
spot_trades = self._get_historic_spot_orders()
|
||||||
|
|
||||||
double_registers = []
|
double_registers = []
|
||||||
double_registers += [DoubleRegister(d.deposit, None, d.executed_time) for d in deposits]
|
double_registers += [
|
||||||
double_registers += [DoubleRegister(None, d.withdrawn, d.executed_time) for d in withdrawals]
|
DoubleRegister(d.deposit, None, d.executed_time) for d in deposits
|
||||||
double_registers += [DoubleRegister(d.input, d.output, d.executed_time) for d in spot_trades]
|
]
|
||||||
|
double_registers += [
|
||||||
|
DoubleRegister(None, d.withdrawn, d.executed_time) for d in withdrawals
|
||||||
|
]
|
||||||
|
double_registers += [
|
||||||
|
DoubleRegister(d.input, d.output, d.executed_time) for d in spot_trades
|
||||||
|
]
|
||||||
double_registers.sort(key=lambda x: x.executed_time)
|
double_registers.sort(key=lambda x: x.executed_time)
|
||||||
return double_registers
|
return double_registers
|
||||||
|
|
||||||
|
@ -253,7 +278,6 @@ class KucoinDepoFetcher(DepoFetcher):
|
||||||
order_details = self._get_order_with_retries(order_id, num_retries=10)
|
order_details = self._get_order_with_retries(order_id, num_retries=10)
|
||||||
return order_from_json(order_details)
|
return order_from_json(order_details)
|
||||||
|
|
||||||
|
|
||||||
def _get_order_with_retries(
|
def _get_order_with_retries(
|
||||||
self,
|
self,
|
||||||
order_id: str,
|
order_id: str,
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import datetime
|
import datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
import fin_defs
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import fin_depo
|
import fin_depo
|
||||||
|
@ -19,6 +17,7 @@ fin_depo.defi_kucoin.logger.setLevel('INFO')
|
||||||
|
|
||||||
NOW = datetime.datetime.now(tz=datetime.UTC)
|
NOW = datetime.datetime.now(tz=datetime.UTC)
|
||||||
|
|
||||||
|
|
||||||
def get_fetcher() -> fin_depo.defi_kucoin.KucoinDepoFetcher:
|
def get_fetcher() -> fin_depo.defi_kucoin.KucoinDepoFetcher:
|
||||||
return fin_depo.defi_kucoin.KucoinDepoFetcher(
|
return fin_depo.defi_kucoin.KucoinDepoFetcher(
|
||||||
secrets.KUCOIN_KEY,
|
secrets.KUCOIN_KEY,
|
||||||
|
@ -26,6 +25,7 @@ def get_fetcher() -> fin_depo.defi_kucoin.KucoinDepoFetcher:
|
||||||
secrets.KUCOIN_PASS,
|
secrets.KUCOIN_PASS,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@needs_secrets
|
@needs_secrets
|
||||||
def test_get_depo():
|
def test_get_depo():
|
||||||
"""Can inspect kucoin depository."""
|
"""Can inspect kucoin depository."""
|
||||||
|
@ -35,21 +35,25 @@ def test_get_depo():
|
||||||
for nested_depo in depo.nested:
|
for nested_depo in depo.nested:
|
||||||
assert isinstance(nested_depo, fin_depo.data.DepoSingle)
|
assert isinstance(nested_depo, fin_depo.data.DepoSingle)
|
||||||
|
|
||||||
|
|
||||||
@needs_secrets
|
@needs_secrets
|
||||||
def test_get_withdrawals():
|
def test_get_withdrawals():
|
||||||
withdrawals = get_fetcher()._get_withdrawals()
|
withdrawals = get_fetcher()._get_withdrawals()
|
||||||
assert len(withdrawals) > 0
|
assert len(withdrawals) > 0
|
||||||
|
|
||||||
|
|
||||||
@needs_secrets
|
@needs_secrets
|
||||||
def test_get_deposits():
|
def test_get_deposits():
|
||||||
deposits = get_fetcher()._get_deposits()
|
deposits = get_fetcher()._get_deposits()
|
||||||
assert len(deposits) > 0
|
assert len(deposits) > 0
|
||||||
|
|
||||||
|
|
||||||
@needs_secrets
|
@needs_secrets
|
||||||
def test_get_historic_spot_orders():
|
def test_get_historic_spot_orders():
|
||||||
orders = get_fetcher()._get_historic_spot_orders()
|
orders = get_fetcher()._get_historic_spot_orders()
|
||||||
assert next(orders)
|
assert next(orders)
|
||||||
|
|
||||||
|
|
||||||
@needs_secrets
|
@needs_secrets
|
||||||
def test_get_double_registers():
|
def test_get_double_registers():
|
||||||
double_registers = get_fetcher()._get_double_registers()
|
double_registers = get_fetcher()._get_double_registers()
|
||||||
|
|
|
@ -106,4 +106,3 @@ def test_place_sell_side_order():
|
||||||
assert order_details.fee_amount is not None
|
assert order_details.fee_amount is not None
|
||||||
|
|
||||||
assert NOW <= order_details.executed_time <= NOW + datetime.timedelta(minutes=10)
|
assert NOW <= order_details.executed_time <= NOW + datetime.timedelta(minutes=10)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user