SyntheticTradeFeed#
tradingstrategy.direct_feed.synthetic_feed.SyntheticTradeFeed Python class in Trading Strategy framework.
- class SyntheticTradeFeed[source]#
Bases:
TradeFeed
Synthetic trade feed that produces random trades.
- __init__(pairs, oracles, reorg_mon, data_retention_time=None, random_seed=1, start_price_range=150, end_price_range=300, min_trades_per_block=0, max_trades_per_block=10, min_amount=50, max_amount=50, price_movement_per_trade=2.5, timeframe=<Timeframe freq:1min offset:0 days 00:00:00>, prices=None, broken_wick_block_frequency=0)[source]#
Create new real-time OHLCV tracker.
- Parameters:
pairs (List[str]) – List of pool addresses, or list of similar identifiers.
oracles (Dict[str, BasePriceOracle]) –
Reference prices for converting ETH or other crypto quoted prices to US dollars.
In the form of pair -> Price oracle maps.
reorg_mon (ReorganisationMonitor) – Reorganisation detector and last good block state for a chain.
timeframe (Timeframe) –
Expected timeframe of the data. Any trade deltas are snapped to the exact timeframe, so that when candle data gets updated, we always update only full candles and never return trade data that would break the timeframe in a middle.
Default to one minute candles.
data_retention_time (Optional[Timedelta]) – Discard entries older than this to avoid filling the RAM.
save_hook – Sync the downloaded data to disk.
Methods
__init__
(pairs, oracles, reorg_mon[, ...])Create new real-time OHLCV tracker.
add_trades
(trades[, start_block, end_block])Add trade to the ring buffer with support for fixing chain reorganisations.
backfill_buffer
(block_count[, tqdm, save_hook])Populate the backbuffer before starting real-time tracker.
check_correct_block_range
(df, start_block, ...)Check that trades in the given DataFrame are for correct block range.
check_current_trades_for_duplicates
()Check for duplicate trades.
check_duplicates_data_frame
(df)Check data for duplicate trades.
check_enough_history
(required_duration[, ...])Check that the dafa we have is good time window wise.
check_reorganisations_and_purge
()Check if any of block data has changed
fetch_trades
(start_block, end_block[, tqdm])Generate few random trades per block per pair.
find_first_included_block_in_candle
(ts)Find the first block number that contains data going into the candle.
get_block_number_of_last_trade
()Get the last block number for which we have good data.
get_exchange_rate
(pair)Get the current exchange rate for the pair.
get_latest_price
(pair)Return the latest price of a pair.
get_latest_trades
(n[, pair])Returns the latest trades.
get_trade_count
()How many trades we track currently.
perform_duty_cycle
([verbose])Update the candle data
restore
(df)Restore data from the previous disk save.
to_pandas
(partition_size)truncate_reorganised_data
(latest_good_block)Discard data because of the chain reorg.
update_cycle
(start_block, end_block, ...)Update the internal work buffer.
- __init__(pairs, oracles, reorg_mon, data_retention_time=None, random_seed=1, start_price_range=150, end_price_range=300, min_trades_per_block=0, max_trades_per_block=10, min_amount=50, max_amount=50, price_movement_per_trade=2.5, timeframe=<Timeframe freq:1min offset:0 days 00:00:00>, prices=None, broken_wick_block_frequency=0)[source]#
Create new real-time OHLCV tracker.
- Parameters:
pairs (List[str]) – List of pool addresses, or list of similar identifiers.
oracles (Dict[str, BasePriceOracle]) –
Reference prices for converting ETH or other crypto quoted prices to US dollars.
In the form of pair -> Price oracle maps.
reorg_mon (ReorganisationMonitor) – Reorganisation detector and last good block state for a chain.
timeframe (Timeframe) –
Expected timeframe of the data. Any trade deltas are snapped to the exact timeframe, so that when candle data gets updated, we always update only full candles and never return trade data that would break the timeframe in a middle.
Default to one minute candles.
data_retention_time (Optional[Timedelta]) – Discard entries older than this to avoid filling the RAM.
save_hook – Sync the downloaded data to disk.