2019-02-24 18:30:05 +00:00
|
|
|
""" Binance exchange subclass """
|
|
|
|
import logging
|
2021-11-04 19:00:02 +00:00
|
|
|
from typing import Dict, List, Tuple
|
2019-02-24 18:30:05 +00:00
|
|
|
|
2021-09-07 17:29:10 +00:00
|
|
|
import arrow
|
2019-08-25 07:50:37 +00:00
|
|
|
|
2019-02-24 18:30:05 +00:00
|
|
|
from freqtrade.exchange import Exchange
|
|
|
|
|
2020-09-28 17:39:41 +00:00
|
|
|
|
2019-02-24 18:30:05 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class Binance(Exchange):
|
|
|
|
|
2019-02-24 19:01:20 +00:00
|
|
|
_ft_has: Dict = {
|
2019-02-24 18:30:05 +00:00
|
|
|
"stoploss_on_exchange": True,
|
2022-02-02 19:40:40 +00:00
|
|
|
"stoploss_order_types": {"limit": "stop_loss_limit"},
|
2019-03-25 23:49:39 +00:00
|
|
|
"order_time_in_force": ['gtc', 'fok', 'ioc'],
|
2021-09-03 06:48:53 +00:00
|
|
|
"time_in_force_parameter": "timeInForce",
|
2020-12-20 10:44:50 +00:00
|
|
|
"ohlcv_candle_limit": 1000,
|
2019-08-14 17:22:52 +00:00
|
|
|
"trades_pagination": "id",
|
|
|
|
"trades_pagination_arg": "fromId",
|
2020-10-13 18:02:47 +00:00
|
|
|
"l2_limit_range": [5, 10, 20, 50, 100, 500, 1000],
|
2019-02-24 18:30:05 +00:00
|
|
|
}
|
|
|
|
|
2020-01-19 18:54:30 +00:00
|
|
|
def stoploss_adjust(self, stop_loss: float, order: Dict) -> bool:
|
|
|
|
"""
|
|
|
|
Verify stop_loss against stoploss-order value (limit or price)
|
|
|
|
Returns True if adjustment is necessary.
|
|
|
|
"""
|
|
|
|
return order['type'] == 'stop_loss_limit' and stop_loss > float(order['info']['stopPrice'])
|
|
|
|
|
2021-09-07 17:29:10 +00:00
|
|
|
async def _async_get_historic_ohlcv(self, pair: str, timeframe: str,
|
2021-11-04 19:00:02 +00:00
|
|
|
since_ms: int, is_new_pair: bool = False,
|
|
|
|
raise_: bool = False
|
|
|
|
) -> Tuple[str, str, List]:
|
2021-09-07 17:29:10 +00:00
|
|
|
"""
|
|
|
|
Overwrite to introduce "fast new pair" functionality by detecting the pair's listing date
|
|
|
|
Does not work for other exchanges, which don't return the earliest data when called with "0"
|
|
|
|
"""
|
|
|
|
if is_new_pair:
|
|
|
|
x = await self._async_get_candle_history(pair, timeframe, 0)
|
|
|
|
if x and x[2] and x[2][0] and x[2][0][0] > since_ms:
|
|
|
|
# Set starting date to first available candle.
|
|
|
|
since_ms = x[2][0][0]
|
2021-09-07 17:51:07 +00:00
|
|
|
logger.info(f"Candle-data for {pair} available starting with "
|
2021-09-07 17:29:10 +00:00
|
|
|
f"{arrow.get(since_ms // 1000).isoformat()}.")
|
|
|
|
return await super()._async_get_historic_ohlcv(
|
2021-11-04 19:00:02 +00:00
|
|
|
pair=pair, timeframe=timeframe, since_ms=since_ms, is_new_pair=is_new_pair,
|
|
|
|
raise_=raise_)
|