Ruff fix
This commit is contained in:
@@ -144,17 +144,17 @@ def populate_dataframe_with_trades(config: Config,
|
|||||||
# calculate imbalances for each candle's orderflow
|
# calculate imbalances for each candle's orderflow
|
||||||
df.loc[is_between, 'imbalances'] = df.loc[is_between, 'orderflow'].apply(
|
df.loc[is_between, 'imbalances'] = df.loc[is_between, 'orderflow'].apply(
|
||||||
lambda x: trades_orderflow_to_imbalances(x,
|
lambda x: trades_orderflow_to_imbalances(x,
|
||||||
imbalance_ratio=config_orderflow['imbalance_ratio'],
|
imbalance_ratio=config_orderflow['imbalance_ratio'], # noqa: E501
|
||||||
imbalance_volume=config_orderflow['imbalance_volume']))
|
imbalance_volume=config_orderflow['imbalance_volume'])) # noqa: E501
|
||||||
|
|
||||||
df.loc[is_between, 'stacked_imbalances_bid'] = df.loc[is_between,
|
df.loc[is_between, 'stacked_imbalances_bid'] = df.loc[is_between,
|
||||||
'imbalances'].apply(
|
'imbalances'].apply(
|
||||||
lambda x: stacked_imbalance_bid(x, # noqa: E501
|
lambda x: stacked_imbalance_bid(x, # noqa: E501
|
||||||
stacked_imbalance_range=config_orderflow['stacked_imbalance_range']))
|
stacked_imbalance_range=config_orderflow['stacked_imbalance_range'])) # noqa: E501
|
||||||
df.loc[is_between, 'stacked_imbalances_ask'] = df.loc[is_between,
|
df.loc[is_between, 'stacked_imbalances_ask'] = df.loc[is_between,
|
||||||
'imbalances'].apply(
|
'imbalances'].apply(
|
||||||
lambda x: stacked_imbalance_ask(x, # noqa: E501
|
lambda x: stacked_imbalance_ask(x, # noqa: E501
|
||||||
stacked_imbalance_range=config_orderflow['stacked_imbalance_range']))
|
stacked_imbalance_range=config_orderflow['stacked_imbalance_range'])) # noqa: E501
|
||||||
|
|
||||||
buy = df.loc[is_between, 'bid'].apply(lambda _: np.where(
|
buy = df.loc[is_between, 'bid'].apply(lambda _: np.where(
|
||||||
trades_grouped_df['side'].str.contains('buy'), 0, trades_grouped_df['amount']))
|
trades_grouped_df['side'].str.contains('buy'), 0, trades_grouped_df['amount']))
|
||||||
|
|||||||
@@ -50,24 +50,9 @@ def public_trades_list_simple_bidask():
|
|||||||
return read_csv('tests/testdata/public_trades_list_simple_bidask.csv').copy()
|
return read_csv('tests/testdata/public_trades_list_simple_bidask.csv').copy()
|
||||||
|
|
||||||
|
|
||||||
def conjuresetup():
|
def test_public_trades_columns_before_change(
|
||||||
public_trades_list = public_trades_list()
|
populate_dataframe_with_trades_dataframe,
|
||||||
print(public_trades_list.columns.tolist())
|
populate_dataframe_with_trades_trades):
|
||||||
public_trades_list_simple = public_trades_list_simple()
|
|
||||||
print(public_trades_list_simple.columns.tolist())
|
|
||||||
print(public_trades_list_simple.loc[:, [
|
|
||||||
'timestamp', 'id', 'price', 'side', 'amount']])
|
|
||||||
public_trades_list_simple_results = public_trades_list_simple_results()
|
|
||||||
print(public_trades_list_simple_results.columns.tolist())
|
|
||||||
public_trades_list_simple_bidask = public_trades_list_simple_bidask()
|
|
||||||
print(public_trades_list_simple_bidask.columns.tolist())
|
|
||||||
print(public_trades_list_simple_bidask)
|
|
||||||
print(public_trades_list_simple_results)
|
|
||||||
# conjuresetup() # never called except in REPL
|
|
||||||
# /conjuresetup
|
|
||||||
|
|
||||||
|
|
||||||
def test_public_trades_columns_before_change(populate_dataframe_with_trades_dataframe, populate_dataframe_with_trades_trades):
|
|
||||||
assert populate_dataframe_with_trades_dataframe.columns.tolist() == [
|
assert populate_dataframe_with_trades_dataframe.columns.tolist() == [
|
||||||
'date', 'open', 'high', 'low', 'close', 'volume']
|
'date', 'open', 'high', 'low', 'close', 'volume']
|
||||||
assert populate_dataframe_with_trades_trades.columns.tolist() == [
|
assert populate_dataframe_with_trades_trades.columns.tolist() == [
|
||||||
@@ -84,7 +69,12 @@ def test_public_trades_mock_populate_dataframe_with_trades__check_orderflow(
|
|||||||
dataframe['date'], unit='ms')
|
dataframe['date'], unit='ms')
|
||||||
dataframe = dataframe.copy().tail().reset_index(drop=True)
|
dataframe = dataframe.copy().tail().reset_index(drop=True)
|
||||||
config = {'timeframe': '5m',
|
config = {'timeframe': '5m',
|
||||||
'orderflow': {'scale': 0.005, 'imbalance_volume': 0, 'imbalance_ratio': 300, 'stacked_imbalance_range': 3}}
|
'orderflow': {
|
||||||
|
'scale': 0.005,
|
||||||
|
'imbalance_volume': 0,
|
||||||
|
'imbalance_ratio': 300,
|
||||||
|
'stacked_imbalance_range': 3
|
||||||
|
}}
|
||||||
df = populate_dataframe_with_trades(config,
|
df = populate_dataframe_with_trades(config,
|
||||||
dataframe, trades, pair='unitttest')
|
dataframe, trades, pair='unitttest')
|
||||||
results = df.iloc[0]
|
results = df.iloc[0]
|
||||||
@@ -143,13 +133,22 @@ def test_public_trades_trades_mock_populate_dataframe_with_trades__check_trades(
|
|||||||
|
|
||||||
config = {
|
config = {
|
||||||
'timeframe': '5m',
|
'timeframe': '5m',
|
||||||
'orderflow': {'scale': 0.5, 'imbalance_volume': 0, 'imbalance_ratio': 300, 'stacked_imbalance_range': 3}
|
'orderflow': {
|
||||||
}
|
'scale': 0.5,
|
||||||
|
'imbalance_volume': 0,
|
||||||
|
'imbalance_ratio': 300,
|
||||||
|
'stacked_imbalance_range': 3
|
||||||
|
}
|
||||||
|
}
|
||||||
df = populate_dataframe_with_trades(config,
|
df = populate_dataframe_with_trades(config,
|
||||||
dataframe, trades, pair='unitttest')
|
dataframe, trades, pair='unitttest')
|
||||||
result = df.iloc[0]
|
result = df.iloc[0]
|
||||||
assert result.index.values.tolist() == ['date', 'open', 'high', 'low', 'close', 'volume', 'trades', 'orderflow',
|
assert result.index.values.tolist() == ['date', 'open', 'high', 'low',
|
||||||
'bid', 'ask', 'delta', 'min_delta', 'max_delta', 'total_trades', 'stacked_imbalances_bid', 'stacked_imbalances_ask']
|
'close', 'volume', 'trades', 'orderflow',
|
||||||
|
'bid', 'ask', 'delta', 'min_delta',
|
||||||
|
'max_delta', 'total_trades',
|
||||||
|
'stacked_imbalances_bid',
|
||||||
|
'stacked_imbalances_ask']
|
||||||
|
|
||||||
assert -50.519000000000005 == result['delta']
|
assert -50.519000000000005 == result['delta']
|
||||||
assert 219.961 == result['bid']
|
assert 219.961 == result['bid']
|
||||||
@@ -254,8 +253,12 @@ def do_plot(pair, data, trades, plot_config=None):
|
|||||||
|
|
||||||
# need to be at last to see if some test changed the testdata
|
# need to be at last to see if some test changed the testdata
|
||||||
# always need to use .copy() to avoid changing the testdata
|
# always need to use .copy() to avoid changing the testdata
|
||||||
def test_public_trades_testdata_sanity(candles, public_trades_list, public_trades_list_simple,
|
def test_public_trades_testdata_sanity(
|
||||||
populate_dataframe_with_trades_dataframe, populate_dataframe_with_trades_trades):
|
candles,
|
||||||
|
public_trades_list,
|
||||||
|
public_trades_list_simple,
|
||||||
|
populate_dataframe_with_trades_dataframe,
|
||||||
|
populate_dataframe_with_trades_trades):
|
||||||
assert 10999 == len(candles)
|
assert 10999 == len(candles)
|
||||||
assert 1000 == len(public_trades_list)
|
assert 1000 == len(public_trades_list)
|
||||||
assert 999 == len(populate_dataframe_with_trades_dataframe)
|
assert 999 == len(populate_dataframe_with_trades_dataframe)
|
||||||
|
|||||||
Reference in New Issue
Block a user