JToken HandleModifySubscription2(List <ZFrame> ident, JObject msg) { JToken res = null; JObject content = (JObject)msg["content"]; string tickerID = content["ticker_id"].ToString(); var oldSubDef = _subscriptions[tickerID]; var contentDict = (Dictionary <string, dynamic>)content .ToObject(typeof(Dictionary <string, dynamic>)); var newSubDef = new SubscriptionDefinition(oldSubDef).Update(contentDict); if (oldSubDef.Equals(newSubDef)) { // nothing to do res = new JObject(); res["trades"] = "no change"; res["order_book"] = "no change"; return(res); } if (newSubDef.Empty()) { _subscriptions.Pop(tickerID, null); } else { _subscriptions[tickerID] = newSubDef; } var msgMod = (JObject)msg.DeepClone(); ((JObject)msgMod["content"]).Update(JObject.FromObject(oldSubDef.Data)); try { string cmd = msg["command"].ToString(); res = (JToken)_commands[cmd].Invoke(this, new Object[] { ident, msgMod }); } catch (Exception err) { _subscriptions[tickerID] = oldSubDef; throw err; } return(res); }
public SubscriptionDefinition(SubscriptionDefinition other) { Data = new Dict <string, dynamic>(other.Data); }
JToken ModifySubscription(List <ZFrame> ident, JObject msg) { var content = (JObject)msg["content"]; string tickerID = content["ticker_id"].ToString(); SubscriptionDefinition sd = _subscriptions[tickerID]; var oldSubDef = _ctsSubscriptions[tickerID]; L.Info(sd); var market = GetMarket(tickerID); T4.DepthBuffer dbuf = T4.DepthBuffer.NoSubscription; T4.DepthLevels dlvl = T4.DepthLevels.Normal; JToken res = null; if (sd["trades_speed"] > 7) { if (sd["order_book_speed"] > 7) { dbuf = T4.DepthBuffer.FastTrade; } else if (sd["order_book_speed"] > 4) { dbuf = T4.DepthBuffer.SmartTrade; } else if (sd["order_book_speed"] > 0) { dbuf = T4.DepthBuffer.SlowTrade; } else { dbuf = T4.DepthBuffer.TradeOnly; } } else { if (sd["order_book_speed"] > 7) { dbuf = T4.DepthBuffer.FastSmart; } else if (sd["order_book_speed"] > 4) { dbuf = T4.DepthBuffer.Smart; } else if (sd["order_book_speed"] > 0) { dbuf = T4.DepthBuffer.SlowSmart; } } if ((dbuf == T4.DepthBuffer.NoSubscription || dbuf == T4.DepthBuffer.TradeOnly) && sd["emit_quotes"]) { dbuf = T4.DepthBuffer.SlowSmart; dlvl = T4.DepthLevels.BestOnly; } else if (dbuf != T4.DepthBuffer.NoSubscription) { // does cts t4 api support arbitrary depth levels or enum numbers? dlvl = (T4.DepthLevels)Math.Min(sd["order_book_levels"], (int)T4.DepthLevels.All); } CTSSubDef newSubDef = new CTSSubDef(dbuf, dlvl); if (oldSubDef.Equals(newSubDef)) { res = JToken.FromObject("no change"); return(res); } //else //{ // if (newSubDef.DepthBuffer == T4.DepthBuffer.NoSubscription) // { // res["order_book"] = "unsubscribed"; // res["trades"] = "unsubscribed"; // } // else if (newSubDef.DepthBuffer == T4.DepthBuffer.TradeOnly) // { // res["order_book"] = "unsubscribed"; // res["trades"] = "subscribed"; // } //} res = JToken.FromObject(newSubDef.ToString()); _ctsSubscriptions[tickerID] = newSubDef; if (!oldSubDef.handled) { market.MarketCheckSubscription += MarketCheckSubscription; } newSubDef.handled = true; market.DepthSubscribe(dbuf, dlvl); return(res); }