public Task Handle(CancelOrder message, IMessageHandlerContext context)
        {
            Log.Info($"Cancelling Order with Id {message.OrderId}");

            MarkAsComplete();
            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        private void CancelOrder(Order order)
        {
            CancelOrder cancel = robotTrade.CancelOrder(Symbol, order.order_id);

            if (cancel.result)
            {
                robotSession.RemoveSessionOrder(order);
                //DbHelper.DBSaveChange(doubleorder, "UpDate");
                Log4NetUtility.Info("RobotHFT", "Canceled Order Success. id:" + Utils.ShortID(order.order_id) + " Price:" + order.price);
            }
            else
            {
                string errmsg = cancel.error_code + "  " + cancel.msg;
                if (cancel.error_code.Contains("3008"))
                {
                    robotSession.RemoveSessionOrder(order);
                    //sessionOrders.Remove(doubleorder);
                    ////DbHelper.CreateInstance().RemoveOrder(doubleorder);
                    errmsg = "已清除脏数据Order。id:" + Utils.ShortID(order.order_id) + " Price:" + order.price;
                }
                else
                {
                    //errmsg = "撤销重复Order失败。id:" + Utils.ShortID(doubleorder.order_id) + " msg:" + cancel.error_code + cancel.msg;
                }
                Log4NetUtility.Info("CancelOrder", errmsg);
                //DbHelper.CreateInstance().AddErrInfo("缓存单验证", errmsg);
            }
        }
Exemplo n.º 3
0
    public Task Handle(CancelOrder message, IMessageHandlerContext context)
    {
        log.Info($"Saga with OrderId {message.OrderId} cancelled");
        MarkAsComplete();

        return(Task.CompletedTask);
    }
        public IHttpActionResult CancelOrder([FromBody] GuidModel model)
        {
            var cmd   = new CancelOrder(model.OrderId);
            var order = _commandDispatcher.ExecuteCommand <OrderAggregate>(cmd);

            return(Ok(OrderModel.FromAggregate(order)));
        }
Exemplo n.º 5
0
        internal void OnCancelOrderCommand_WhenNoOrderExists_DoesNotSendCommand()
        {
            // Arrange
            var order     = new StubOrderBuilder().EntryOrder("O-123456").BuildMarketOrder();
            var traderId  = TraderId.FromString("TESTER-000");
            var accountId = AccountId.FromString("NAUTILUS-000-SIMULATED");

            var command = new CancelOrder(
                traderId,
                accountId,
                order.Id,
                Guid.NewGuid(),
                StubZonedDateTime.UnixEpoch());

            // Act
            this.engine.Endpoint.SendAsync(command).Wait();
            Task.Delay(100).Wait();  // Buffer to avoid intermittent tests

            // Assert
            Assert.Null(this.engine.UnhandledMessages.FirstOrDefault());
            Assert.Equal(2, this.engine.ProcessedCount);
            Assert.Equal(1, this.engine.CommandCount);
            Assert.Empty(this.tradingGateway.CalledMethods);
            Assert.Empty(this.tradingGateway.ReceivedObjects);
        }
Exemplo n.º 6
0
        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            CancelOrder cancelOrderGUI = new CancelOrder();

            cancelOrderGUI.Show();
            this.Hide();
        }
Exemplo n.º 7
0
 public Task <Unit> Handle(CancelOrder command, CancellationToken cancellationToken)
 {
     return(orderRepository.GetAndUpdate(
                command.OrderId,
                order => order.Cancel(command.CancellationReason),
                cancellationToken));
 }
