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 OnBid_(Bid bid) { foreach (Strategy current in this.strategiesByInstrument[bid.instrumentId]) { current.OnBid_(bid); } base.OnBid_(bid); }
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 OnBid(Bid bid) { if (this.orders[bid.instrumentId] == null) { return; } if (this.fillOnQuote) { for (int i = 0; i < this.orders[bid.instrumentId].Count; i++) { Order order = this.orders[bid.instrumentId][i]; if (order.side == OrderSide.Sell) { while (true) { switch (order.type) { case OrderType.Market: goto IL_6C; case OrderType.Stop: if (bid.price <= order.stopPx) { order.type = OrderType.Market; continue; } break; case OrderType.Limit: goto IL_81; case OrderType.StopLimit: if (bid.price <= order.stopPx) { order.type = OrderType.Limit; continue; } break; } break; } goto IL_F5; IL_6C: this.Fill(order, bid.price, bid.size); goto IL_F5; IL_81: if (bid.price >= order.price) { if (this.fillAtLimitPrice) { this.Fill(order, order.price, bid.size); } else { this.Fill(order, bid.price, bid.size); } } } IL_F5:; } } }
public Bid(Bid bid) : base(bid) { }
public virtual void OnBid(Bid bid) { }
internal virtual void OnBid_(Bid bid) { if (this.raiseEvents && this.instruments.Contains(bid.instrumentId)) { this.OnBid(this.framework.InstrumentManager.GetById(bid.instrumentId), bid); List<Stop> list = this.stopsByInstrument[bid.instrumentId]; if (list != null) { for (int i = 0; i < list.Count; i++) { list[i].OnBid(bid); } } } LinkedList<Strategy> linkedList = this.strategiesByInstrument[bid.instrumentId]; if (linkedList != null) { for (LinkedListNode<Strategy> linkedListNode = linkedList.First; linkedListNode != null; linkedListNode = linkedListNode.Next) { linkedListNode.Data.OnBid_(bid); } } }
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; } }
public void OnBid(Bid bid) { if (this.orders[bid.instrumentId] == null) { return; } for (int i = 0; i < this.orders[bid.instrumentId].Count; i++) { Order order = this.orders[bid.instrumentId][i]; this.Process(order, bid, this.framework.dataManager.GetAsk(order.instrument)); 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 OnBid(Bid bid) { }
protected internal override void OnBid(Instrument instrument, Bid bid) { this.alphaComponent.OnBid(bid); this.positionComponent.OnBid(bid); }
public Quote(Bid bid, Ask ask) { this.Bid = bid; this.Ask = ask; this.DateTime = bid.DateTime > ask.DateTime ? bid.DateTime : ask.DateTime; }
public void OnBid(Bid bid) { if (this.orders[bid.instrumentId] == null) { return; } if (this.fillOnQuote) { for (int i = 0; i < this.orders[bid.instrumentId].Count; i++) { Order order = this.orders[bid.instrumentId][i]; if (order.side == OrderSide.Sell) { while (true) { switch (order.type) { case OrderType.Market: goto IL_6C; case OrderType.Stop: if (bid.price <= order.stopPx) { order.type = OrderType.Market; continue; } break; case OrderType.Limit: goto IL_81; case OrderType.StopLimit: if (bid.price <= order.stopPx) { order.type = OrderType.Limit; continue; } break; } break; } goto IL_F5; IL_6C: this.Fill(order, bid.price, bid.size); goto IL_F5; IL_81: if (bid.price >= order.price) { if (this.fillAtLimitPrice) { this.Fill(order, order.price, bid.size); } else { this.Fill(order, bid.price, bid.size); } } } IL_F5 :; } } }
internal void OnBid(Bid bid) { this.bid[bid.instrumentId] = bid; }
protected internal virtual void OnBid(Instrument instrument, Bid bid) { }
internal void OnBid(Bid bid) { if (this.traceOnQuote && this.side == PositionSide.Long) { this.currPrice = bid.price; this.fillPrice = bid.price; this.trailPrice = bid.price; this.CheckStop(); } }
public void EmitBid(Bid bid) { this.framework.eventManager.OnEvent(bid); }
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; }
internal void OnBid(Bid bid) { if (this.strategy != null && this.strategy.status == StrategyStatus.Running) { this.strategy.OnBid_(bid); } }
private void FireBid(int InstrumentId, DateTime _dateTime, DateTime _exchangeDateTime, DepthMarketDataNClass pDepthMarketData, DepthMarketDataNClass DepthMarket) { do { if (pDepthMarketData.Bids == null || pDepthMarketData.Bids.Length == 0) break; if (DepthMarket.Bids != null && DepthMarket.Bids.Length > 0) { if (DepthMarket.Bids[0].Size == pDepthMarketData.Bids[0].Size && DepthMarket.Bids[0].Price == pDepthMarketData.Bids[0].Price) { // 由于与上次一样,不能动 break; } } Bid bid = new Bid( _dateTime, _exchangeDateTime, this.id, InstrumentId, pDepthMarketData.Bids[0].Price, pDepthMarketData.Bids[0].Size); EmitData(bid); } while (false); }
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; } }