From 0096bbcec66a459cb7af908a2316a507f6fc26d1 Mon Sep 17 00:00:00 2001 From: Paulo Antunes Date: Sat, 9 May 2020 18:13:22 +0200 Subject: [PATCH] #64 Trial & Error --- CHANGELOG.md | 3 +- requirements.txt | 1 + xtcryptosignals/settings.py | 2 ++ xtcryptosignals/settings_exchanges.py | 7 +++++ xtcryptosignals/tasks/exchanges/kucoin.py | 34 ++++++++++++++++++++ xtcryptosignals/tasks/schemas/kucoin.py | 38 +++++++++++++++++++++++ xtcryptosignals/tasks/settings_local.py | 10 ++++-- 7 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 xtcryptosignals/tasks/exchanges/kucoin.py create mode 100644 xtcryptosignals/tasks/schemas/kucoin.py diff --git a/CHANGELOG.md b/CHANGELOG.md index fb043355..f2a0658f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,10 @@ All changes will be registered here per release. ## [0.6.0] - Current date -Added exchange: +Added the following exchanges: * Bitstamp +* Kucoin Code fixes and improvements. diff --git a/requirements.txt b/requirements.txt index c67cf7f0..13483880 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,6 +22,7 @@ beautifulsoup4 millify py-etherscan-api cfscrape +python-kucoin # versioned library dependencies marshmallow==2.20.5 jsonschema==2.6.0 diff --git a/xtcryptosignals/settings.py b/xtcryptosignals/settings.py index 7256ff6c..aa4678ab 100644 --- a/xtcryptosignals/settings.py +++ b/xtcryptosignals/settings.py @@ -56,6 +56,7 @@ BITMAX, BILAXY, BITSTAMP, + KUCOIN, ) # noqa __all__ = [ @@ -77,6 +78,7 @@ "BITMAX", "BILAXY", "BITSTAMP", + "KUCOIN", "TICKER_SCHEDULE", "HISTORY_FREQUENCY", "PRICE_CHANGE_FREQUENCIES", diff --git a/xtcryptosignals/settings_exchanges.py b/xtcryptosignals/settings_exchanges.py index a1e7d6ff..2bca983a 100644 --- a/xtcryptosignals/settings_exchanges.py +++ b/xtcryptosignals/settings_exchanges.py @@ -24,6 +24,7 @@ BITMAX = "bitmax" BILAXY = "bilaxy" BITSTAMP = "bitstamp" +KUCOIN = "kucoin" EXCHANGES = [ @@ -42,6 +43,7 @@ BITMAX, BILAXY, BITSTAMP, + KUCOIN, ] @@ -87,6 +89,11 @@ {OKEX: {"pairs": [("BTC", "USDT"), ("ETH", "USDT"), ("LTC", "USDT"),]}} ) +# Kucoin +SYMBOLS_PER_EXCHANGE.append( + {KUCOIN: {"pairs": [("BTC", "USDT"), ("ETH", "USDT"),]}} +) + # BIBOX SYMBOLS_PER_EXCHANGE.append( {BIBOX: {"pairs": [("BTC", "USDT"), ("ETH", "USDT"), ("LTC", "USDT"),]}} diff --git a/xtcryptosignals/tasks/exchanges/kucoin.py b/xtcryptosignals/tasks/exchanges/kucoin.py new file mode 100644 index 00000000..84e79397 --- /dev/null +++ b/xtcryptosignals/tasks/exchanges/kucoin.py @@ -0,0 +1,34 @@ +__author__ = "Paulo Antunes" +__copyright__ = "Copyright 2018, XTCryptoSignals" +__credits__ = [ + "Paulo Antunes", +] +__license__ = "GPL" +__maintainer__ = "Paulo Antunes" +__email__ = "pjmlantunes@gmail.com" + + +from kucoin.client import Client +from kucoin.exceptions import KucoinAPIException +from xtcryptosignals.tasks import settings as s + + +class Kucoin: + def __init__(self): + self.client = Client(s.KUCOIN_API_KEY, s.KUCOIN_API_SECRET, s.KUCOIN_API_PASSPHRASE) + + def get_ticker(self, symbol): + _symbol = "-".join(symbol) + + try: + item = self.client.get_ticker(_symbol) + except (KucoinAPIException, Exception) as err: + raise ValueError(str(err)) + + try: + item.update(self.client.get_24hr_stats(_symbol)) + except (KucoinAPIException, Exception) as err: + raise ValueError(str(err)) + + item.update(ticker=symbol[0]) + return item diff --git a/xtcryptosignals/tasks/schemas/kucoin.py b/xtcryptosignals/tasks/schemas/kucoin.py new file mode 100644 index 00000000..2a74fd38 --- /dev/null +++ b/xtcryptosignals/tasks/schemas/kucoin.py @@ -0,0 +1,38 @@ +__author__ = "Paulo Antunes" +__copyright__ = "Copyright 2018, XTCryptoSignals" +__credits__ = [ + "Paulo Antunes", +] +__license__ = "GPL" +__maintainer__ = "Paulo Antunes" +__email__ = "pjmlantunes@gmail.com" + + +from marshmallow import ( + fields, + pre_load, + post_load, +) +from xtcryptosignals.tasks.schemas.base import BaseSchema +from xtcryptosignals.tasks import settings as s + + +class Kucoin(BaseSchema): + symbol = fields.Str(required=True) + source = fields.Str(required=True) + last = fields.Float(required=True, attribute="price") + vol = fields.Float(required=True, attribute="volume_24h") + high = fields.Float(required=True, attribute="highest_price_24h") + low = fields.Float(required=True, attribute="lowest_price_24h") + + @pre_load + def pre_load(self, data): + data["source"] = s.KUCOIN + data["symbol"] = data["symbol"].replace("-", "") + data["vol"] = float(data["vol"]) * float(data["last"]) + return data + + @post_load + def post_load(self, data): + super().post_load(data) + return data diff --git a/xtcryptosignals/tasks/settings_local.py b/xtcryptosignals/tasks/settings_local.py index b5730dc9..a878b85f 100644 --- a/xtcryptosignals/tasks/settings_local.py +++ b/xtcryptosignals/tasks/settings_local.py @@ -8,5 +8,11 @@ __email__ = "pjmlantunes@gmail.com" -BINANCE_API_KEY = "" # Add Personal Binance API KEY -BINANCE_API_SECRET = "" # Add Personal Binance API SECRET +# Add the following Personal Exchange keys in order to be able to Trade + +BINANCE_API_KEY = "" +BINANCE_API_SECRET = "" + +KUCOIN_API_KEY = "" +KUCOIN_API_SECRET = "" +KUCOIN_API_PASSPHRASE = ""