private void OnClientResponse(ClientResponse response) { SendOutMessage(new PortfolioMessage { PortfolioName = response.Id, Currency = TransaqHelper.ToCurrency(response.Currency), }); if (response.MlIntraDay != null) { SendOutMessage( this .CreatePortfolioChangeMessage(response.Id) .Add(PositionChangeTypes.Leverage, response.MlIntraDay.Value)); } //if (MicexRegisters) // SendCommand(new RequestPortfolioTPlusMessage {Client = response.Id}); }
private void OnClientResponse(ClientResponse response) { if (response.Remove) { return; } SendOutMessage(new PortfolioMessage { PortfolioName = response.Id, Currency = TransaqHelper.ToCurrency(response.Currency), }); if (!response.Union.IsEmpty()) { SendOutMessage(new PortfolioMessage { PortfolioName = response.Union }); } if (!response.FortsAcc.IsEmpty()) { SendOutMessage(new PortfolioMessage { PortfolioName = response.FortsAcc }); } //if (response.MlIntraDay != null) //{ // SendOutMessage( // this // .CreatePortfolioChangeMessage(response.Id) // .Add(PositionChangeTypes.Leverage, response.MlIntraDay.Value)); //} //if (MicexRegisters) // SendCommand(new RequestPortfolioTPlusMessage {Client = response.Id}); }
private void ProcessRegisterMessage(OrderRegisterMessage regMsg) { DateTime?expDate; if (regMsg.TillDate == null || regMsg.TillDate == DateTimeOffset.MaxValue) { expDate = null; } else { expDate = regMsg.TillDate.Value.ToLocalTime(TimeHelper.Moscow); } BaseCommandMessage command; switch (regMsg.OrderType) { case OrderTypes.Limit: case OrderTypes.Market: { command = new NewOrderMessage { ByMarket = regMsg.OrderType == OrderTypes.Market, Client = regMsg.PortfolioName, Quantity = regMsg.Volume.To <int>(), Unfilled = regMsg.TimeInForce.ToTransaq(), BuySell = regMsg.Side.ToTransaq(), Price = regMsg.Price, SecId = (int)regMsg.SecurityId.Native, ExpDate = expDate, BrokerRef = regMsg.Comment, Hidden = (int)(regMsg.Volume - (regMsg.VisibleVolume ?? regMsg.Volume)), }; break; } case OrderTypes.Conditional: { var cond = (TransaqOrderCondition)regMsg.Condition; if (cond.Type == TransaqOrderConditionTypes.Algo) { command = new NewCondOrderMessage { ByMarket = regMsg.OrderType == OrderTypes.Market, Client = regMsg.PortfolioName, Quantity = regMsg.Volume.To <int>(), BuySell = regMsg.Side.ToTransaq(), Price = regMsg.Price, SecId = (int)regMsg.SecurityId.Native, CondType = cond.AlgoType ?? TransaqAlgoOrderConditionTypes.None, CondValue = cond.AlgoValue ?? 0m, ValidAfterType = cond.AlgoValidAfterType ?? TransaqAlgoOrderValidTypes.TillCancelled, ValidAfter = cond.AlgoValidAfter, ValidBeforeType = cond.AlgoValidBeforeType ?? TransaqAlgoOrderValidTypes.TillCancelled, ValidBefore = cond.AlgoValidBefore, ExpDate = expDate, BrokerRef = regMsg.Comment, Hidden = (int)(regMsg.Volume - (regMsg.VisibleVolume ?? regMsg.Volume)), }; } else // if (regMsg.Condition is TransaqOrderCondition) { if (!cond.CheckConditionUnitType()) { throw new InvalidOperationException(LocalizedStrings.Str3549); } var stopOrder = new NewStopOrderMessage { SecId = (int)regMsg.SecurityId.Native, Client = regMsg.PortfolioName, BuySell = regMsg.Side.ToTransaq(), LinkedOrderNo = cond.LinkedOrderId.To <string>(), ExpDate = expDate, ValidFor = expDate, }; switch (cond.Type) { case TransaqOrderConditionTypes.StopLoss: stopOrder.StopLoss = TransaqHelper.CreateStopLoss(cond); break; case TransaqOrderConditionTypes.TakeProfit: stopOrder.TakeProfit = TransaqHelper.CreateTakeProfit(cond); break; case TransaqOrderConditionTypes.TakeProfitStopLoss: stopOrder.StopLoss = TransaqHelper.CreateStopLoss(cond); stopOrder.TakeProfit = TransaqHelper.CreateTakeProfit(cond); break; } command = stopOrder; } //else // throw new InvalidOperationException(LocalizedStrings.Str3550Params.Put(regMsg.Condition, regMsg.TransactionId)); break; } case OrderTypes.Repo: { command = new NewRepoOrderMessage { SecId = (int)regMsg.SecurityId.Native, Client = regMsg.PortfolioName, BuySell = regMsg.Side.ToTransaq(), CpFirmId = regMsg.RepoInfo.Partner, MatchRef = regMsg.RepoInfo.MatchRef, BrokerRef = regMsg.Comment, Price = regMsg.Price, Quantity = regMsg.Volume.To <int>(), SettleCode = regMsg.RepoInfo.SettleCode, RefundRate = regMsg.RepoInfo.RefundRate, Rate = regMsg.RepoInfo.Rate, }; break; } case OrderTypes.ExtRepo: { command = new NewMRepoOrderMessage { SecId = (int)regMsg.SecurityId.Native, Client = regMsg.PortfolioName, BuySell = regMsg.Side.ToTransaq(), CpFirmId = regMsg.RepoInfo.Partner, MatchRef = regMsg.RepoInfo.MatchRef, BrokerRef = regMsg.Comment, Price = regMsg.Price, Quantity = regMsg.Volume.To <int>(), SettleCode = regMsg.RepoInfo.SettleCode, RefundRate = regMsg.RepoInfo.RefundRate, Value = regMsg.RepoInfo.Value, Term = regMsg.RepoInfo.Term, Rate = regMsg.RepoInfo.Rate, StartDiscount = regMsg.RepoInfo.StartDiscount, LowerDiscount = regMsg.RepoInfo.LowerDiscount, UpperDiscount = regMsg.RepoInfo.UpperDiscount, BlockSecurities = regMsg.RepoInfo.BlockSecurities, }; break; } case OrderTypes.Rps: { command = new NewRpsOrderMessage { SecId = (int)regMsg.SecurityId.Native, Client = regMsg.PortfolioName, BuySell = regMsg.Side.ToTransaq(), CpFirmId = regMsg.RpsInfo.Partner, MatchRef = regMsg.RpsInfo.MatchRef, BrokerRef = regMsg.Comment, Price = regMsg.Price, Quantity = regMsg.Volume.To <int>(), SettleCode = regMsg.RpsInfo.SettleCode, }; break; } case OrderTypes.Execute: { //command = new NewReportMessage //{ // BuySell = regMsg.Side.ToTransaq(), //}; //break; throw new NotImplementedException(); } default: throw new ArgumentOutOfRangeException(); } var result = SendCommand(command); _orders.Add(result.TransactionId, regMsg.TransactionId); _ordersTypes.Add(regMsg.TransactionId, command is NewCondOrderMessage ? OrderTypes.Limit : regMsg.OrderType); }