mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 00:23:07 +00:00
Replaces public_trades_to_dataframe with trades_list_to_df
This commit is contained in:
@@ -2,7 +2,6 @@ from freqtrade.data.converter.converter import (clean_ohlcv_dataframe, convert_o
|
||||
ohlcv_fill_up_missing_data, ohlcv_to_dataframe,
|
||||
order_book_to_dataframe,
|
||||
populate_dataframe_with_trades,
|
||||
public_trades_to_dataframe,
|
||||
reduce_dataframe_footprint, trim_dataframe,
|
||||
trim_dataframes)
|
||||
from freqtrade.data.converter.trade_converter import (convert_trades_format,
|
||||
@@ -24,7 +23,6 @@ __all__ = [
|
||||
'convert_trades_format',
|
||||
'convert_trades_to_ohlcv',
|
||||
'populate_dataframe_with_trades',
|
||||
'public_trades_to_dataframe',
|
||||
'trades_convert_types',
|
||||
'trades_df_remove_duplicates',
|
||||
'trades_dict_to_list',
|
||||
|
||||
@@ -195,30 +195,6 @@ def populate_dataframe_with_trades(config: Config,
|
||||
return dataframe
|
||||
|
||||
|
||||
def public_trades_to_dataframe(trades: List, pair: str) -> DataFrame:
|
||||
"""
|
||||
Converts a list with candle (TRADES) data (in format returned by ccxt.fetch_trades)
|
||||
to a Dataframe
|
||||
:param trades: list with candle (TRADES) data, as returned by exchange.async_get_candle_history
|
||||
:param timeframe: timeframe (e.g. 5m). Used to fill up eventual missing data
|
||||
:param pair: Pair this data is for (used to warn if fillup was necessary)
|
||||
:param fill_missing: fill up missing candles with 0 candles
|
||||
(see trades_fill_up_missing_data for details)
|
||||
:param drop_incomplete: Drop the last candle of the dataframe, assuming it's incomplete
|
||||
:return: DataFrame
|
||||
"""
|
||||
logger.debug(f"Converting candle (TRADES) data to dataframe for pair {pair}.")
|
||||
cols = DEFAULT_TRADES_COLUMNS
|
||||
df = DataFrame(trades, columns=cols)
|
||||
df['date'] = pd.to_datetime(df['timestamp'], unit='ms', utc=True)
|
||||
|
||||
# Some exchanges return int values for Volume and even for OHLC.
|
||||
# Convert them since TA-LIB indicators used in the strategy assume floats
|
||||
# and fail with exception...
|
||||
df = df.astype(dtype={'amount': 'float', 'cost': 'float', 'price': 'float'})
|
||||
return df
|
||||
|
||||
|
||||
def trades_to_volumeprofile_with_total_delta_bid_ask(trades: DataFrame, scale: float):
|
||||
"""
|
||||
:param trades: dataframe
|
||||
|
||||
@@ -25,9 +25,8 @@ from freqtrade.constants import (DEFAULT_AMOUNT_RESERVE_PERCENT, DEFAULT_TRADES_
|
||||
ExchangeConfig, ListPairsWithTimeframes, MakerTaker, OBLiteral,
|
||||
PairWithTimeframe)
|
||||
from freqtrade.data.converter import clean_ohlcv_dataframe, ohlcv_to_dataframe, trades_dict_to_list
|
||||
from freqtrade.data.converter.converter import (_calculate_ohlcv_candle_start_and_end,
|
||||
public_trades_to_dataframe)
|
||||
from freqtrade.data.converter.trade_converter import trades_df_remove_duplicates
|
||||
from freqtrade.data.converter.converter import _calculate_ohlcv_candle_start_and_end
|
||||
from freqtrade.data.converter.trade_converter import trades_df_remove_duplicates, trades_list_to_df
|
||||
from freqtrade.enums import OPTIMIZE_MODES, CandleType, MarginMode, PriceType, RunMode, TradingMode
|
||||
from freqtrade.exceptions import (DDosProtection, ExchangeError, InsufficientFundsError,
|
||||
InvalidOrderException, OperationalException, PricingError,
|
||||
@@ -2106,7 +2105,7 @@ class Exchange:
|
||||
cache: bool,
|
||||
first_required_candle_date: Optional[int]) -> DataFrame:
|
||||
# keeping parsed dataframe in cache
|
||||
trades_df = public_trades_to_dataframe(ticks, pair=pair)
|
||||
trades_df = trades_list_to_df(ticks, True)
|
||||
# keeping last candle time as last refreshed time of the pair
|
||||
if ticks and cache:
|
||||
idx = -1
|
||||
|
||||
@@ -3,8 +3,10 @@ import numpy as np
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
||||
from freqtrade.data.converter import populate_dataframe_with_trades, public_trades_to_dataframe
|
||||
from freqtrade.data.converter.converter import trades_to_volumeprofile_with_total_delta_bid_ask
|
||||
from freqtrade.constants import DEFAULT_TRADES_COLUMNS
|
||||
from freqtrade.data.converter import populate_dataframe_with_trades
|
||||
from freqtrade.data.converter.orderflow import trades_to_volumeprofile_with_total_delta_bid_ask
|
||||
from freqtrade.data.converter.trade_converter import trades_list_to_df
|
||||
|
||||
|
||||
BIN_SIZE_SCALE = 0.5
|
||||
@@ -74,7 +76,7 @@ def test_public_trades_mock_populate_dataframe_with_trades__check_orderflow(
|
||||
'imbalance_volume': 0,
|
||||
'imbalance_ratio': 300,
|
||||
'stacked_imbalance_range': 3
|
||||
}}
|
||||
}}
|
||||
df = populate_dataframe_with_trades(config,
|
||||
dataframe, trades, pair='unitttest')
|
||||
results = df.iloc[0]
|
||||
@@ -138,8 +140,8 @@ def test_public_trades_trades_mock_populate_dataframe_with_trades__check_trades(
|
||||
'imbalance_volume': 0,
|
||||
'imbalance_ratio': 300,
|
||||
'stacked_imbalance_range': 3
|
||||
}
|
||||
}
|
||||
}
|
||||
df = populate_dataframe_with_trades(config,
|
||||
dataframe, trades, pair='unitttest')
|
||||
row = df.iloc[0]
|
||||
@@ -164,7 +166,8 @@ def test_public_trades_trades_mock_populate_dataframe_with_trades__check_trades(
|
||||
|
||||
|
||||
def test_public_trades_put_volume_profile_into_ohlcv_candles(public_trades_list_simple, candles):
|
||||
df = public_trades_to_dataframe(public_trades_list_simple, 'doesntmatter')
|
||||
df = trades_list_to_df(
|
||||
public_trades_list_simple[DEFAULT_TRADES_COLUMNS].values.tolist())
|
||||
df = trades_to_volumeprofile_with_total_delta_bid_ask(
|
||||
df, scale=BIN_SIZE_SCALE)
|
||||
candles['vp'] = np.nan
|
||||
@@ -176,7 +179,8 @@ def test_public_trades_put_volume_profile_into_ohlcv_candles(public_trades_list_
|
||||
|
||||
def test_public_trades_binned_big_sample_list(public_trades_list):
|
||||
BIN_SIZE_SCALE = 0.05
|
||||
trades = public_trades_to_dataframe(public_trades_list, 'doesntmatter')
|
||||
trades = trades_list_to_df(
|
||||
public_trades_list[DEFAULT_TRADES_COLUMNS].values.tolist())
|
||||
df = trades_to_volumeprofile_with_total_delta_bid_ask(
|
||||
trades, scale=BIN_SIZE_SCALE)
|
||||
assert df.columns.tolist() == ['bid', 'ask', 'delta',
|
||||
@@ -203,7 +207,7 @@ def test_public_trades_binned_big_sample_list(public_trades_list):
|
||||
assert 57.551 == df['delta'].iat[-1] # delta
|
||||
|
||||
BIN_SIZE_SCALE = 1
|
||||
trades = public_trades_to_dataframe(public_trades_list, 'doesntmatter')
|
||||
trades = trades_list_to_df(public_trades_list[DEFAULT_TRADES_COLUMNS].values.tolist())
|
||||
df = trades_to_volumeprofile_with_total_delta_bid_ask(
|
||||
trades, scale=BIN_SIZE_SCALE)
|
||||
assert 2 == len(df)
|
||||
|
||||
Reference in New Issue
Block a user