Candles

Overview
The Candles component allows users to maintains a moving window of data and indicators that can be used in their strategy. It is a vital feature for traders to generate custom OHLCV (Open, High, Low, Close, Volume) candles. It combines historical and real-time data, allowing the creation of real-time custom technical indicators with the use of pandas_ta.
Usage Examples
Initializing Candles
Create an instance of a candle for BTC-USDT from Binance Spot:
Logging Candles on Tick
To log candle data periodically, you can use the on_tick method:
Multiple Candles Initialization
For strategies that require multiple candle intervals or trading pairs, initialize separate instances:
To fetch candles, apply the connector_name above in the get_candle method of CandlesFactory:
Key Methods and Properties
Candles Factory
The CandlesFactory class creates and returns a Candle object based on the specified connector and trading pair. It has a class method get_candle which takes in a connector, trading pair, interval, and max_records as parameters.
The CandlesBase class is the cornerstone for fetching and storing candle data from exchanges. It ensures compatibility across different connectors by utilizing REST and WebSocket connections for data retrieval.
Key Features:
Inherits from
NetworkBase, ensuring network reliability and consistency.Utilizes Rest and WS Assistants for all I/O operations.
Incorporates a double-ended queue to store candles efficiently.
Implements the Throttler module for API rate limiting.
Below are the key methods and properties available in a Candles object.
get_candle Method
get_candle MethodA static method from the CandlesFactory class to obtain candle data:
Parameters:
connector_name: Identifies the data source, likebinanceorbinance_perpetual.trading_pair: The trading pair in 'BASE-QUOTE' format, e.g.,BTC-USDT.interval: The time interval between candles.max_records: Maximum number of candles to store.
start and stop Methods
start and stop MethodsEssential for initializing and terminating the candle data stream:
start(): Begin streaming and collecting candle data.stop(): Terminate the candle data stream.
is_ready Property
is_ready PropertyConfirms if the candle data set is complete:
candles_df Property
candles_df PropertyAccesses the latest DataFrame of candle data:
Last updated