Exemplo n.º 8
0
        public async Task <CancelOrderResponse> CancelOrder(CancelOrder cancelOrder)
        {
            string json = string.Empty;

            var client = new CexHttpClient();

            try
            {
                json = JsonConvert.SerializeObject(cancelOrder);
            }
            catch (JsonException ex)
            {
                throw new JsonException(CexConstants.InvalidJsonException, ex);
            }

            using (HttpContent content = new StringContent(json))
            {
                try
                {
                    var responseObject = await client.CexPostAsync(CexConstants.CancelOrderUrl, content);

                    return(new CancelOrderResponse()
                    {
                        StatusCode = responseObject.Item1
                    });
                }
                catch (HttpRequestException ex)
                {
                    throw new HttpRequestException(CexConstants.HttpPostRequestException, ex);
                }
            }
        }
Exemplo n.º 9
0
        private void CreateGtdCancelBackup(Order order)
        {
            if (!order.ExpireTime.HasValue)
            {
                // This should "never happen"
                this.Logger.LogError(
                    LogId.Trading,
                    $"Cannot schedule backup CancelOrder (no expire time set for GTD order {order.Id}).");

                return;
            }

            var traderId = this.database.GetTraderId(order.Id);

            if (traderId is null)
            {
                // This should never happen
                this.Logger.LogError(
                    LogId.Database,
                    $"Cannot schedule backup CancelOrder command (cannot find TraderId for {order.Id}).");
                return;
            }

            var accountId = this.database.GetAccountId(order.Id);

            if (accountId is null)
            {
                // This should "never happen"
                this.Logger.LogError(
                    LogId.Database,
                    $"Cannot schedule backup CancelOrder command (cannot find AccountId for {order.Id}).");
                return;
            }

            var cancelOrder = new CancelOrder(
                traderId,
                accountId,
                order.Id,
                this.NewGuid(),
                order.ExpireTime.Value);

            var jobKey  = new JobKey($"{nameof(CancelOrder)}-{order.Id.Value}", "OMS");
            var trigger = TriggerBuilder
                          .Create()
                          .WithIdentity(jobKey.Name, jobKey.Group)
                          .StartAt(order.ExpireTime.Value.ToDateTimeUtc())
                          .Build();

            var createJob = new CreateJob(
                this.Endpoint,
                cancelOrder,
                jobKey,
                trigger,
                this.NewGuid(),
                this.TimeNow());

            this.cancelJobs.Add(order.Id, jobKey);

            this.Send(createJob, ComponentAddress.Scheduler);
        }
Exemplo n.º 10
0
        public IAggregate Handle(CancelOrder command)
        {
            var order = _domainRepository.GetById <Order>(command.Id);

            order.Cancel();
            return(order);
        }
        public void Handle(CancelOrder command)
        {
            var order = _repository.Find(command.OrderId);

            order.Cancel();
            _repository.Save(order, command.Id.ToString());
        }
Exemplo n.º 12
0
        public void Update(OrderDetail dbEntity, OrderDetail entity)
        {
            try
            {
                string action = "SendToShip";

                if (action == "Complete")
                {
                    OrderDetail orderDetail = _Context.OrderDetails.Where(s => s.UniqueID == dbEntity.UniqueID).FirstOrDefault();
                    if (orderDetail != null)
                    {
                        orderDetail.Status = "Complete";
                        _Context.SaveChanges();

                        CompletedOrder completed = new CompletedOrder();
                        completed.UniqueID           = orderDetail.UniqueID;
                        completed.DateOfCompliletion = DateTime.Now;
                        _Context.CompletedOrders.Add(completed);
                        _Context.SaveChanges();
                    }
                }
                else if (action == "Cancel")
                {
                    OrderDetail orderDetail = _Context.OrderDetails.Where(s => s.UniqueID == entity.UniqueID).FirstOrDefault();
                    if (orderDetail != null)
                    {
                        orderDetail.Status = "Cancel";
                        _Context.SaveChanges();


                        CancelOrder cancelOrder = new CancelOrder();
                        cancelOrder.UniqueID           = orderDetail.UniqueID;
                        cancelOrder.DateOfCompliletion = DateTime.Now;
                        _Context.CancelOrders.Add(cancelOrder);
                        _Context.SaveChanges();
                    }
                }
                else if (action == "SendToShip")
                {
                    OrderDetail orderDetail = _Context.OrderDetails.Where(s => s.UniqueID == dbEntity.UniqueID).FirstOrDefault();
                    if (orderDetail != null)
                    {
                        orderDetail.Status = "Send To Ship";
                        _Context.SaveChanges();


                        Shippment ship = new Shippment();
                        ship.Status             = "Pending";
                        ship.UniqueID           = orderDetail.UniqueID;
                        ship.DateOfCompliletion = DateTime.Now;
                        _Context.Shippments.Add(ship);
                        _Context.SaveChanges();
                    }
                }
            }
            catch
            {
            }
        }
 public IActionResult PostCancelOrder([FromBody] CancelOrder cancelOrder)
 {
     if (cancelOrder == null)
     {
         return(BadRequest("Cancel Order is null !!!"));
     }
     _dataRepository.Add(cancelOrder);
     return(CreatedAtRoute("GetCancelOrder", new { Id = cancelOrder.CancelOrderID }, cancelOrder));
 }
