public void Subscrible(Security security) { SecurityIb contractIb = _secIB.Find( contract => contract.Symbol + "_" + contract.SecType + "_" + contract.Exchange == security.Name); if (contractIb == null) { return; } if (_connectedContracts.Find(s => s == security.Name) == null) { _connectedContracts.Add(security.Name); _client.GetMarketDataToSecurity(contractIb); if (contractIb.CreateMarketDepthFromTrades == false) { _client.GetMarketDepthToSecurity(contractIb); } } }
/// <summary> /// загрузить позицию по портфелю /// </summary> private void LoadPortfolioPosition2() { int msgVersion = TcpReadInt(); string account = TcpReadString(); SecurityIb contract = new SecurityIb(); contract.ConId = TcpReadInt(); contract.Symbol = TcpReadString(); contract.SecType = TcpReadString(); contract.Expiry = TcpReadString(); contract.Strike = TcpReadDouble(); contract.Right = TcpReadString(); contract.Multiplier = TcpReadString(); contract.Exchange = TcpReadString(); contract.Currency = TcpReadString(); contract.LocalSymbol = TcpReadString(); if (msgVersion >= 2) { contract.TradingClass = TcpReadString(); } int pos = TcpReadInt(); if (msgVersion >= 3) { TcpReadDouble(); } if (NewPortfolioPosition != null) { NewPortfolioPosition(contract, account, pos); } }
private void AddTick(Trade trade, SecurityIb sec) { try { if (trade.Price <= 0) { return; } ServerTime = trade.Time; SecurityIb contractIb = _secIB.Find( contract => contract.ConId == sec.ConId); if (contractIb != null && contractIb.CreateMarketDepthFromTrades) { SendMdFromTrade(trade); } if (NewTradesEvent != null) { NewTradesEvent(trade); } } catch (Exception error) { SendLogMessage(error.ToString(), LogMessageType.Error); } }
public void SendOrder(Order order) { SecurityIb contractIb = _secIB.Find( contract => contract.Symbol + "_" + contract.SecType + "_" + contract.Exchange == order.SecurityNameCode); if (contractIb == null) { return; } if (contractIb.MinTick < 1) { int decimals = 0; decimal minTick = Convert.ToDecimal(contractIb.MinTick); while (true) { minTick = minTick * 10; decimals++; if (minTick > 1) { break; } } while (true) { if (order.Price % Convert.ToDecimal(contractIb.MinTick) != 0) { string minusVal = "0."; for (int i = 0; i < decimals - 1; i++) { minusVal += "0"; } minusVal += "1"; order.Price -= minusVal.ToDecimal(); } else { break; } } } _client.ExecuteOrder(order, contractIb); }
/// <summary> /// подписываемся на стаканы /// </summary> public void GetMarketDepthToSecurity(SecurityIb contract) { if (_namesSecuritiesWhoOptOnMarketDepth == null) { _namesSecuritiesWhoOptOnMarketDepth = new List <string>(); } if (_namesSecuritiesWhoOptOnMarketDepth.Find( s => s == contract.Symbol + "_" + contract.SecType + "_" + contract.Exchange) != null) { return; } _namesSecuritiesWhoOptOnMarketDepth.Add(contract.Symbol + "_" + contract.SecType + "_" + contract.Exchange); // _twsServer.reqMktDepthEx(contractIb.ConId, contractIb, 10, new TagValueList()); if (!_isConnected) { return; } try { TcpWrite(10); TcpWrite(5); TcpWrite(contract.ConId.ToString()); TcpWrite(contract.ConId.ToString()); TcpWrite(contract.Symbol); TcpWrite(contract.SecType); TcpWrite(contract.Expiry); TcpWrite(contract.Strike); TcpWrite(contract.Right); TcpWrite(contract.Multiplier); TcpWrite(contract.Exchange); TcpWrite(contract.Currency); TcpWrite(contract.LocalSymbol); TcpWrite(contract.TradingClass); TcpWrite("10"); TcpWrite(""); TcpSendMessage(); } catch (Exception error) { SendLogMessage(error.ToString(), LogMessageType.Error); } }
void _ibClient_NewPortfolioPosition(SecurityIb contract, string accountName, int value) { try { if (_portfolios == null || _portfolios.Count == 0) { return; } // see if you already have the right portfolio / смотрим, есть ли уже нужный портфель Portfolio portfolio = _portfolios.Find(portfolio1 => portfolio1.Number == accountName); if (portfolio == null) { //SendLogMessage("обновляли позицию. Не можем найти портфель"); return; } // see if you already have the right Os.Engine security / смотрим, есть ли нужная бумага в формате Os.Engine string name = contract.Symbol + "_" + contract.SecType + "_" + contract.Exchange; if (_securities == null || _securities.Find(security => security.Name == name) == null) { //SendLogMessage("обновляли позицию. Не можем найти бумагу. " + contract.Symbol); return; } // update the contract position / обновляем позицию по контракту PositionOnBoard positionOnBoard = new PositionOnBoard(); positionOnBoard.SecurityNameCode = name; positionOnBoard.PortfolioName = accountName; positionOnBoard.ValueCurrent = value; portfolio.SetNewPosition(positionOnBoard); if (PortfolioEvent != null) { PortfolioEvent(_portfolios); } } catch (Exception error) { SendLogMessage(error.ToString(), LogMessageType.Error); } }
/// <summary> /// подписываемся на тики /// </summary> public void GetMarketDataToSecurity(SecurityIb contract) { if (_namesSecuritiesWhoOptOnTrades == null) { _namesSecuritiesWhoOptOnTrades = new List <string>(); } if (_namesSecuritiesWhoOptOnTrades.Find( s => s == contract.Symbol + "_" + contract.SecType + "_" + contract.Exchange) != null) { return; } _namesSecuritiesWhoOptOnTrades.Add(contract.Symbol + "_" + contract.SecType + "_" + contract.Exchange); if (!_isConnected) { return; } try { TcpWrite(1); TcpWrite(11); TcpWrite(contract.ConId); TcpWrite(0); TcpWrite(contract.Symbol); TcpWrite(contract.SecType); TcpWrite(""); TcpWrite(0); TcpWrite(null); TcpWrite(""); TcpWrite(contract.Exchange); TcpWrite(""); TcpWrite(contract.Currency); TcpWrite(""); TcpWrite(null); TcpWrite(false); TcpWrite(""); TcpWrite(false); TcpWrite(""); TcpSendMessage(); } catch (Exception error) { SendLogMessage(error.ToString(), LogMessageType.Error); throw; } }
/// <summary> /// загрузить трэйд /// </summary> private void LoadTrade() { int msgVersion = TcpReadInt(); int requestId = TcpReadInt(); int tickType = TcpReadInt(); decimal price = TcpReadDecimal(); if (msgVersion < 2) { return; } var size = TcpReadInt(); if (msgVersion >= 3) { TcpReadInt(); } if (tickType != 1 && tickType != 2 && tickType != 4) { return; } SecurityIb security = _serverSecurities.Find(sec => sec.ConId == requestId); if (security == null) { return; } Trade trade = new Trade(); trade.Price = price; trade.Volume = size; trade.Time = DateTime.Now; trade.SecurityNameCode = security.Symbol + "_" + security.SecType + "_" + security.Exchange; if (NewTradeEvent != null) { NewTradeEvent(trade); } }
private void SaveSecFromTable() { if (SecToSubscrible == null || SecToSubscrible.Count == 0) { return; } for (int i = 0; i < _grid.Rows.Count; i++) { SecurityIb security = SecToSubscrible[i]; security.Symbol = Convert.ToString(_grid.Rows[i].Cells[0].Value); security.Exchange = Convert.ToString(_grid.Rows[i].Cells[1].Value); security.SecType = Convert.ToString(_grid.Rows[i].Cells[2].Value); security.LocalSymbol = Convert.ToString(_grid.Rows[i].Cells[3].Value); security.PrimaryExch = Convert.ToString(_grid.Rows[i].Cells[4].Value); } }
/// <summary> /// взять детали по бумаге /// </summary> public void GetSecurityDetail(SecurityIb contract) { if (!_isConnected) { return; } try { TcpWrite(9); TcpWrite(7); TcpWrite(-1); TcpWrite(contract.ConId); TcpWrite(contract.Symbol); TcpWrite(contract.SecType); TcpWrite(contract.Expiry); TcpWrite(contract.Strike); TcpWrite(contract.Right); TcpWrite(contract.Multiplier); TcpWrite(contract.Exchange); TcpWrite(contract.Currency); TcpWrite(contract.LocalSymbol); TcpWrite(contract.TradingClass); TcpWrite(contract.IncludeExpired); TcpWrite(contract.SecIdType); TcpWrite(contract.SecId); TcpSendMessage(); } catch (Exception error) { SendLogMessage(error.ToString(), LogMessageType.Error); } }
/// <summary> /// request instrument history /// запрос истории по инструменту /// </summary> public List <Candle> GetCandleHistory(string nameSec, TimeFrame tf) { SecurityIb contractIb = _secIB.Find( contract => contract.Symbol + "_" + contract.SecType + "_" + contract.Exchange == nameSec); if (contractIb == null) { return(null);; } DateTime timeEnd = DateTime.Now.ToUniversalTime(); DateTime timeStart = timeEnd.AddMinutes(60); string barSize = "1 min"; int mergeCount = 0; if (tf == TimeFrame.Sec1) { barSize = "1 sec"; timeStart = timeEnd.AddMinutes(10); } else if (tf == TimeFrame.Sec5) { barSize = "5 secs"; } else if (tf == TimeFrame.Sec15) { barSize = "15 secs"; } else if (tf == TimeFrame.Sec30) { barSize = "30 secs"; } else if (tf == TimeFrame.Min1) { timeStart = timeEnd.AddHours(5); barSize = "1 min"; } else if (tf == TimeFrame.Min5) { timeStart = timeEnd.AddHours(25); barSize = "5 mins"; } else if (tf == TimeFrame.Min15) { timeStart = timeEnd.AddHours(75); barSize = "15 mins"; } else if (tf == TimeFrame.Min30) { timeStart = timeEnd.AddHours(150); barSize = "30 mins"; } else if (tf == TimeFrame.Hour1) { timeStart = timeEnd.AddHours(1300); barSize = "1 hour"; } else if (tf == TimeFrame.Hour2) { timeStart = timeEnd.AddHours(2100); barSize = "1 hour"; mergeCount = 2; } else if (tf == TimeFrame.Hour4) { timeStart = timeEnd.AddHours(4200); barSize = "1 hour"; mergeCount = 4; } else if (tf == TimeFrame.Day) { barSize = "1 day"; timeStart = timeEnd.AddDays(701); } else { return(null); } CandlesRequestResult = null; _client.GetCandles(contractIb, timeEnd, timeStart, barSize, "TRADES"); DateTime startSleep = DateTime.Now; while (true) { Thread.Sleep(1000); if (startSleep.AddSeconds(30) < DateTime.Now) { break; } if (CandlesRequestResult != null) { break; } } if (CandlesRequestResult != null && CandlesRequestResult.CandlesArray.Count != 0) { if (mergeCount != 0) { List <Candle> newCandles = Merge(CandlesRequestResult.CandlesArray, mergeCount); CandlesRequestResult.CandlesArray = newCandles; return(StraichCandles(CandlesRequestResult)); } return(StraichCandles(CandlesRequestResult)); } _client.GetCandles(contractIb, timeEnd, timeStart, barSize, "MIDPOINT"); startSleep = DateTime.Now; while (true) { Thread.Sleep(1000); if (startSleep.AddSeconds(30) < DateTime.Now) { break; } if (CandlesRequestResult != null) { break; } } if (CandlesRequestResult != null && CandlesRequestResult.CandlesArray.Count != 0) { if (mergeCount != 0) { List <Candle> newCandles = Merge(CandlesRequestResult.CandlesArray, mergeCount); CandlesRequestResult.CandlesArray = newCandles; return(StraichCandles(CandlesRequestResult)); } return(StraichCandles(CandlesRequestResult)); } return(null); }
void _ibClient_NewMarketDepth(int id, int position, int operation, int side, decimal price, int size) { try { // take all the necessary data / берём все нужные данные SecurityIb myContract = _secIB.Find(contract => contract.ConId == id); if (myContract == null) { return; } if (position > 10) { return; } string name = myContract.Symbol + "_" + myContract.SecType + "_" + myContract.Exchange; Security mySecurity = _securities.Find(security => security.Name == name); if (mySecurity == null) { return; } if (_depths == null) { _depths = new List <MarketDepth>(); } MarketDepth myDepth = _depths.Find(depth => depth.SecurityNameCode == name); if (myDepth == null) { myDepth = new MarketDepth(); myDepth.SecurityNameCode = name; _depths.Add(myDepth); } myDepth.Time = DateTime.Now; Side sideLine; if (side == 1) { // ask/аск sideLine = Side.Buy; } else { // bid/бид sideLine = Side.Sell; } List <MarketDepthLevel> bids = myDepth.Bids; List <MarketDepthLevel> asks = myDepth.Asks; if (asks == null || asks.Count < 10) { asks = new List <MarketDepthLevel>(); bids = new List <MarketDepthLevel>(); for (int i = 0; i < 10; i++) { asks.Add(new MarketDepthLevel()); bids.Add(new MarketDepthLevel()); } myDepth.Bids = bids; myDepth.Asks = asks; } if (operation == 2) {// if need to remove / если нужно удалить if (sideLine == Side.Buy) { // asks.RemoveAt(position); MarketDepthLevel level = bids[position]; level.Ask = 0; level.Bid = 0; level.Price = 0; } else if (sideLine == Side.Sell) { //bids.RemoveAt(position); MarketDepthLevel level = asks[position]; level.Ask = 0; level.Bid = 0; level.Price = 0; } } else if (operation == 0 || operation == 1) { // need to update / нужно обновить if (sideLine == Side.Buy) { MarketDepthLevel level = bids[position]; level.Bid = Convert.ToDecimal(size); level.Ask = 0; level.Price = price; } else if (sideLine == Side.Sell) { MarketDepthLevel level = asks[position]; level.Bid = 0; level.Ask = Convert.ToDecimal(size); level.Price = price; } } if (myDepth.Bids[0].Price != 0 && myDepth.Asks[0].Price != 0) { MarketDepth copy = myDepth.GetCopy(); if (MarketDepthEvent != null) { MarketDepthEvent(copy); } } } catch (Exception error) { SendLogMessage(error.ToString(), LogMessageType.Error); } }
void _ibClient_NewContractEvent(SecurityIb contract) { try { if (_securities == null) { _securities = new List <Security>(); } SecurityIb securityIb = _secIB.Find(security => security.Symbol == contract.Symbol && security.Exchange == contract.Exchange); if (securityIb == null) { securityIb = _secIB.Find(security => security.LocalSymbol == contract.LocalSymbol && security.Exchange == contract.Exchange); } if (securityIb == null) { return; } securityIb.Exchange = contract.Exchange; securityIb.Expiry = contract.Expiry; securityIb.LocalSymbol = contract.LocalSymbol; securityIb.Multiplier = contract.Multiplier; securityIb.Right = contract.Right; securityIb.ConId = contract.ConId; securityIb.Currency = contract.Currency; securityIb.Strike = contract.Strike; securityIb.MinTick = contract.MinTick; securityIb.Symbol = contract.Symbol; securityIb.TradingClass = contract.TradingClass; securityIb.SecType = contract.SecType; securityIb.PrimaryExch = contract.PrimaryExch; //_twsServer.reqMktData(securityIb.ConId, securityIb.Symbol, securityIb.SecType, securityIb.Expiry, securityIb.Strike, // securityIb.Right, securityIb.Multiplier, securityIb.Exchange, securityIb.PrimaryExch, securityIb.Currency,"",true, new TagValueList()); //_twsServer.reqMktData2(securityIb.ConId, securityIb.LocalSymbol, securityIb.SecType, securityIb.Exchange, securityIb.PrimaryExch, securityIb.Currency, "", false, new TagValueList()); string name = securityIb.Symbol + "_" + securityIb.SecType + "_" + securityIb.Exchange; if (_securities.Find(securiti => securiti.Name == name) == null) { Security security = new Security(); security.Name = name; security.NameFull = name; security.NameClass = securityIb.SecType; if (string.IsNullOrWhiteSpace(security.NameClass)) { security.NameClass = "Unknown"; } security.PriceStep = Convert.ToDecimal(securityIb.MinTick); security.PriceStepCost = Convert.ToDecimal(securityIb.MinTick); security.Lot = 1; security.PriceLimitLow = 0; security.PriceLimitHigh = 0; security.NameId = name; security.SecurityType = SecurityType.Stock; _securities.Add(security); if (SecurityEvent != null) { SecurityEvent(_securities); } } } catch (Exception error) { SendLogMessage(error.ToString(), LogMessageType.Error); } }
/// <summary> /// upload security for connection /// загрузить бумаги для подключения /// </summary> private void LoadIbSecurities() { if (!File.Exists(@"Engine\" + @"IbSecuritiesToWatch.txt")) { return; } try { using (StreamReader reader = new StreamReader(@"Engine\" + @"IbSecuritiesToWatch.txt")) { _secIB = new List <SecurityIb>(); while (!reader.EndOfStream) { try { SecurityIb security = new SecurityIb(); string[] contrStrings = reader.ReadLine().Split('@'); security.ComboLegsDescription = contrStrings[0]; Int32.TryParse(contrStrings[1], out security.ConId); security.Currency = contrStrings[2]; security.Exchange = contrStrings[3]; security.Expiry = contrStrings[4]; Boolean.TryParse(contrStrings[5], out security.IncludeExpired); security.LocalSymbol = contrStrings[6]; security.Multiplier = contrStrings[7]; security.PrimaryExch = contrStrings[8]; security.Right = contrStrings[9]; security.SecId = contrStrings[10]; security.SecIdType = contrStrings[11]; security.SecType = contrStrings[12]; Double.TryParse(contrStrings[13], out security.Strike); security.Symbol = contrStrings[14]; security.TradingClass = contrStrings[15]; if (contrStrings.Length > 15 && string.IsNullOrEmpty(contrStrings[16]) == false) { security.CreateMarketDepthFromTrades = Convert.ToBoolean(contrStrings[16]); } _secIB.Add(security); } catch { // ignore } } if (_secIB.Count == 0) { SecurityIb sec1 = new SecurityIb(); sec1.Symbol = "AAPL"; sec1.Exchange = "SMART"; sec1.SecType = "STK"; _secIB.Add(sec1); SecurityIb sec2 = new SecurityIb(); sec2.Symbol = "FB"; sec2.Exchange = "SMART"; sec2.SecType = "STK"; _secIB.Add(sec2); SecurityIb sec3 = new SecurityIb(); sec3.Symbol = "EUR"; sec3.Exchange = "IDEALPRO"; sec3.SecType = "CASH"; _secIB.Add(sec3); SecurityIb sec4 = new SecurityIb(); sec4.Symbol = "GBP"; sec4.Exchange = "IDEALPRO"; sec4.SecType = "CASH"; _secIB.Add(sec4); } } } catch (Exception) { // ignored } }
/// <summary> /// исполнить ордер на бирже /// </summary> public void ExecuteOrder(Order order, SecurityIb contract) { //_twsServer.placeOrderEx(_nextOrderNum - 1, contractIb, orderIb); if (_isConnected == false) { return; } if (_orders == null) { _orders = new List <Order>(); } try { if (_orders.Find(o => o.NumberUser == order.NumberUser) == null) { _orders.Add(order); } _nextOrderNum++; order.NumberMarket = _nextOrderNum.ToString(); TcpWrite(3); TcpWrite(43); TcpWrite(_nextOrderNum); TcpWrite(contract.ConId); TcpWrite(contract.Symbol); TcpWrite(contract.SecType); TcpWrite(contract.Expiry); TcpWrite(contract.Strike); TcpWrite(contract.Right); TcpWrite(contract.Multiplier); TcpWrite(contract.Exchange); TcpWrite(contract.PrimaryExch); TcpWrite(contract.Currency); TcpWrite(contract.LocalSymbol); TcpWrite(contract.TradingClass); TcpWrite(contract.SecIdType); TcpWrite(contract.SecId); string action = ""; if (order.Side == Side.Buy) { action = "BUY"; } else { action = "SELL"; } string type = ""; if (order.TypeOrder == OrderPriceType.Limit) { type = "LMT"; } else { type = "MKT"; } // paramsList.AddParameter main order fields TcpWrite(action); TcpWrite(order.Volume.ToString()); TcpWrite(type); TcpWrite(order.Price.ToString(new NumberFormatInfo() { CurrencyDecimalSeparator = "." })); TcpWrite(""); } catch (Exception error) { SendLogMessage(error.ToString(), LogMessageType.Error); } // paramsList.AddParameter extended order fields TcpWrite(null); // null TcpWrite(""); TcpWrite(order.PortfolioNumber); TcpWrite(""); TcpWrite(0); TcpWrite(null); TcpWrite(true); TcpWrite(0); TcpWrite(false); TcpWrite(false); TcpWrite(0); TcpWrite(0); TcpWrite(false); TcpWrite(false); TcpWrite(""); TcpWrite(0); TcpWrite(null); // order.GoodAfterTime TcpWrite(null); // order.GoodTillDate TcpWrite(null); // order.FaGroup TcpWrite(null); // order.FaMethod TcpWrite(null); // order.FaPercentage TcpWrite(null); // order.FaProfile TcpWrite(null); // order.ShortSaleSlot // 0 only for retail, 1 or 2 only for institution. TcpWrite(""); // order.DesignatedLocation// only populate when order.shortSaleSlot = 2. TcpWrite(-1); // order.ExemptCode TcpWrite(0); // order.OcaType TcpWrite(null); // order.Rule80A TcpWrite(null); // order.SettlingFirm TcpWrite(0); // order.AllOrNone TcpWrite(""); // order.MinQty TcpWrite(""); // order.PercentOffset TcpWrite(false); // order.ETradeOnly TcpWrite(false); // order.FirmQuoteOnly TcpWrite(""); //order.NbboPriceCap TcpWrite(0); // order.AuctionStrategy TcpWrite(""); // order.StartingPrice TcpWrite(""); // order.StockRefPrice TcpWrite(""); // order.Delta TcpWrite(""); TcpWrite(""); TcpWrite(false); // order.OverridePercentageConstraints // Volatility orders TcpWrite(""); // order.Volatility TcpWrite(""); // order.VolatilityType TcpWrite(""); // order.DeltaNeutralOrderType TcpWrite(""); // order.DeltaNeutralAuxPrice TcpWrite(0); // order.ContinuousUpdate TcpWrite(""); // order.ReferencePriceType TcpWrite(""); // order.TrailStopPrice TcpWrite(""); // order.TrailingPercent TcpWrite(""); // order.ScaleInitLevelSize TcpWrite(""); // order.ScaleSubsLevelSize TcpWrite(""); // order.ScalePriceIncrement TcpWrite(""); // order.ScaleTable TcpWrite(""); // order.ActiveStartTime TcpWrite(""); // order.ActiveStopTime TcpWrite(null); //order.HedgeType TcpWrite(false); // order.OptOutSmartRouting TcpWrite(null); // order.ClearingAccount TcpWrite(null); // order.ClearingIntent TcpWrite(false); // order.NotHeld TcpWrite(false); TcpWrite(null); // order.AlgoStrategy TcpWrite(null); // order.AlgoId TcpWrite(false); // order.WhatIf TcpWrite(""); // TagValueListToString(order.OrderMiscOptions) TcpSendMessage(); }
/// <summary> /// загрузить спецификацию по контракту /// </summary> private void LoadContractData() { int msgVersion = TcpReadInt(); int requestId = -1; if (msgVersion >= 3) { requestId = TcpReadInt(); } SecurityIb contract = new SecurityIb(); contract.Symbol = TcpReadString(); contract.SecType = TcpReadString(); contract.Expiry = TcpReadString(); contract.Strike = TcpReadDouble(); contract.Right = TcpReadString(); contract.Exchange = TcpReadString(); contract.Currency = TcpReadString(); contract.LocalSymbol = TcpReadString(); TcpReadString(); contract.TradingClass = TcpReadString(); contract.ConId = TcpReadInt(); contract.MinTick = TcpReadDouble(); contract.Multiplier = TcpReadString(); TcpReadString(); TcpReadString(); if (msgVersion >= 2) { TcpReadInt(); } if (msgVersion >= 4) { TcpReadInt(); } if (msgVersion >= 5) { TcpReadString(); TcpReadString(); } if (msgVersion >= 6) { TcpReadString(); TcpReadString(); TcpReadString(); TcpReadString(); TcpReadString(); TcpReadString(); TcpReadString(); } if (msgVersion >= 8) { TcpReadString(); TcpReadDouble(); } if (msgVersion >= 7) { int secIdListCount = TcpReadInt(); if (secIdListCount > 0) { for (int i = 0; i < secIdListCount; ++i) { TcpReadString(); TcpReadString(); } } } if (_serverSecurities == null) { _serverSecurities = new List <SecurityIb>(); } _serverSecurities.Add(contract); if (NewContractEvent != null) { NewContractEvent(contract); } }