Slightly change returned column scheme

This commit is contained in:
Matthias
2024-04-28 10:40:54 +02:00
parent 54d467d2bf
commit 3e20770446
3 changed files with 28 additions and 22 deletions

View File

@@ -502,7 +502,7 @@ class PairHistory(BaseModel):
timeframe: str timeframe: str
timeframe_ms: int timeframe_ms: int
columns: List[str] columns: List[str]
selected_columns: List[str] = [] all_columns: List[str] = []
data: SerializeAsAny[List[Any]] data: SerializeAsAny[List[Any]]
length: int length: int
buy_signals: int buy_signals: int

View File

@@ -1204,7 +1204,7 @@ class RPC:
if has_content: if has_content:
if selected_cols: if selected_cols:
# Ensure OHLCV columns are always present # Ensure OHLCV columns are always present
cols_set = set(DEFAULT_DATAFRAME_COLUMNS + selected_cols) cols_set = set(DEFAULT_DATAFRAME_COLUMNS + list(signals.keys()) + selected_cols)
df_cols = [col for col in dataframe_columns if col in cols_set] df_cols = [col for col in dataframe_columns if col in cols_set]
dataframe = dataframe.loc[:, df_cols] dataframe = dataframe.loc[:, df_cols]
@@ -1231,8 +1231,8 @@ class RPC:
'timeframe': timeframe, 'timeframe': timeframe,
'timeframe_ms': timeframe_to_msecs(timeframe), 'timeframe_ms': timeframe_to_msecs(timeframe),
'strategy': strategy, 'strategy': strategy,
'columns': dataframe_columns, 'all_columns': dataframe_columns,
'selected_columns': list(dataframe.columns), 'columns': list(dataframe.columns),
'data': dataframe.values.tolist(), 'data': dataframe.values.tolist(),
'length': len(dataframe), 'length': len(dataframe),
'buy_signals': signals['enter_long'], # Deprecated 'buy_signals': signals['enter_long'], # Deprecated

View File

@@ -1522,31 +1522,37 @@ def test_api_pair_candles(botclient, ohlcv_history):
rc = client_get(client, rc = client_get(client,
f"{BASE_URI}/pair_candles?limit={amount}&pair=XRP%2FBTC&timeframe={timeframe}") f"{BASE_URI}/pair_candles?limit={amount}&pair=XRP%2FBTC&timeframe={timeframe}")
assert_response(rc) assert_response(rc)
assert 'strategy' in rc.json() resp = rc.json()
assert rc.json()['strategy'] == CURRENT_TEST_STRATEGY assert 'strategy' in resp
assert 'columns' in rc.json() assert resp['strategy'] == CURRENT_TEST_STRATEGY
assert 'data_start_ts' in rc.json() assert 'columns' in resp
assert 'data_start' in rc.json() assert 'data_start_ts' in resp
assert 'data_stop' in rc.json() assert 'data_start' in resp
assert 'data_stop_ts' in rc.json() assert 'data_stop' in resp
assert rc.json()['data_start'] == '2017-11-26 08:50:00+00:00' assert 'data_stop_ts' in resp
assert rc.json()['data_start_ts'] == 1511686200000 assert resp['data_start'] == '2017-11-26 08:50:00+00:00'
assert rc.json()['data_stop'] == '2017-11-26 09:00:00+00:00' assert resp['data_start_ts'] == 1511686200000
assert rc.json()['data_stop_ts'] == 1511686800000 assert resp['data_stop'] == '2017-11-26 09:00:00+00:00'
assert isinstance(rc.json()['columns'], list) assert resp['data_stop_ts'] == 1511686800000
assert set(rc.json()['columns']) == { assert isinstance(resp['columns'], list)
assert set(resp['columns']) == {
'date', 'open', 'high', 'low', 'close', 'volume', 'date', 'open', 'high', 'low', 'close', 'volume',
'sma', 'enter_long', 'exit_long', 'enter_short', 'exit_short', '__date_ts', 'sma', 'enter_long', 'exit_long', 'enter_short', 'exit_short', '__date_ts',
'_enter_long_signal_close', '_exit_long_signal_close', '_enter_long_signal_close', '_exit_long_signal_close',
'_enter_short_signal_close', '_exit_short_signal_close' '_enter_short_signal_close', '_exit_short_signal_close'
} }
assert 'pair' in rc.json() # All columns doesn't include the internal columns
assert rc.json()['pair'] == 'XRP/BTC' assert set(resp['all_columns']) == {
'date', 'open', 'high', 'low', 'close', 'volume',
'sma', 'enter_long', 'exit_long', 'enter_short', 'exit_short'
}
assert 'pair' in resp
assert resp['pair'] == 'XRP/BTC'
assert 'data' in rc.json() assert 'data' in resp
assert len(rc.json()['data']) == amount assert len(resp['data']) == amount
assert (rc.json()['data'] == assert (resp['data'] ==
[['2017-11-26T08:50:00Z', 8.794e-05, 8.948e-05, 8.794e-05, 8.88e-05, 0.0877869, [['2017-11-26T08:50:00Z', 8.794e-05, 8.948e-05, 8.794e-05, 8.88e-05, 0.0877869,
None, 0, 0, 0, 0, 1511686200000, None, None, None, None], None, 0, 0, 0, 0, 1511686200000, None, None, None, None],
['2017-11-26T08:55:00Z', 8.88e-05, 8.942e-05, 8.88e-05, ['2017-11-26T08:55:00Z', 8.88e-05, 8.942e-05, 8.88e-05,