Exemplo n.º 14
0
 private CancelOrderMessage CreateCancelOrderMessage(CancelOrder cancelOrder)
 {
     return(new CancelOrderMessage
     {
         RefId = cancelOrder.RefId,
         Symbol = cancelOrder.Symbol,
         Sender = Wallet.Address
     });
 }
    public void Handle(CancelOrder command)
    {
        this.logger.Log("Cancelling order " + command.OrderId);
        var order = this.repository.GetById(command.OrderId);

        order.Status = OrderStatus.Cancelled;
        this.repository.Save(order);
        this.publisher.Publish(new OrderCancelled(command.OrderId));
    }
Exemplo n.º 16
0
 public void Handle(CancelOrder message)
 {
     this.Bus.Publish <OrderCancelled>(x =>
     {
         x.OrderId = this.Data.OrderId;
     });
     this.MarkAsComplete();
     Console.WriteLine("Order Cancelled: " + message.OrderId);
 }
Exemplo n.º 17
0
        public CancelOrderMessage(CancelOrder cancelOrder, Wallet wallet, TransactionOption options)
        {
            this.wallet  = wallet;
            this.options = options;

            this.message        = new CancelOrderProto();
            this.message.Symbol = cancelOrder.Symbol;
            this.message.RefId  = cancelOrder.RefId;
        }
Exemplo n.º 18
0
        public Task Handle(CancelOrder message, IMessageHandlerContext context)
        {
            log.Info($"Order #{message.OrderId} was cancelled.");

            //TODO: Possibly publish an OrderCancelled event?

            MarkAsComplete(); // Since the saga is complete now, all further messages will be ignored, thus nothing will happen once timeout is resolved.

            return(Task.CompletedTask);
        }
        public IActionResult GetCancelOrderById(long cancelOrderId)
        {
            CancelOrder cancelOrder = _dataRepository.Get(cancelOrderId);

            if (cancelOrder == null)
            {
                return(NotFound("Cancel Order record not found !!!"));
            }
            return(Ok(cancelOrder));
        }
Exemplo n.º 20
0
        public string BuildCancelOrder(CancelOrder cancelOrder)
        {
            Wallet.EnsureWalletIsReady();
            CancelOrderMessage msgBean = CreateCancelOrderMessage(cancelOrder);

            byte[] msg       = EncodeCancelOrderMessage(msgBean);
            byte[] signature = EncodeSignature(Sign(msgBean));
            byte[] stdTx     = EncodeStdTx(msg, signature);
            return(EncodeUtils.ByteArrayToHex(stdTx));
        }
Exemplo n.º 21
0
        public async Task <ActionResult> cancelOrder(CancelOrder model)
        {
            bool status = await _Order.cancelOrder(model);

            if (status == true)
            {
                return(Ok(status));
            }
            return(BadRequest(status));
        }
