private void ReadOrderStatus(IBSocket socket, ServerVersions version) { var id = socket.ReadInt(); var status = socket.ReadOrderStatus(); /* filled */ socket.ReadInt(); var balance = socket.ReadDecimal(); var avgPrice = socket.ReadDecimal(); var permId = version >= ServerVersions.V2 ? socket.ReadInt() : (int?)null; var parentId = version >= ServerVersions.V3 ? socket.ReadInt() : (int?)null; var lastTradePrice = version >= ServerVersions.V4 ? socket.ReadDecimal() : (decimal?)null; var clientId = version >= ServerVersions.V5 ? socket.ReadInt() : (int?)null; var whyHeld = version >= ServerVersions.V6 ? socket.ReadStr() : null; var execMsg = new ExecutionMessage { ExecutionType = ExecutionTypes.Transaction, OriginalTransactionId = id, Balance = balance, OrderStatus = status, OrderState = status.ToOrderState(), HasOrderInfo = true, }; execMsg.SetAveragePrice(avgPrice); if (permId != null) execMsg.SetPermId(permId.Value); if (parentId != null) execMsg.Condition = new IBOrderCondition { ParentId = parentId.Value }; if (lastTradePrice != null) execMsg.SetLastTradePrice(lastTradePrice.Value); if (clientId != null) execMsg.SetClientId(clientId.Value); if (whyHeld != null) execMsg.SetWhyHeld(whyHeld); SendOutMessage(execMsg); }
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); }