Compare commits
No commits in common. "cc50cba21025a986a40a23ca8412d88e96d74034" and "29af8ff3710635e17f2a965fbb256be70d05d6be" have entirely different histories.
cc50cba210
...
29af8ff371
|
@ -4,7 +4,6 @@ import datetime
|
||||||
import logging
|
import logging
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
import time
|
|
||||||
import fin_defs
|
import fin_defs
|
||||||
import kucoin.client
|
import kucoin.client
|
||||||
|
|
||||||
|
@ -95,17 +94,13 @@ class KucoinDepoFetcher(DepoFetcher):
|
||||||
other accounts cannot be used.
|
other accounts cannot be used.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
|
----
|
||||||
- A fee will be paid to Kucoin, with the rate determined by your WIP
|
- A fee will be paid to Kucoin, with the rate determined by your WIP
|
||||||
level and the asset being traded.
|
level and the asset being traded.
|
||||||
- The full `input_amount` may not be used. Inspect the resulting
|
- The full `input_amount` may not be used. Inspect the resulting
|
||||||
`TradeOrderDetails` to see how much of the `input_amount` have been
|
`TradeOrderDetails` to see how much of the `input_amount` have been
|
||||||
used.
|
used.
|
||||||
|
|
||||||
References:
|
|
||||||
|
|
||||||
- POST Market Order: <https://www.kucoin.com/docs/rest/spot-trading/orders/place-order>
|
|
||||||
- GET Market Order by id: <https://www.kucoin.com/docs/rest/spot-trading/orders/get-order-details-by-orderid>
|
|
||||||
"""
|
"""
|
||||||
# Check requirements
|
# Check requirements
|
||||||
if not self.allow_trades:
|
if not self.allow_trades:
|
||||||
|
@ -136,17 +131,8 @@ class KucoinDepoFetcher(DepoFetcher):
|
||||||
del symbol, side, size, funds, input_amount
|
del symbol, side, size, funds, input_amount
|
||||||
|
|
||||||
# Determine order details
|
# Determine order details
|
||||||
return self._get_order_details(response['orderId'], input_asset, output_asset)
|
order_id = response['orderId']
|
||||||
|
order_details = self.kucoin_client.get_order(order_id)
|
||||||
def _get_order_details(self, order_id: str,
|
|
||||||
input_asset: fin_defs.Asset,
|
|
||||||
output_asset: fin_defs.Asset) -> TradeOrderDetails:
|
|
||||||
"""Determine the order details for the order with the given id.
|
|
||||||
|
|
||||||
Retries the order a few times, as KuCoin might not have propagated the
|
|
||||||
order through their systems.
|
|
||||||
"""
|
|
||||||
order_details = self._get_order_with_retries(order_id, num_retries=10)
|
|
||||||
|
|
||||||
# Convert from kucoin results
|
# Convert from kucoin results
|
||||||
if input_asset == fin_defs.USDT:
|
if input_asset == fin_defs.USDT:
|
||||||
|
@ -163,22 +149,6 @@ class KucoinDepoFetcher(DepoFetcher):
|
||||||
output_amount=output_amount_final,
|
output_amount=output_amount_final,
|
||||||
fee_asset=fin_defs.WELL_KNOWN_SYMBOLS[order_details['feeCurrency']],
|
fee_asset=fin_defs.WELL_KNOWN_SYMBOLS[order_details['feeCurrency']],
|
||||||
fee_amount=Decimal(order_details['fee']),
|
fee_amount=Decimal(order_details['fee']),
|
||||||
executed_time=datetime.datetime.fromtimestamp(
|
|
||||||
order_details['createdAt'] / 1000, tz=datetime.UTC
|
|
||||||
),
|
|
||||||
order_id=order_id,
|
order_id=order_id,
|
||||||
raw_order_details=order_details,
|
raw_order_details=order_details,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_order_with_retries(self, order_id: str, *, num_retries: int, sleep_between_tries:float = 1.0) -> dict:
|
|
||||||
"""Get the order details from KuCoin backend.
|
|
||||||
|
|
||||||
Retries the order a few times, as KuCoin might not have propagated the
|
|
||||||
order through their systems since it was sent.
|
|
||||||
"""
|
|
||||||
for _ in range(num_retries):
|
|
||||||
try:
|
|
||||||
return self.kucoin_client.get_order(order_id)
|
|
||||||
except kucoin.exceptions.KucoinAPIException as e: # noqa
|
|
||||||
time.sleep(sleep_between_tries)
|
|
||||||
return self.kucoin_client.get_order(order_id)
|
|
||||||
|
|
|
@ -15,6 +15,6 @@ NORDNET_PASSWORD = load_secret('NORDNET_PASSWORD')
|
||||||
KRAKEN_KEY = load_secret('KRAKEN_KEY')
|
KRAKEN_KEY = load_secret('KRAKEN_KEY')
|
||||||
KRAKEN_SECRET = load_secret('KRAKEN_SECRET')
|
KRAKEN_SECRET = load_secret('KRAKEN_SECRET')
|
||||||
|
|
||||||
KUCOIN_KEY = load_secret('KUCOIN_KEY_TRADING')
|
KUCOIN_KEY = load_secret('KUCOIN_KEY')
|
||||||
KUCOIN_SECRET = load_secret('KUCOIN_SECRET_TRADING')
|
KUCOIN_SECRET = load_secret('KUCOIN_SECRET')
|
||||||
KUCOIN_PASS = load_secret('KUCOIN_PASS_TRADING')
|
KUCOIN_PASS = load_secret('KUCOIN_PASS')
|
||||||
|
|
|
@ -13,6 +13,7 @@ needs_secrets = pytest.mark.skipif(
|
||||||
|
|
||||||
@needs_secrets
|
@needs_secrets
|
||||||
def test_get_depo():
|
def test_get_depo():
|
||||||
|
session = requests.Session()
|
||||||
fetcher = fin_depo.defi_kraken.KrakenDepoFetcher(
|
fetcher = fin_depo.defi_kraken.KrakenDepoFetcher(
|
||||||
secrets.KRAKEN_KEY,
|
secrets.KRAKEN_KEY,
|
||||||
secrets.KRAKEN_SECRET,
|
secrets.KRAKEN_SECRET,
|
||||||
|
|
|
@ -2,13 +2,12 @@ from decimal import Decimal
|
||||||
|
|
||||||
import fin_defs
|
import fin_defs
|
||||||
import pytest
|
import pytest
|
||||||
import datetime
|
|
||||||
|
|
||||||
import fin_depo
|
import fin_depo
|
||||||
|
|
||||||
from . import secrets
|
from . import secrets
|
||||||
|
|
||||||
TEST_MARKET_ORDERS = True
|
TEST_MARKET_ORDERS = False
|
||||||
|
|
||||||
needs_secrets = pytest.mark.skipif(
|
needs_secrets = pytest.mark.skipif(
|
||||||
not secrets.KUCOIN_KEY,
|
not secrets.KUCOIN_KEY,
|
||||||
|
@ -17,7 +16,6 @@ needs_secrets = pytest.mark.skipif(
|
||||||
|
|
||||||
fin_depo.defi_kucoin.logger.setLevel('INFO')
|
fin_depo.defi_kucoin.logger.setLevel('INFO')
|
||||||
|
|
||||||
NOW = datetime.datetime.now(tz=datetime.UTC)
|
|
||||||
|
|
||||||
@needs_secrets
|
@needs_secrets
|
||||||
def test_get_depo():
|
def test_get_depo():
|
||||||
|
@ -84,7 +82,6 @@ def test_place_buy_side_order():
|
||||||
assert order_details.fee_asset == fin_defs.USDT
|
assert order_details.fee_asset == fin_defs.USDT
|
||||||
assert order_details.fee_amount <= Decimal('0.0002')
|
assert order_details.fee_amount <= Decimal('0.0002')
|
||||||
|
|
||||||
assert NOW <= order_details.executed_time <= NOW + datetime.timedelta(minutes=10)
|
|
||||||
|
|
||||||
@needs_secrets
|
@needs_secrets
|
||||||
def test_place_sell_side_order():
|
def test_place_sell_side_order():
|
||||||
|
@ -118,5 +115,3 @@ def test_place_sell_side_order():
|
||||||
|
|
||||||
assert order_details.fee_asset == fin_defs.USDT
|
assert order_details.fee_asset == fin_defs.USDT
|
||||||
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)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user