Exemplo n.º 22
0
        public void Should_Command_Without_Result()
        {
            var handler = new OrderHandler();
            var change  = new CancelOrder {
                OrderId = 1
            };

            handler.Command(change);
            Assert.AreEqual(1, change.OrderId);
        }
        public Task Handle(CancelOrder message, IMessageHandlerContext context)
        {
            log.Info($"Order #{message.OrderId} was cancelled.");

            //TODO: Possibly publish an OrderCancelled event?

            MarkAsComplete();

            return(Task.CompletedTask);
        }
        public void When_CancelOrderWhenDelivered_ThrowsInvalidOrderStateException()
        {
            Given(InitialEvents);

            var command = new CancelOrder(id);

            command.Metadata.CausationId   = command.Metadata.CommandId;
            command.Metadata.CorrelationId = causationAndCorrelationId;

            WhenThrows <CancelOrder, InvalidOrderStateException>(command);
        }
        public void When_CancelOrderWhenShipped_CancelOrderFailed()
        {
            Given(InitialEvents.Take(3).ToArray());

            var command = new CancelOrder(id);

            command.Metadata.CausationId   = command.Metadata.CommandId;
            command.Metadata.CorrelationId = causationAndCorrelationId;

            WhenThrows <CancelOrder, InvalidOrderStateException>(command);
        }
        public IActionResult DeleteBrand(long cancelOrderId)
        {
            CancelOrder cancelOrder = _dataRepository.Get(cancelOrderId);

            if (cancelOrder == null)
            {
                return(NotFound("Cancel Order record not found !!!"));
            }
            _dataRepository.Delete(cancelOrder);
            return(GetCancelOrder());
        }
        public Task Handle(CancelOrder message, IMessageHandlerContext context)
        {
            MarkAsComplete();

            var orderCancelled = new OrderCanceled
            {
                OrderId = Data.OrderId
            };

            return(context.Publish(orderCancelled));
        }
        public Task Handle(CancelOrder message, IMessageHandlerContext context)
        {
            log.Info($"Received the CancelOrder command for {message.OrderId}. Cancelling the order.");
            MarkAsComplete();
            var orderCancelled = new OrderCancelled
            {
                OrderId = message.OrderId
            };

            return(context.Publish(orderCancelled));
        }
        public void CancelOrder(int orderNumber)
        {
            var command = new CancelOrder
            {
                ClientId = Context.ConnectionId,
                OrderNumber = orderNumber
            };

            MvcApplication.Bus.SetMessageHeader(command, "Debug", ((bool)Clients.Caller.debug).ToString());

            MvcApplication.Bus.Send(command);
        }
Exemplo n.º 30
0
        public OrderReply CancelOrder(Stock stock, int id)
        {
            CancelOrder request = new CancelOrder(Name, stock, id);
            bool        success = request.Execute();
            OrderReply  reply   = (request.Reply as OrderReply) ?? new OrderReply(false);

            if (success)
            {
                UpdateOrder(reply);
            }
            return(reply);
        }
Exemplo n.º 31
0
        public void CancelOrder(int orderNumber)
        {
            var command = new CancelOrder
            {
                ClientId    = Context.ConnectionId,
                OrderNumber = orderNumber
            };

            MvcApplication.Bus.SetMessageHeader(command, "Debug", ((bool)Clients.Caller.debug).ToString());

            MvcApplication.Bus.Send(command);
        }
Exemplo n.º 32
0
    public void CancelOrder(int orderNumber)
    {
        CancelOrder command = new CancelOrder
        {
            ClientId = Context.ConnectionId,
            OrderNumber = orderNumber
        };

        bool isDebug = (bool)Clients.Caller.debug;
        SendOptions sendOptions = new SendOptions();
        sendOptions.SetHeader("Debug", isDebug.ToString());
        MvcApplication.Endpoint.Send(command,sendOptions);
    }