Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kucoin] Add implementation #18

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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()

6 changes: 6 additions & 0 deletions trading_backend/exchanges/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
HuobiPro
)

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

__all__ = [
"Exchange",
"Binance",
Expand All @@ -62,4 +67,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()