Make ohlcv data endpoint work correctly with new interface

This commit is contained in:
Matthias 2021-11-20 20:09:37 +01:00
parent 32a56bbd4a
commit 7a8978abbb
3 changed files with 54 additions and 34 deletions

View File

@ -145,6 +145,8 @@ class OrderTypes(BaseModel):
class ShowConfig(BaseModel): class ShowConfig(BaseModel):
version: str version: str
dry_run: bool dry_run: bool
trading_mode: str
short_allowed: bool
stake_currency: str stake_currency: str
stake_amount: Union[float, str] stake_amount: Union[float, str]
available_capital: Optional[float] available_capital: Optional[float]
@ -339,6 +341,10 @@ class PairHistory(BaseModel):
length: int length: int
buy_signals: int buy_signals: int
sell_signals: int sell_signals: int
enter_long_signals: int
exit_long_signals: int
enter_short_signals: int
exit_short_signals: int
last_analyzed: datetime last_analyzed: datetime
last_analyzed_ts: int last_analyzed_ts: int
data_start_ts: int data_start_ts: int

View File

@ -108,6 +108,8 @@ class RPC:
val = { val = {
'version': __version__, 'version': __version__,
'dry_run': config['dry_run'], 'dry_run': config['dry_run'],
'trading_mode': config.get('trading_mode', 'spot'),
'short_allowed': config.get('trading_mode', 'spot') != 'spot',
'stake_currency': config['stake_currency'], 'stake_currency': config['stake_currency'],
'stake_currency_decimals': decimals_per_coin(config['stake_currency']), 'stake_currency_decimals': decimals_per_coin(config['stake_currency']),
'stake_amount': config['stake_amount'], 'stake_amount': config['stake_amount'],
@ -909,20 +911,21 @@ class RPC:
def _convert_dataframe_to_dict(strategy: str, pair: str, timeframe: str, dataframe: DataFrame, def _convert_dataframe_to_dict(strategy: str, pair: str, timeframe: str, dataframe: DataFrame,
last_analyzed: datetime) -> Dict[str, Any]: last_analyzed: datetime) -> Dict[str, Any]:
has_content = len(dataframe) != 0 has_content = len(dataframe) != 0
buy_signals = 0 signals = {
sell_signals = 0 'enter_long': 0,
'exit_long': 0,
'enter_short': 0,
'exit_short': 0,
}
if has_content: if has_content:
dataframe.loc[:, '__date_ts'] = dataframe.loc[:, 'date'].view(int64) // 1000 // 1000 dataframe.loc[:, '__date_ts'] = dataframe.loc[:, 'date'].view(int64) // 1000 // 1000
# Move signal close to separate column when signal for easy plotting # Move signal close to separate column when signal for easy plotting
if 'buy' in dataframe.columns: for sig_type in signals.keys():
buy_mask = (dataframe['buy'] == 1) if sig_type in dataframe.columns:
buy_signals = int(buy_mask.sum()) mask = (dataframe[sig_type] == 1)
dataframe.loc[buy_mask, '_buy_signal_close'] = dataframe.loc[buy_mask, 'close'] signals[sig_type] = int(mask.sum())
if 'sell' in dataframe.columns: dataframe.loc[mask, f'_{sig_type}_signal_close'] = dataframe.loc[mask, 'close']
sell_mask = (dataframe['sell'] == 1)
sell_signals = int(sell_mask.sum())
dataframe.loc[sell_mask, '_sell_signal_close'] = dataframe.loc[sell_mask, 'close']
dataframe = dataframe.replace([inf, -inf], NAN) dataframe = dataframe.replace([inf, -inf], NAN)
dataframe = dataframe.replace({NAN: None}) dataframe = dataframe.replace({NAN: None})
@ -934,8 +937,12 @@ class RPC:
'columns': list(dataframe.columns), 'columns': list(dataframe.columns),
'data': dataframe.values.tolist(), 'data': dataframe.values.tolist(),
'length': len(dataframe), 'length': len(dataframe),
'buy_signals': buy_signals, 'buy_signals': signals['enter_long'], # Deprecated
'sell_signals': sell_signals, 'sell_signals': signals['exit_long'], # Deprecated
'enter_long_signals': signals['enter_long'],
'exit_long_signals': signals['exit_long'],
'enter_short_signals': signals['enter_short'],
'exit_short_signals': signals['exit_short'],
'last_analyzed': last_analyzed, 'last_analyzed': last_analyzed,
'last_analyzed_ts': int(last_analyzed.timestamp()), 'last_analyzed_ts': int(last_analyzed.timestamp()),
'data_start': '', 'data_start': '',

View File

@ -527,18 +527,20 @@ def test_api_show_config(botclient):
rc = client_get(client, f"{BASE_URI}/show_config") rc = client_get(client, f"{BASE_URI}/show_config")
assert_response(rc) assert_response(rc)
assert 'dry_run' in rc.json() response = rc.json()
assert rc.json()['exchange'] == 'binance' assert 'dry_run' in response
assert rc.json()['timeframe'] == '5m' assert response['exchange'] == 'binance'
assert rc.json()['timeframe_ms'] == 300000 assert response['timeframe'] == '5m'
assert rc.json()['timeframe_min'] == 5 assert response['timeframe_ms'] == 300000
assert rc.json()['state'] == 'running' assert response['timeframe_min'] == 5
assert rc.json()['bot_name'] == 'freqtrade' assert response['state'] == 'running'
assert not rc.json()['trailing_stop'] assert response['bot_name'] == 'freqtrade'
assert 'bid_strategy' in rc.json() assert response['trading_mode'] == 'spot'
assert 'ask_strategy' in rc.json() assert not response['trailing_stop']
assert 'unfilledtimeout' in rc.json() assert 'bid_strategy' in response
assert 'version' in rc.json() assert 'ask_strategy' in response
assert 'unfilledtimeout' in response
assert 'version' in response
def test_api_daily(botclient, mocker, ticker, fee, markets): def test_api_daily(botclient, mocker, ticker, fee, markets):
@ -1168,9 +1170,11 @@ def test_api_pair_candles(botclient, ohlcv_history):
assert 'data_stop_ts' in rc.json() assert 'data_stop_ts' in rc.json()
assert len(rc.json()['data']) == 0 assert len(rc.json()['data']) == 0
ohlcv_history['sma'] = ohlcv_history['close'].rolling(2).mean() ohlcv_history['sma'] = ohlcv_history['close'].rolling(2).mean()
ohlcv_history['buy'] = 0 ohlcv_history['enter_long'] = 0
ohlcv_history.loc[1, 'buy'] = 1 ohlcv_history.loc[1, 'enter_long'] = 1
ohlcv_history['sell'] = 0 ohlcv_history['exit_long'] = 0
ohlcv_history['enter_short'] = 0
ohlcv_history['exit_short'] = 0
ftbot.dataprovider._set_cached_df("XRP/BTC", timeframe, ohlcv_history) ftbot.dataprovider._set_cached_df("XRP/BTC", timeframe, ohlcv_history)
@ -1189,9 +1193,12 @@ def test_api_pair_candles(botclient, ohlcv_history):
assert rc.json()['data_stop'] == '2017-11-26 09:00:00+00:00' assert rc.json()['data_stop'] == '2017-11-26 09:00:00+00:00'
assert rc.json()['data_stop_ts'] == 1511686800000 assert rc.json()['data_stop_ts'] == 1511686800000
assert isinstance(rc.json()['columns'], list) assert isinstance(rc.json()['columns'], list)
assert rc.json()['columns'] == ['date', 'open', 'high', assert set(rc.json()['columns']) == {
'low', 'close', 'volume', 'sma', 'buy', 'sell', 'date', 'open', 'high', 'low', 'close', 'volume',
'__date_ts', '_buy_signal_close', '_sell_signal_close'] 'sma', 'enter_long', 'exit_long', 'enter_short', 'exit_short', '__date_ts',
'_enter_long_signal_close', '_exit_long_signal_close',
'_enter_short_signal_close', '_exit_short_signal_close'
}
assert 'pair' in rc.json() assert 'pair' in rc.json()
assert rc.json()['pair'] == 'XRP/BTC' assert rc.json()['pair'] == 'XRP/BTC'
@ -1200,12 +1207,12 @@ def test_api_pair_candles(botclient, ohlcv_history):
assert (rc.json()['data'] == assert (rc.json()['data'] ==
[['2017-11-26 08:50:00', 8.794e-05, 8.948e-05, 8.794e-05, 8.88e-05, 0.0877869, [['2017-11-26 08:50:00', 8.794e-05, 8.948e-05, 8.794e-05, 8.88e-05, 0.0877869,
None, 0, 0, 1511686200000, None, None], None, 0, 0, 0, 0, 1511686200000, None, None, None, None],
['2017-11-26 08:55:00', 8.88e-05, 8.942e-05, 8.88e-05, ['2017-11-26 08:55:00', 8.88e-05, 8.942e-05, 8.88e-05,
8.893e-05, 0.05874751, 8.886500000000001e-05, 1, 0, 1511686500000, 8.893e-05, 8.893e-05, 0.05874751, 8.886500000000001e-05, 1, 0, 0, 0, 1511686500000, 8.893e-05,
None], None, None, None],
['2017-11-26 09:00:00', 8.891e-05, 8.893e-05, 8.875e-05, 8.877e-05, ['2017-11-26 09:00:00', 8.891e-05, 8.893e-05, 8.875e-05, 8.877e-05,
0.7039405, 8.885e-05, 0, 0, 1511686800000, None, None] 0.7039405, 8.885e-05, 0, 0, 0, 0, 1511686800000, None, None, None, None]
]) ])