private void ReadMyTrade(IBSocket socket, ServerVersions version) { /* requestId */ if (version >= ServerVersions.V7) socket.ReadInt(); // http://www.interactivebrokers.com/en/software/api/apiguide/java/execution.htm var transactionId = socket.ReadInt(); //Handle the 2^31-1 == 0 bug if (transactionId == int.MaxValue) transactionId = 0; //Read Contract Fields var contractId = version >= ServerVersions.V5 ? socket.ReadInt() : -1; var secName = socket.ReadStr(); var type = socket.ReadSecurityType(); var expiryDate = socket.ReadExpiry(); var strike = socket.ReadDecimal(); var optionType = socket.ReadOptionType(); var multiplier = version >= ServerVersions.V9 ? socket.ReadMultiplier() : null; var boardCode = socket.ReadBoardCode(); var currency = socket.ReadCurrency(); var secCode = socket.ReadLocalCode(secName); var secClass = (version >= ServerVersions.V10) ? socket.ReadStr() : null; var tradeId = socket.ReadStr(); var time = socket.ReadDateTime("yyyyMMdd HH:mm:ss"); var portfolio = socket.ReadStr(); /* exchange */ socket.ReadStr(); var side = socket.ReadTradeSide(); var volume = socket.ReadDecimal(); var price = socket.ReadDecimal(); var permId = version >= ServerVersions.V2 ? socket.ReadInt() : (int?)null; var clientId = version >= ServerVersions.V3 ? socket.ReadInt() : (int?)null; var liquidation = version >= ServerVersions.V4 ? socket.ReadInt() : (int?)null; var cumulativeQuantity = version >= ServerVersions.V6 ? socket.ReadInt() : (int?)null; var averagePrice = version >= ServerVersions.V6 ? socket.ReadDecimal() : (decimal?)null; var orderRef = version >= ServerVersions.V8 ? socket.ReadStr() : null; var evRule = version >= ServerVersions.V9 ? socket.ReadStr() : null; var evMultiplier = version >= ServerVersions.V9 ? socket.ReadDecimal() : (decimal?)null; var secId = new SecurityId { SecurityCode = secCode, BoardCode = GetBoardCode(boardCode), InteractiveBrokers = contractId, }; SendOutMessage(new SecurityMessage { SecurityId = secId, Name = secName, SecurityType = type, ExpiryDate = expiryDate, Strike = strike, OptionType = optionType, Currency = currency, Multiplier = multiplier ?? 0, Class = secClass }); // заявка была создана руками if (transactionId == 0) return; _secIdByTradeIds[tradeId] = secId; var execMsg = new ExecutionMessage { ExecutionType = ExecutionTypes.Transaction, OriginalTransactionId = transactionId, TradeStringId = tradeId, OriginSide = side, TradePrice = price, TradeVolume = volume, PortfolioName = portfolio, ServerTime = time, SecurityId = secId, HasTradeInfo = true, }; if (permId != null) execMsg.SetPermId(permId.Value); if (clientId != null) execMsg.SetClientId(clientId.Value); if (liquidation != null) execMsg.SetLiquidation(liquidation.Value); if (cumulativeQuantity != null) execMsg.SetCumulativeQuantity(cumulativeQuantity.Value); if (averagePrice != null) execMsg.SetAveragePrice(averagePrice.Value); if (orderRef != null) execMsg.SetOrderRef(orderRef); if (evRule != null) execMsg.SetEvRule(evRule); if (evMultiplier != null) execMsg.SetEvMultiplier(evMultiplier.Value); SendOutMessage(execMsg); }