public Level2Snapshot(DateTime dateTime, byte providerId, int instrumentId, Bid[] bids, Ask[] asks) : base(dateTime) { this.providerId = providerId; this.instrumentId = instrumentId; this.bids = bids; this.asks = asks; }
internal override void OnAsk_(Ask ask) { foreach (Strategy current in this.strategiesByInstrument[ask.instrumentId]) { current.OnAsk_(ask); } base.OnAsk_(ask); }
public Quote(Bid bid, Ask ask) { this.bid = bid; this.ask = ask; if (bid.dateTime > ask.DateTime) { this.dateTime = bid.dateTime; return; } this.dateTime = ask.dateTime; }
public Quote GetQuote(int level) { Bid bid = new Bid(); Ask ask = new Ask(); if (this.bids.Count < level) { Tick tick = this.bids[level]; bid = new Bid(tick.dateTime, tick.providerId, tick.instrumentId, tick.price, tick.size); } if (this.asks.Count < level) { Tick tick2 = this.asks[level]; ask = new Ask(tick2.dateTime, tick2.providerId, tick2.instrumentId, tick2.price, tick2.size); } return new Quote(bid, ask); }
public void Import(string fileName, string symbol, int type) { Console.WriteLine("Starting export: " + fileName + " " + symbol); int num = 0; int num2 = 0; int num3 = 0; TextReader textReader = File.OpenText(fileName); Instrument instrument = this.framework.InstrumentManager.Get(symbol); if (instrument == null) { instrument = new Instrument(InstrumentType.Stock, symbol, "", 1); this.framework.InstrumentManager.Add(instrument, true); } int num4 = 0; double num5 = -1.0; int num6 = -1; double num7 = -1.0; int num8 = -1; textReader.ReadLine(); while (true) { string text = textReader.ReadLine(); if (text == null) { break; } string[] array = text.Split(new char[] { ',' }); CultureInfo invariantCulture = CultureInfo.InvariantCulture; switch (type) { case 4: { DateTime dateTime = DateTime.ParseExact(array[0], "yyyy-MM-dd HH:mm:ss.fff", invariantCulture); double num9 = double.Parse(array[1], invariantCulture); int num10 = int.Parse(array[2]); if (num9 > 0.0 && num10 > 0) { Trade obj = new Trade(dateTime, 1, instrument.Id, num9, num10); this.framework.DataManager.Save(instrument, obj); num3++; } break; } case 5: { DateTime dateTime2 = DateTime.ParseExact(array[0], "yyyy-MM-dd HH:mm:ss.fff", invariantCulture); double num11 = double.Parse(array[1], invariantCulture); int num12 = int.Parse(array[2]); double num13 = double.Parse(array[3], invariantCulture); int num14 = int.Parse(array[4]); if (num11 > 0.0 && num12 > 0 && (num5 != num11 || num6 != num12)) { Bid obj2 = new Bid(dateTime2, 1, instrument.Id, num11, num12); this.framework.DataManager.Save(instrument, obj2); num5 = num11; num6 = num12; num2++; } if (num13 > 0.0 && num14 > 0 && (num7 != num13 || num8 != num14)) { Ask obj3 = new Ask(dateTime2, 1, instrument.Id, num13, num14); this.framework.DataManager.Save(instrument, obj3); num7 = num13; num8 = num14; num++; } break; } } if (num4 % 100000 == 0) { Console.WriteLine(num4); } num4++; } Console.WriteLine(string.Concat(new object[] { "Lines = ", num4, " bids: ", num2, " asks: ", num, " trades: ", num3 })); textReader.Close(); }
public Instrument(Instrument instrument) : this() { this.id = instrument.id; this.type = instrument.type; this.symbol = instrument.symbol; this.description = instrument.description; this.exchange = instrument.exchange; this.currencyId = instrument.currencyId; this.tickSize = instrument.tickSize; this.putcall = instrument.putcall; this.factor = instrument.factor; this.strike = instrument.strike; this.maturity = instrument.maturity; this.margin = instrument.margin; foreach (Leg current in instrument.Legs) { this.Legs.Add(new Leg(current.Instrument, current.Weight)); } this.trade = instrument.Trade; this.bid = instrument.Bid; this.ask = instrument.Ask; }
public virtual void OnAsk(Ask ask) { }
protected internal virtual void OnAsk(Instrument instrument, Ask ask) { }
public Quote(Bid bid, Ask ask) { this.Bid = bid; this.Ask = ask; this.DateTime = bid.DateTime > ask.DateTime ? bid.DateTime : ask.DateTime; }
public void OnAsk(Ask ask) { if (this.orders[ask.instrumentId] == null) { return; } for (int i = 0; i < this.orders[ask.instrumentId].Count; i++) { Order order = this.orders[ask.instrumentId][i]; this.Process(order, this.framework.dataManager.GetBid(order.instrument), ask); if (this.addQueueToOrderText) { order.Text = order.queueSize.ToString(); } } }
private void Process(Order order, Bid bid, Ask ask) { if (ask == null || bid == null) { return; } if (!order.isQueueCalculated) { this.SetQueueSizeByQuote(order); } if (order.type == OrderType.Limit) { if (order.isOutPrice) { double queueSize = order.queueSize; this.SetQueueSizeByQuote(order); if (order.isOutPrice) { order.queueSize = queueSize; } } if (order.side == OrderSide.Buy) { if (bid.price < order.price) { order.queueSize = 0.0; this.Fill(order, order.price, (int)order.leavesQty); return; } if (bid.price == order.price && order.queueSize > (double)bid.size + order.qty) { order.queueSize = (double)bid.size + order.qty; return; } } else { if (order.side == OrderSide.Sell) { if (ask.price > order.price) { order.queueSize = 0.0; this.Fill(order, order.price, (int)order.leavesQty); return; } if (ask.price == order.price && order.queueSize > (double)ask.size + order.qty) { order.queueSize = (double)ask.size + order.qty; return; } } } } else { if (order.side == OrderSide.Buy) { if ((double)ask.size >= order.qty) { this.Fill(order, ask.price, (int)order.leavesQty); return; } this.Fill(order, ask.price, ask.size); if (order.leavesQty > 0.0) { double num = ask.price + order.instrument.tickSize; double num2 = Math.Ceiling(order.leavesQty / (double)ask.size); if (num2 >= 1.0) { int num3 = 0; while ((double)num3 < num2) { if (order.leavesQty >= (double)ask.size) { this.Fill(order, num + (double)num3 * order.instrument.tickSize, ask.size); } else { if (order.leavesQty < (double)ask.size) { this.Fill(order, num + (double)num3 * order.instrument.tickSize, (int)order.leavesQty); return; } } num3++; } return; } this.Fill(order, num, (int)order.leavesQty); return; } } else { if (order.side == OrderSide.Sell) { if ((double)bid.size >= order.leavesQty) { this.Fill(order, bid.price, (int)order.leavesQty); return; } this.Fill(order, bid.price, bid.size); if (order.leavesQty > 0.0) { double num4 = bid.price - order.instrument.tickSize; double num5 = Math.Ceiling(order.leavesQty / (double)bid.size); if (num5 >= 1.0) { int num6 = 0; while ((double)num6 < num5) { if (order.leavesQty >= (double)bid.size) { this.Fill(order, num4 - (double)num6 * order.instrument.tickSize, bid.size); } else { if (order.leavesQty < (double)bid.size) { this.Fill(order, num4 - (double)num6 * order.instrument.tickSize, (int)order.leavesQty); return; } } num6++; } return; } this.Fill(order, num4, (int)order.leavesQty); } } } } }
protected virtual void OnAsk(Ask Ask) { }
protected internal override void OnAsk(Instrument instrument, Ask ask) { this.alphaComponent.OnAsk(ask); this.positionComponent.OnAsk(ask); }
private void FireAsk(int InstrumentId, DateTime _dateTime, DateTime _exchangeDateTime, DepthMarketDataNClass pDepthMarketData, DepthMarketDataNClass DepthMarket) { do { if (pDepthMarketData.Asks == null || pDepthMarketData.Asks.Length == 0) break; if (DepthMarket.Asks != null && DepthMarket.Asks.Length > 0) { if (DepthMarket.Asks[0].Size == pDepthMarketData.Asks[0].Size && DepthMarket.Asks[0].Price == pDepthMarketData.Asks[0].Price) { // 由于与上次一样,不能动 break; } } Ask ask = new Ask( _dateTime, _exchangeDateTime, this.id, InstrumentId, pDepthMarketData.Asks[0].Price, pDepthMarketData.Asks[0].Size); EmitData(ask); } while (false); }
public void OnAsk(Ask ask) { if (this.orders[ask.instrumentId] == null) { return; } if (this.fillOnQuote) { for (int i = 0; i < this.orders[ask.instrumentId].Count; i++) { Order order = this.orders[ask.instrumentId][i]; if (order.side == OrderSide.Buy) { while (true) { switch (order.type) { case OrderType.Market: goto IL_6B; case OrderType.Stop: if (ask.price >= order.stopPx) { order.type = OrderType.Market; continue; } break; case OrderType.Limit: goto IL_80; case OrderType.StopLimit: if (ask.price >= order.stopPx) { order.type = OrderType.Limit; continue; } break; } break; } goto IL_F4; IL_6B: this.Fill(order, ask.price, ask.size); goto IL_F4; IL_80: if (ask.price <= order.price) { if (this.fillAtLimitPrice) { this.Fill(order, order.price, ask.size); } else { this.Fill(order, ask.price, ask.size); } } } IL_F4 :; } } }
internal void OnAsk(Ask ask) { this.ask[ask.instrumentId] = ask; }
public void OutputSeries(out IDataSeries trades, out IDataSeries bids, out IDataSeries asks) { trades = new TickSeries(); bids = new TickSeries(); asks = new TickSeries(); PbTickCodec codec = new PbTickCodec(); int TradingDay = -1; int _lastTradeSize = 0; foreach (var s in Series) { if(TradingDay != s.TradingDay) { _lastTradeSize = 0; TradingDay = s.TradingDay; } var dateTime = codec.GetDateTime(s.ActionDay == 0 ? s.TradingDay : s.ActionDay).Add(codec.GetUpdateTime(s)); var tick = PbTick2DepthMarketDataNClass(codec, s); if(SubscribeExternData) { var trade = new TradeEx(dateTime, 0, _InstrumentId, tick.LastPrice, (int)tick.Volume); trade.Size -= _lastTradeSize; trade.DepthMarketData = tick; trades.Add(trade); } else { var trade = new Trade(dateTime, 0, _InstrumentId, tick.LastPrice, (int)tick.Volume); trade.Size -= _lastTradeSize; trades.Add(trade); } if (tick.Bids != null && tick.Bids.Length > 0) { var bid = new Bid(dateTime, 0, _InstrumentId, tick.Bids[0].Price, tick.Bids[0].Size); bids.Add(bid); } if (tick.Asks != null && tick.Asks.Length > 0) { var ask = new Ask(dateTime, 0, _InstrumentId, tick.Asks[0].Price, tick.Asks[0].Size); asks.Add(ask); } _lastTradeSize = (int)tick.Volume; } }
internal void OnAsk(Ask ask) { if (this.traceOnQuote && this.side == PositionSide.Short) { this.currPrice = ask.price; this.fillPrice = ask.price; this.trailPrice = ask.price; this.CheckStop(); } }
internal virtual void OnAsk_(Ask ask) { if (this.raiseEvents && this.instruments.Contains(ask.instrumentId)) { this.OnAsk(this.framework.InstrumentManager.GetById(ask.instrumentId), ask); } List<Stop> list = this.stopsByInstrument[ask.instrumentId]; if (list != null) { for (int i = 0; i < list.Count; i++) { list[i].OnAsk(ask); } } LinkedList<Strategy> linkedList = this.strategiesByInstrument[ask.instrumentId]; if (linkedList != null) { for (LinkedListNode<Strategy> linkedListNode = linkedList.First; linkedListNode != null; linkedListNode = linkedListNode.Next) { linkedListNode.Data.OnAsk_(ask); } } }
public void EmitAsk(Ask ask) { this.framework.eventManager.OnEvent(ask); }
public Ask(Ask ask) : base(ask) { }
public void OnAsk(Ask ask) { if (this.orders[ask.instrumentId] == null) { return; } if (this.fillOnQuote) { for (int i = 0; i < this.orders[ask.instrumentId].Count; i++) { Order order = this.orders[ask.instrumentId][i]; if (order.side == OrderSide.Buy) { while (true) { switch (order.type) { case OrderType.Market: goto IL_6B; case OrderType.Stop: if (ask.price >= order.stopPx) { order.type = OrderType.Market; continue; } break; case OrderType.Limit: goto IL_80; case OrderType.StopLimit: if (ask.price >= order.stopPx) { order.type = OrderType.Limit; continue; } break; } break; } goto IL_F4; IL_6B: this.Fill(order, ask.price, ask.size); goto IL_F4; IL_80: if (ask.price <= order.price) { if (this.fillAtLimitPrice) { this.Fill(order, order.price, ask.size); } else { this.Fill(order, ask.price, ask.size); } } } IL_F4:; } } }
internal void OnAsk(Ask ask) { if (this.strategy != null && this.strategy.status == StrategyStatus.Running) { this.strategy.OnAsk_(ask); } }
private void Send(Order order) { base.EmitExecutionReport(new ExecutionReport { dateTime = this.framework.Clock.DateTime, order = order, commandID = order.id, instrument = order.instrument, ordQty = order.qty, timeInForce = order.timeInForce, execType = ExecType.ExecNew, ordStatus = OrderStatus.New, currencyId = order.instrument.currencyId, ordType = order.type, side = order.side, cumQty = 0.0, lastQty = 0.0, leavesQty = 0.0, lastPx = 0.0, avgPx = 0.0, text = order.text }); int id = order.instrument.Id; if (this.orders[id] == null) { this.orders[id] = new List <Order>(); } this.orders[id].Add(order); switch (order.type) { case OrderType.Market: if (!this.fillMarketOnNext) { Instrument instrument = order.instrument; if (this.fillOnQuote) { switch (order.side) { case OrderSide.Buy: { Ask ask = this.framework.DataManager.GetAsk(instrument); if (ask != null) { this.Fill(order, ask.Price, ask.Size); return; } break; } case OrderSide.Sell: { Bid bid = this.framework.DataManager.GetBid(instrument); if (bid != null) { this.Fill(order, bid.Price, bid.Size); return; } break; } } } if (this.fillOnTrade) { Trade trade = this.framework.DataManager.GetTrade(instrument); if (trade != null) { this.Fill(order, trade.Price, trade.Size); } } } break; case OrderType.Stop: case OrderType.Limit: break; default: return; } }