Merge pull request #7298 from freqtrade/tif_align

align TimeInForce to ccxt usage
This commit is contained in:
Matthias
2022-08-29 06:36:51 +02:00
committed by GitHub
19 changed files with 58 additions and 52 deletions

View File

@@ -23,7 +23,8 @@ REQUIRED_ORDERTIF = ['entry', 'exit']
REQUIRED_ORDERTYPES = ['entry', 'exit', 'stoploss', 'stoploss_on_exchange']
PRICING_SIDES = ['ask', 'bid', 'same', 'other']
ORDERTYPE_POSSIBILITIES = ['limit', 'market']
ORDERTIF_POSSIBILITIES = ['gtc', 'fok', 'ioc']
_ORDERTIF_POSSIBILITIES = ['GTC', 'FOK', 'IOC', 'PO']
ORDERTIF_POSSIBILITIES = _ORDERTIF_POSSIBILITIES + [t.lower() for t in _ORDERTIF_POSSIBILITIES]
HYPEROPT_LOSS_BUILTIN = ['ShortTradeDurHyperOptLoss', 'OnlyProfitHyperOptLoss',
'SharpeHyperOptLoss', 'SharpeHyperOptLossDaily',
'SortinoHyperOptLoss', 'SortinoHyperOptLossDaily',

View File

@@ -23,8 +23,7 @@ class Binance(Exchange):
_ft_has: Dict = {
"stoploss_on_exchange": True,
"stoploss_order_types": {"limit": "stop_loss_limit"},
"order_time_in_force": ['gtc', 'fok', 'ioc'],
"time_in_force_parameter": "timeInForce",
"order_time_in_force": ['GTC', 'FOK', 'IOC'],
"ohlcv_candle_limit": 1000,
"trades_pagination": "id",
"trades_pagination_arg": "fromId",

View File

@@ -62,7 +62,7 @@ class Exchange:
# or by specifying them in the configuration.
_ft_has_default: Dict = {
"stoploss_on_exchange": False,
"order_time_in_force": ["gtc"],
"order_time_in_force": ["GTC"],
"time_in_force_parameter": "timeInForce",
"ohlcv_params": {},
"ohlcv_candle_limit": 500,
@@ -611,7 +611,7 @@ class Exchange:
"""
Checks if order time in force configured in strategy/config are supported
"""
if any(v not in self._ft_has["order_time_in_force"]
if any(v.upper() not in self._ft_has["order_time_in_force"]
for k, v in order_time_in_force.items()):
raise OperationalException(
f'Time in force policies are not supported for {self.name} yet.')
@@ -989,12 +989,12 @@ class Exchange:
ordertype: str,
leverage: float,
reduceOnly: bool,
time_in_force: str = 'gtc',
time_in_force: str = 'GTC',
) -> Dict:
params = self._params.copy()
if time_in_force != 'gtc' and ordertype != 'market':
if time_in_force != 'GTC' and ordertype != 'market':
param = self._ft_has.get('time_in_force_parameter', '')
params.update({param: time_in_force})
params.update({param: time_in_force.upper()})
if reduceOnly:
params.update({'reduceOnly': True})
return params
@@ -1009,7 +1009,7 @@ class Exchange:
rate: float,
leverage: float,
reduceOnly: bool = False,
time_in_force: str = 'gtc',
time_in_force: str = 'GTC',
) -> Dict:
if self._config['dry_run']:
dry_order = self.create_dry_run_order(

View File

@@ -19,6 +19,7 @@ logger = logging.getLogger(__name__)
class Ftx(Exchange):
_ft_has: Dict = {
"order_time_in_force": ['GTC', 'IOC', 'PO'],
"stoploss_on_exchange": True,
"ohlcv_candle_limit": 1500,
"ohlcv_require_since": True,

View File

@@ -25,8 +25,7 @@ class Gateio(Exchange):
_ft_has: Dict = {
"ohlcv_candle_limit": 1000,
"time_in_force_parameter": "timeInForce",
"order_time_in_force": ['gtc', 'ioc'],
"order_time_in_force": ['GTC', 'IOC'],
"stoploss_order_types": {"limit": "limit"},
"stoploss_on_exchange": True,
}
@@ -57,7 +56,7 @@ class Gateio(Exchange):
ordertype: str,
leverage: float,
reduceOnly: bool,
time_in_force: str = 'gtc',
time_in_force: str = 'GTC',
) -> Dict:
params = super()._get_params(
side=side,
@@ -69,7 +68,7 @@ class Gateio(Exchange):
if ordertype == 'market' and self.trading_mode == TradingMode.FUTURES:
params['type'] = 'market'
param = self._ft_has.get('time_in_force_parameter', '')
params.update({param: 'ioc'})
params.update({param: 'IOC'})
return params
def get_trades_for_order(self, order_id: str, pair: str, since: datetime,

View File

@@ -171,7 +171,7 @@ class Kraken(Exchange):
ordertype: str,
leverage: float,
reduceOnly: bool,
time_in_force: str = 'gtc'
time_in_force: str = 'GTC'
) -> Dict:
params = super()._get_params(
side=side,

View File

@@ -23,8 +23,7 @@ class Kucoin(Exchange):
"stoploss_order_types": {"limit": "limit", "market": "market"},
"l2_limit_range": [20, 100],
"l2_limit_range_required": False,
"order_time_in_force": ['gtc', 'fok', 'ioc'],
"time_in_force_parameter": "timeInForce",
"order_time_in_force": ['GTC', 'FOK', 'IOC'],
"ohlcv_candle_limit": 1500,
}

View File

@@ -98,7 +98,7 @@ class Okx(Exchange):
ordertype: str,
leverage: float,
reduceOnly: bool,
time_in_force: str = 'gtc',
time_in_force: str = 'GTC',
) -> Dict:
params = super()._get_params(
side=side,

View File

@@ -78,8 +78,8 @@ class IStrategy(ABC, HyperStrategyMixin):
# Optional time in force
order_time_in_force: Dict = {
'entry': 'gtc',
'exit': 'gtc',
'entry': 'GTC',
'exit': 'GTC',
}
# run "populate_indicators" only for new candle

View File

@@ -88,8 +88,8 @@ class {{ strategy }}(IStrategy):
# Optional order time in force.
order_time_in_force = {
'entry': 'gtc',
'exit': 'gtc'
'entry': 'GTC',
'exit': 'GTC'
}
{{ plot_config | indent(4) }}

View File

@@ -88,8 +88,8 @@ class SampleStrategy(IStrategy):
# Optional order time in force.
order_time_in_force = {
'entry': 'gtc',
'exit': 'gtc'
'entry': 'GTC',
'exit': 'GTC'
}
plot_config = {