Skip to content

Commit

Permalink
[Kucoin] Add implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Herklos committed Oct 27, 2021
1 parent 113b507 commit 562bed0
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def gateio_exchange():
return ExchangeWrapper(ccxt.async_support.gateio())


@pytest.fixture
def kucoin_exchange():
return ExchangeWrapper(ccxt.async_support.kucoin())


@pytest.fixture
def default_exchange():
"""
Expand Down
23 changes: 23 additions & 0 deletions tests/exchanges/test_kucoin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Drakkar-Software trading-backend
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
import ccxt.async_support
import trading_backend.exchanges as exchanges
from tests import kucoin_exchange


def test_get_name(kucoin_exchange):
assert exchanges.Kucoin(kucoin_exchange).get_name() == ccxt.async_support.kucoin().name.lower()

2 changes: 1 addition & 1 deletion tests/test_exchanges_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ def test_get_exchanges():
for exchange_class in exchanges_by_name.values()
for exchange in exchange_class.__subclasses__()
})
assert len(exchanges_by_name) == 7
assert len(exchanges_by_name) == 8
assert trading_backend.exchange_factory._get_exchanges() == exchanges_by_name
6 changes: 6 additions & 0 deletions trading_backend/exchanges/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
HuobiPro
)

from trading_backend.exchanges import kucoin
from trading_backend.exchanges.kucoin import (
Kucoin
)

__all__ = [
"Exchange",
"Binance",
Expand All @@ -56,4 +61,5 @@
"GateIO",
"Huobi",
"HuobiPro",
"Kucoin",
]
43 changes: 43 additions & 0 deletions trading_backend/exchanges/kucoin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Drakkar-Software trading-backend
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
import trading_backend.exchanges as exchanges


class Kucoin(exchanges.Exchange):
SPOT_ID = (None, None)
MARGIN_ID = (None, None)
FUTURE_ID = (None, None)
IS_SPONSORING = True
HEADER_PART = "partner"
HEADER_PART_ID = "id"
HEADER_PART_SECRET = "secret"

@classmethod
def get_name(cls):
return 'kucoin'

def get_orders_parameters(self, params=None) -> dict:
if self.HEADER_PART not in self._exchange.connector.client.options:
self._exchange.connector.client.options[self.HEADER_PART] = {}
options_broker = self._exchange.connector.client.options[self.HEADER_PART]
if options_broker.get(self.HEADER_PART_ID, None) != self._get_id():
self._exchange.connector.client.options[self.HEADER_PART][self.HEADER_PART_ID],\
self._exchange.connector.client.options[self.HEADER_PART][self.HEADER_PART_SECRET] = self._get_id()
return super().get_orders_parameters(params)

async def _inner_is_valid_account(self) -> (bool, str):
# Nothing to do
return await super()._inner_is_valid_account()

0 comments on commit 562bed0

Please sign in to comment.