Make ohlcv data endpoint work correctly with new interface
This commit is contained in:
parent
32a56bbd4a
commit
7a8978abbb
@ -145,6 +145,8 @@ class OrderTypes(BaseModel):
|
||||
class ShowConfig(BaseModel):
|
||||
version: str
|
||||
dry_run: bool
|
||||
trading_mode: str
|
||||
short_allowed: bool
|
||||
stake_currency: str
|
||||
stake_amount: Union[float, str]
|
||||
available_capital: Optional[float]
|
||||
@ -339,6 +341,10 @@ class PairHistory(BaseModel):
|
||||
length: int
|
||||
buy_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_ts: int
|
||||
data_start_ts: int
|
||||
|
@ -108,6 +108,8 @@ class RPC:
|
||||
val = {
|
||||
'version': __version__,
|
||||
'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_decimals': decimals_per_coin(config['stake_currency']),
|
||||
'stake_amount': config['stake_amount'],
|
||||
@ -909,20 +911,21 @@ class RPC:
|
||||
def _convert_dataframe_to_dict(strategy: str, pair: str, timeframe: str, dataframe: DataFrame,
|
||||
last_analyzed: datetime) -> Dict[str, Any]:
|
||||
has_content = len(dataframe) != 0
|
||||
buy_signals = 0
|
||||
sell_signals = 0
|
||||
signals = {
|
||||
'enter_long': 0,
|
||||
'exit_long': 0,
|
||||
'enter_short': 0,
|
||||
'exit_short': 0,
|
||||
}
|
||||
if has_content:
|
||||
|
||||
dataframe.loc[:, '__date_ts'] = dataframe.loc[:, 'date'].view(int64) // 1000 // 1000
|
||||
# Move signal close to separate column when signal for easy plotting
|
||||
if 'buy' in dataframe.columns:
|
||||
buy_mask = (dataframe['buy'] == 1)
|
||||
buy_signals = int(buy_mask.sum())
|
||||
dataframe.loc[buy_mask, '_buy_signal_close'] = dataframe.loc[buy_mask, 'close']
|
||||
if 'sell' in dataframe.columns:
|
||||
sell_mask = (dataframe['sell'] == 1)
|
||||
sell_signals = int(sell_mask.sum())
|
||||
dataframe.loc[sell_mask, '_sell_signal_close'] = dataframe.loc[sell_mask, 'close']
|
||||
for sig_type in signals.keys():
|
||||
if sig_type in dataframe.columns:
|
||||
mask = (dataframe[sig_type] == 1)
|
||||
signals[sig_type] = int(mask.sum())
|
||||
dataframe.loc[mask, f'_{sig_type}_signal_close'] = dataframe.loc[mask, 'close']
|
||||
dataframe = dataframe.replace([inf, -inf], NAN)
|
||||
dataframe = dataframe.replace({NAN: None})
|
||||
|
||||
@ -934,8 +937,12 @@ class RPC:
|
||||
'columns': list(dataframe.columns),
|
||||
'data': dataframe.values.tolist(),
|
||||
'length': len(dataframe),
|
||||
'buy_signals': buy_signals,
|
||||
'sell_signals': sell_signals,
|
||||
'buy_signals': signals['enter_long'], # Deprecated
|
||||
'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_ts': int(last_analyzed.timestamp()),
|
||||
'data_start': '',
|
||||
|
@ -527,18 +527,20 @@ def test_api_show_config(botclient):
|
||||
|
||||
rc = client_get(client, f"{BASE_URI}/show_config")
|
||||
assert_response(rc)
|
||||
assert 'dry_run' in rc.json()
|
||||
assert rc.json()['exchange'] == 'binance'
|
||||
assert rc.json()['timeframe'] == '5m'
|
||||
assert rc.json()['timeframe_ms'] == 300000
|
||||
assert rc.json()['timeframe_min'] == 5
|
||||
assert rc.json()['state'] == 'running'
|
||||
assert rc.json()['bot_name'] == 'freqtrade'
|
||||
assert not rc.json()['trailing_stop']
|
||||
assert 'bid_strategy' in rc.json()
|
||||
assert 'ask_strategy' in rc.json()
|
||||
assert 'unfilledtimeout' in rc.json()
|
||||
assert 'version' in rc.json()
|
||||
response = rc.json()
|
||||
assert 'dry_run' in response
|
||||
assert response['exchange'] == 'binance'
|
||||
assert response['timeframe'] == '5m'
|
||||
assert response['timeframe_ms'] == 300000
|
||||
assert response['timeframe_min'] == 5
|
||||
assert response['state'] == 'running'
|
||||
assert response['bot_name'] == 'freqtrade'
|
||||
assert response['trading_mode'] == 'spot'
|
||||
assert not response['trailing_stop']
|
||||
assert 'bid_strategy' in response
|
||||
assert 'ask_strategy' in response
|
||||
assert 'unfilledtimeout' in response
|
||||
assert 'version' in response
|
||||
|
||||
|
||||
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 len(rc.json()['data']) == 0
|
||||
ohlcv_history['sma'] = ohlcv_history['close'].rolling(2).mean()
|
||||
ohlcv_history['buy'] = 0
|
||||
ohlcv_history.loc[1, 'buy'] = 1
|
||||
ohlcv_history['sell'] = 0
|
||||
ohlcv_history['enter_long'] = 0
|
||||
ohlcv_history.loc[1, 'enter_long'] = 1
|
||||
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)
|
||||
|
||||
@ -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_ts'] == 1511686800000
|
||||
assert isinstance(rc.json()['columns'], list)
|
||||
assert rc.json()['columns'] == ['date', 'open', 'high',
|
||||
'low', 'close', 'volume', 'sma', 'buy', 'sell',
|
||||
'__date_ts', '_buy_signal_close', '_sell_signal_close']
|
||||
assert set(rc.json()['columns']) == {
|
||||
'date', 'open', 'high', 'low', 'close', 'volume',
|
||||
'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 rc.json()['pair'] == 'XRP/BTC'
|
||||
|
||||
@ -1200,12 +1207,12 @@ def test_api_pair_candles(botclient, ohlcv_history):
|
||||
|
||||
assert (rc.json()['data'] ==
|
||||
[['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,
|
||||
8.893e-05, 0.05874751, 8.886500000000001e-05, 1, 0, 1511686500000, 8.893e-05,
|
||||
None],
|
||||
8.893e-05, 0.05874751, 8.886500000000001e-05, 1, 0, 0, 0, 1511686500000, 8.893e-05,
|
||||
None, None, None],
|
||||
['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]
|
||||
|
||||
])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user