Back

Current Price OnData python

Hi :) I'm wondering how I can get the live price of a stock from OnData. Not self.Securities[symbol].Price I don't want my securities price I want the current tick price on the market. I saw some things with data[symbol].Price or slice[symbol].Price but neither of these work. I'm not sure what the syntax is :(

Update Backtest







Hi Michael, to get the tick price, you should subscribe to the Tick resolution when you add the security. 

self.AddEquity(symbol, Resolution.Tick)

self.AddForex(symbol, Resolution.Tick)

In OnData(self, slice), ticks = slice[symbol] will give you a list of tick objects. Each object has properties like Price, Ask/Bid for forex.

def OnData(self, slice):
ticks = slcie[symbol]
for tick in ticks:
price = tick.Price

 

A slice represents a moment or period of time - a "time slice". Slices are emitted at the end time of the period (slice.EndTime). If you've asked for minute data it will emit at the end of the minute; with data for the trailing minute. Ticks are point values in time. If you've asked for tick data it is an instantaneous object with no period. 

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed