merged with feat/short

This commit is contained in:
Sam Germain
2021-09-15 22:28:10 -06:00
parent 8e83cb4d64
commit 98b00e8daf
93 changed files with 673 additions and 2067 deletions

View File

@@ -3,6 +3,7 @@ import logging
from datetime import datetime
from typing import Dict, List, Optional
import arrow
import ccxt
from freqtrade.exceptions import (DDosProtection, InsufficientFundsError, InvalidOrderException,
@@ -19,6 +20,7 @@ class Binance(Exchange):
_ft_has: Dict = {
"stoploss_on_exchange": True,
"order_time_in_force": ['gtc', 'fok', 'ioc'],
"time_in_force_parameter": "timeInForce",
"ohlcv_candle_limit": 1000,
"trades_pagination": "id",
"trades_pagination_arg": "fromId",
@@ -117,5 +119,25 @@ class Binance(Exchange):
if premium_index is None:
raise OperationalException("Funding rate cannot be None for Binance._get_funding_fee")
nominal_value = mark_price * contract_size
adjustment = nominal_value * _calculate_funding_rate(pair, premium_index)
funding_rate = self._calculate_funding_rate(pair, premium_index)
if funding_rate is None:
raise OperationalException("Funding rate should never be none on Binance")
adjustment = nominal_value * funding_rate
return adjustment
async def _async_get_historic_ohlcv(self, pair: str, timeframe: str,
since_ms: int, is_new_pair: bool
) -> List:
"""
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]
logger.info(f"Candle-data for {pair} available starting with "
f"{arrow.get(since_ms // 1000).isoformat()}.")
return await super()._async_get_historic_ohlcv(
pair=pair, timeframe=timeframe, since_ms=since_ms, is_new_pair=is_new_pair)