Back

Void OnData(Slice slice) not triggered

I am new to QC and creating new brokerage I have successfully implemented IBrokerage and IDataQueueHandler 
In the algorithm, ondata method does not called,

public override void OnData(Slice slice)

where as contineously getting tick data in

private void OnTradeReceived(Tick trade)

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.


Without further details on your code, the custom brokerages and the data you have subscribed to, it's virtually impossible to tell what's wrong.

0

Hi Douglas Stridsberg   you can find git repository here
https://github.com/meghs91/Alphamatic.git

0

Hey, sorry, I don't have time to do private bug testing of closed repos and I declined your invitation. If you seek help on forums, you need to (at the very least) be able to provide a minimal example of your code so people can study it and find out what's going on.

You need to look at a working version of LEAN and break at the OnData method to see what is calling it, and work your way backwards through it to compare what is happening in master vs what is happening in your code.

0

thanks, Douglas Stridsberg for the tip. here is the gist for brokerage and IDataQueueHandler

Gist Link MyBrokerage.cs

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using NodaTime;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Logging;
using QuantConnect.Packets;
using RestSharp;
using KTick = KiteConnect.Tick;
using Tick = QuantConnect.Data.Market.Tick;

namespace QuantConnect.Brokerages.MyBrokerage
{
public partial class MyBrokerage : Brokerage, IDataQueueHandler
{
/// <summary>
/// The list of ticks received
/// </summary>
private readonly List<Tick> _ticks = new List<Tick>();

private readonly ConcurrentDictionary<string, Symbol> _subscribedSymbols = new ConcurrentDictionary<string, Symbol>();

#region IDataQueueHandler implementation

/// <summary>
/// Get the next ticks from the live trading data queue
/// </summary>
/// <returns>IEnumerable list of ticks since the last update.</returns>
public IEnumerable<BaseData> GetNextTicks()
{
lock (_ticks)
{
var copy = _ticks.ToArray();
_ticks.Clear();
return copy;
}
}

/// <summary>
/// Adds the specified symbols to the subscription
/// </summary>
/// <param name="job">Job we're subscribing for:</param>
/// <param name="symbols">The symbols to be added keyed by SecurityType</param>
public void Subscribe(LiveNodePacket job, IEnumerable<Symbol> symbols)
{
var symbolsToSubscribe = symbols.Where(x => !_subscribedSymbols.ContainsKey(x.Value));

foreach (var symbol in symbolsToSubscribe.Where(CanSubscribe))
{
//FOLLOWING CODE JUST TO SUBSCRIBLE ONLY TCS SPECIFIC SECURITIES FOR TESTING PURPOSE
Log.Trace($"MyBrokerage.Subscribe(): {symbol}");
Symbol sym = Symbol.Create("TCS", SecurityType.Equity, Market.USA);
_subscribedSymbols.TryAdd(sym.Value, symbol);
ticker.Subscribe(Tokens: new UInt32[] { 2953217 }); // SUBSCRIBE TO BROKER DATA FEED
}

}

/// <summary>
/// Removes the specified symbols from the subscription
/// </summary>
/// <param name="job">Job we're processing.</param>
/// <param name="symbols">The symbols to be removed keyed by SecurityType</param>
public void Unsubscribe(LiveNodePacket job, IEnumerable<Symbol> symbols)
{
var symbolsToUnsubscribe = symbols.Where(x => _subscribedSymbols.ContainsKey(x.Value));

foreach (var symbol in symbolsToUnsubscribe.Where(CanSubscribe))
{
Log.Trace($"MyBrokerage.Unsubscribe(): {symbol}");

Symbol removed;
_subscribedSymbols.TryRemove(symbol.Value, out removed);
}
ticker.UnSubscribe(symbolsToUnsubscribe.Select((Symbol arg) => UInt32.Parse(arg.Value)).ToArray());

}

/// <summary>
/// Returns true if this brokerage supports the specified symbol
/// </summary>
private static bool CanSubscribe(Symbol symbol)
{
// ignore unsupported security types
if (symbol.ID.SecurityType != SecurityType.Equity)
return false;

return symbol.Value.ToLower().IndexOf("universe", StringComparison.Ordinal) == -1;
}

/// <summary>
/// Event handler for streaming trade ticks
/// </summary>
/// <param name="trade">The data object containing the received tick</param>
private void OnTradeReceived(KTick trade)
{
Symbol symbol = Symbol.Create("TCS", SecurityType.Equity, Market.NSE);

var time = DateTime.Now;

// live ticks timestamps must be in exchange time zone
DateTimeZone exchangeTimeZone;
if (!_symbolExchangeTimeZones.TryGetValue(key: symbol, value: out exchangeTimeZone))
{
exchangeTimeZone = _marketHours.GetExchangeHours(Market.USA, symbol, SecurityType.Equity).TimeZone;
_symbolExchangeTimeZones.Add(symbol, exchangeTimeZone);
}
time = time.ConvertFromUtc(exchangeTimeZone);

var tick = new Tick(System.DateTime.Now, symbol, trade.LastPrice, trade.LastPrice, trade.LastPrice)
{
TickType = TickType.Trade,
Quantity = trade.LastQuantity
};
//WE RECEIVED DATA HERE
Log.Trace($"Tick : { tick.LastPrice}");
lock (_ticks)
{
_ticks.Add(tick);
}
}

#endregion

#region IBrokerage implementation
public MyBrokerage(IOrderProvider orderProvider, ISecurityProvider securityProvider, string appID, string appSecret, string accessToken, string userID) : base("MyBrokerage")
{
MyAPIKey = appID;
MySecret = appSecret;
MyAccessToken = accessToken;
MyUserId = userID;

kite = new Kite(MyAPIKey, Debug: true);
kite.SetAccessToken(MyAccessToken);


_orderProvider = orderProvider;
_securityProvider = securityProvider;

_marketHours = MarketHoursDatabase.FromDataFolder();

}

/// <summary>
/// Connects the client to the broker's remote servers
/// </summary>
public override void Connect()
{
ticker.OnTick += (TickData) => OnTick(TickData);
}

//Other stub method implemented

#endregion
}
}

 

0

Cool! For Kite Brokerage? Write to us in the slack channel Meghdoot, we'd be happy to help. Will you contribute the integration back to the open source?

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.


Jared Broad Yes, I'm working on Kite Brokerage, definitely love to contribute.


for those facing the same issue, this is due to timezone and data resolution cause the issue

Time resolution changed to .Second from .Tick  and 

set timezone to local timezone previously it was default "America/New_York"

0

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