Пример #1
0
        public async void Visit(KillOrderTransaction transaction)
        {
            try
            {
                var reply = await transClient.CancelOrder(new CancelOrder { order_id = transaction.OrderExchangeId });

                OnMessageReceived(TransactionReply.Accepted(transaction, reply.code));

                var oscm = new OrderStateChangeMessage
                {
                    TransactionId   = transaction.TransactionId,
                    OrderExchangeId = reply.code,
                    Quantity        = reply.qty,
                    ActiveQuantity  = reply.qtyLeft,
                    FilledQuantity  = reply.qty_executed,
                    ChangeTime      = DateTime.Now,
                    State           = OrderState.Cancelled
                };
                OnMessageReceived(oscm);
            }
            catch (FTEException e)
            {
                OnMessageReceived(TransactionReply.Rejected(transaction, e.Message));
            }
        }
Пример #2
0
        public void Accept(string clOrderId)
        {
            Guid transactionId;
            using (_transactionIdsLock.Lock())
            {
                if (!_clientOrderIdToTransactionIdMap.TryGetValue(clOrderId, out transactionId))
                {
                    return;
                }

                Forget(clOrderId);
            }

            _sendMessage(TransactionReply.Accepted(transactionId));
        }
Пример #3
0
        private void TrySendTransactionReplyAccepted(Guid transactionId)
        {
            using (transactionIdsByRequestIdLock.Lock())
            {
                uint requestId;
                if (transactionRequestIds.TryGetValue(transactionId, out requestId))
                {
                    transactionIdsByRequestId.Remove(requestId);
                }

                if (!transactionRequestIds.Remove(transactionId))
                {
                    return;
                }
            }

            OnMessageReceived(TransactionReply.Accepted(transactionId));
        }
Пример #4
0
        public async void Visit(NewOrderTransaction transaction)
        {
            try
            {
                //internal async Task<string> ResolveInstrumentAsync(Instrument instrument)
                //{
                //    var data = await instrumentConverter.ResolveInstrumentAsync(this, instrument);
                //    return data?.Symbol;
                //}

                var data = await connector.ResolveInstrumentDataAsync(transaction.Instrument);

                if (data == null)
                {
                    OnMessageReceived(TransactionReply.Rejected(transaction, $"Unable to get symbol of {transaction.Instrument}"));
                    return;
                }

                if (!accounts.TryGetValue(transaction.Account, out var account))
                {
                    OnMessageReceived(TransactionReply.Rejected(transaction, $"Не найден счет {transaction.Account}"));
                    return;
                }

                var order = new SpimexAdapter.FTE.Order
                {
                    account = account.code,
                    firm    = account.firm,
                    client  = account.client,

                    security = data.Symbol,
                    board    = data.Board,

                    @type    = transaction.GetOrderType(),
                    @params  = transaction.GetOrderParams(),
                    buy_sell = transaction.GetOperation(),

                    price         = PriceHelper.FromPrice(transaction.Price),
                    qty           = transaction.Quantity,
                    trn           = transaction.TransactionId.ToString("N"),
                    isMarketMaker = transaction.IsMarketMakerOrder,
                    comment       = transaction.Comment,
                };


                var reply = await transClient.SendOrder(order);

                OnMessageReceived(TransactionReply.Accepted(transaction, reply.code));

                OrderState?state = null;
                switch (reply.status)
                {
                case OrderStatus.CANCELED:
                    state = OrderState.Cancelled;
                    break;

                case OrderStatus.MATCHED:
                    state = OrderState.Filled;
                    break;

                case OrderStatus.FREEZED:
                case OrderStatus.QUEUED:
                    state = reply.qty_executed > 0 ? OrderState.PartiallyFilled : OrderState.Active;
                    break;
                }

                var oscm = new OrderStateChangeMessage
                {
                    TransactionId   = transaction.TransactionId,
                    OrderExchangeId = reply.code,
                    Quantity        = order.qty,
                    ActiveQuantity  = reply.qtyLeft,
                    FilledQuantity  = reply.qty_executed,
                    Price           = PriceHelper.ToPrice(order.price),
                    ChangeTime      = DateTime.Now,
                    State           = state
                };
                OnMessageReceived(oscm);
            }
            catch (FTEException e)
            {
                OnMessageReceived(TransactionReply.Rejected(transaction, e.Message));
            }
        }