India Equity

Handling Data

Introduction

LEAN passes the data you request to the OnDataon_data method so you can make trading decisions. The default OnDataon_data method accepts a Slice object, but you can define additional OnDataon_data methods that accept different data types. For example, if you define an OnDataon_data method that accepts a TradeBar argument, it only receives TradeBar objects. The Slice object that the OnDataon_data method receives groups all the data together at a single moment in time. To access the Slice outside of the OnDataon_data method, use the CurrentSlicecurrent_slice property of your algorithm.

All the data formats use DataDictionary objects to group data by Symbol and provide easy access to information. The plural of the type denotes the collection of objects. For instance, the TradeBars DataDictionary is made up of TradeBar objects. To access individual data points in the dictionary, you can index the dictionary with the security ticker or Symbolsymbol, but we recommend you use the Symbolsymbol.

To view the resolutions that are available for India Equity data, see Resolutions.

Trades

TradeBar objects are price bars that consolidate individual trades from the exchanges. They contain the open, high, low, close, and volume of trading activity over a period of time.

Tradebar decomposition

TradeBar objects have the following properties:

To get the TradeBar objects in the Slice, index the Slice or index the Barsbars property of the Slice with the security Symbolsymbol. If the security doesn't actively trade or you are in the same time step as when you added the security subscription, the Slice may not contain data for your Symbolsymbol. To avoid issues, check if the Slice contains data for your security before you index the Slice with the security Symbolsymbol.

public override void OnData(Slice slice)
{
    if (slice.Bars.ContainsKey(_symbol))
    {
        var tradeBar = slice.Bars[_symbol];
    }
}
def on_data(self, slice: Slice) -> None:
    trade_bar = slice.bars.get(self._symbol)   # None if not found

You can also iterate through the TradeBars dictionary. The keys of the dictionary are the Symbol objects and the values are the TradeBar objects.

public override void OnData(Slice slice)
{
    foreach (var kvp in slice.Bars)
    {
        var symbol = kvp.Key;
        var tradeBar = kvp.Value;
        var closePrice = tradeBar.Close;
    }
}
def on_data(self, slice: Slice) -> None:
    for symbol, trade_bar in slice.bars.items():
        close_price = trade_bar.close

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: