Changesets · Branches · Tags · Compare
| Changeset | 323404e4348f756ee62bfb0247f388133d2edb47cf1790d14c020fdb4727e6fd |
|---|---|
| Author | Matthias <xmatthias@outlook.com> · 2021-04-13 12:28 +02:00 |
| Committer | Matthias <xmatthias@outlook.com> · 2021-04-13 12:28 +02:00 |
| Parents | 55e614fcfc74 |
6 files changed
modified freqtrade/exchange/__init__.py +1 −0
| @@ -15,3 +15,4 @@ | ||
| 15 | 15 | validate_exchanges) |
| 16 | 16 | from freqtrade.exchange.ftx import Ftx |
| 17 | 17 | from freqtrade.exchange.kraken import Kraken |
| 18 | +from freqtrade.exchange.kucoin import Kucoin |
modified freqtrade/exchange/bittrex.py +0 −4
| @@ -12,10 +12,6 @@ | ||
| 12 | 12 | """ |
| 13 | 13 | Bittrex exchange class. Contains adjustments needed for Freqtrade to work |
| 14 | 14 | with this exchange. |
| 15 | - | |
| 16 | - Please note that this exchange is not included in the list of exchanges | |
| 17 | - officially supported by the Freqtrade development team. So some features | |
| 18 | - may still not work as expected. | |
| 19 | 15 | """ |
| 20 | 16 | |
| 21 | 17 | _ft_has: Dict = { |
modified freqtrade/exchange/exchange.py +11 −3
| @@ -63,6 +63,7 @@ | ||
| 63 | 63 | "trades_pagination": "time", # Possible are "time" or "id" |
| 64 | 64 | "trades_pagination_arg": "since", |
| 65 | 65 | "l2_limit_range": None, |
| 66 | + "l2_limit_range_required": True, # Allow Empty L2 limit (kucoin) | |
| 66 | 67 | } |
| 67 | 68 | _ft_has: Dict = {} |
| 68 | 69 | |
| @@ -1154,14 +1155,20 @@ | ||
| 1154 | 1155 | return self.fetch_order(order_id, pair) |
| 1155 | 1156 | |
| 1156 | 1157 | @staticmethod |
| 1157 | - def get_next_limit_in_list(limit: int, limit_range: Optional[List[int]]): | |
| 1158 | + def get_next_limit_in_list(limit: int, limit_range: Optional[List[int]], | |
| 1159 | + range_required: bool = True): | |
| 1158 | 1160 | """ |
| 1159 | 1161 | Get next greater value in the list. |
| 1160 | 1162 | Used by fetch_l2_order_book if the api only supports a limited range |
| 1161 | 1163 | """ |
| 1162 | 1164 | if not limit_range: |
| 1163 | 1165 | return limit |
| 1164 | - return min([x for x in limit_range if limit <= x] + [max(limit_range)]) | |
| 1166 | + | |
| 1167 | + result = min([x for x in limit_range if limit <= x] + [max(limit_range)]) | |
| 1168 | + if not range_required and limit > result: | |
| 1169 | + # Range is not required - we can use None as parameter. | |
| 1170 | + return None | |
| 1171 | + return result | |
| 1165 | 1172 | |
| 1166 | 1173 | @retrier |
| 1167 | 1174 | def fetch_l2_order_book(self, pair: str, limit: int = 100) -> dict: |
| @@ -1171,7 +1178,8 @@ | ||
| 1171 | 1178 | Returns a dict in the format |
| 1172 | 1179 | {'asks': [price, volume], 'bids': [price, volume]} |
| 1173 | 1180 | """ |
| 1174 | - limit1 = self.get_next_limit_in_list(limit, self._ft_has['l2_limit_range']) | |
| 1181 | + limit1 = self.get_next_limit_in_list(limit, self._ft_has['l2_limit_range'], | |
| 1182 | + self._ft_has['l2_limit_range_required']) | |
| 1175 | 1183 | try: |
| 1176 | 1184 | |
| 1177 | 1185 | return self._api.fetch_l2_order_book(pair, limit1) |
added freqtrade/exchange/kucoin.py +24 −0
| @@ -0,0 +1,24 @@ | ||
| 1 | +""" Kucoin exchange subclass """ | |
| 2 | +import logging | |
| 3 | +from typing import Dict | |
| 4 | + | |
| 5 | +from freqtrade.exchange import Exchange | |
| 6 | + | |
| 7 | + | |
| 8 | +logger = logging.getLogger(__name__) | |
| 9 | + | |
| 10 | + | |
| 11 | +class Kucoin(Exchange): | |
| 12 | + """ | |
| 13 | + Kucoin exchange class. Contains adjustments needed for Freqtrade to work | |
| 14 | + with this exchange. | |
| 15 | + | |
| 16 | + Please note that this exchange is not included in the list of exchanges | |
| 17 | + officially supported by the Freqtrade development team. So some features | |
| 18 | + may still not work as expected. | |
| 19 | + """ | |
| 20 | + | |
| 21 | + _ft_has: Dict = { | |
| 22 | + "l2_limit_range": [20, 100], | |
| 23 | + "l2_limit_range_required": False, | |
| 24 | + } |
modified tests/exchange/test_ccxt_compat.py +10 −3
| @@ -36,7 +36,12 @@ | ||
| 36 | 36 | 'pair': 'BTC/USDT', |
| 37 | 37 | 'hasQuoteVolume': True, |
| 38 | 38 | 'timeframe': '5m', |
| 39 | - } | |
| 39 | + }, | |
| 40 | + 'kucoin': { | |
| 41 | + 'pair': 'BTC/USDT', | |
| 42 | + 'hasQuoteVolume': True, | |
| 43 | + 'timeframe': '5m', | |
| 44 | + }, | |
| 40 | 45 | } |
| 41 | 46 | |
| 42 | 47 | |
| @@ -100,14 +105,16 @@ | ||
| 100 | 105 | assert 'asks' in l2 |
| 101 | 106 | assert 'bids' in l2 |
| 102 | 107 | l2_limit_range = exchange._ft_has['l2_limit_range'] |
| 108 | + l2_limit_range_required = exchange._ft_has['l2_limit_range_required'] | |
| 103 | 109 | for val in [1, 2, 5, 25, 100]: |
| 104 | 110 | l2 = exchange.fetch_l2_order_book(pair, val) |
| 105 | 111 | if not l2_limit_range or val in l2_limit_range: |
| 106 | 112 | assert len(l2['asks']) == val |
| 107 | 113 | assert len(l2['bids']) == val |
| 108 | 114 | else: |
| 109 | - next_limit = exchange.get_next_limit_in_list(val, l2_limit_range) | |
| 110 | - if next_limit > 200: | |
| 115 | + next_limit = exchange.get_next_limit_in_list( | |
| 116 | + val, l2_limit_range, l2_limit_range_required) | |
| 117 | + if next_limit is None or next_limit > 200: | |
| 111 | 118 | # Large orderbook sizes can be a problem for some exchanges (bitrex ...) |
| 112 | 119 | assert len(l2['asks']) > 200 |
| 113 | 120 | assert len(l2['asks']) > 200 |
modified tests/exchange/test_exchange.py +3 −0
| @@ -1641,6 +1641,9 @@ | ||
| 1641 | 1641 | # Going over the limit ... |
| 1642 | 1642 | assert Exchange.get_next_limit_in_list(1001, limit_range) == 1000 |
| 1643 | 1643 | assert Exchange.get_next_limit_in_list(2000, limit_range) == 1000 |
| 1644 | + # Without required range | |
| 1645 | + assert Exchange.get_next_limit_in_list(2000, limit_range, False) is None | |
| 1646 | + assert Exchange.get_next_limit_in_list(15, limit_range, False) == 20 | |
| 1644 | 1647 | |
| 1645 | 1648 | assert Exchange.get_next_limit_in_list(21, None) == 21 |
| 1646 | 1649 | assert Exchange.get_next_limit_in_list(100, None) == 100 |