Exemplo n.º 1
0
        private void BuyPartiallyFilled(Order order, BinanceCanceledOrder orderStatus)
        {
            var quantity         = orderStatus.OriginalQuantity;
            var executedQuantity = orderStatus.ExecutedQuantity;

            var amountToPlace = quantity - executedQuantity;

            var newOrder = new Order()
            {
                Amount     = amountToPlace,
                AmountUSDT = order.AmountUSDT,
                BAlfa      = order.BAlfa,
                BAlfaUSDT  = order.BAlfaUSDT,
                BBeta      = order.BBeta,
                SAlfa      = order.SAlfa,
                SAlfaUSDT  = order.SAlfaUSDT,
                SBeta      = order.SBeta,
                TickUp     = order.TickUp,
                Processing = false,
                Guid       = Guid.NewGuid().ToString(),
                Pair       = order.Pair,
                Status     = Status.WaitBuy,
                StartDate  = DateTime.Now,
            };

            Add(newOrder);
        }
Exemplo n.º 2
0
        private void SellPartiallyFilled(Order order, BinanceCanceledOrder orderStatus)
        {
            var buyOrder = CloneBinancePlaceOrder(order.BuyOrder);

            buyOrder.OriginalQuantity = orderStatus.ExecutedQuantity;
            buyOrder.ExecutedQuantity = orderStatus.ExecutedQuantity;

            var newOrder = new Order()
            {
                Amount     = orderStatus.ExecutedQuantity,
                BAlfa      = order.BAlfa,
                BBeta      = order.BBeta,
                SAlfa      = order.SBeta,
                SBeta      = order.SBeta,
                TickUp     = order.TickUp,
                Processing = false,
                Guid       = Guid.NewGuid().ToString(),
                BuyOrder   = buyOrder,
                BuyPrice   = order.BuyPrice,
                BuyOrderCompletedDatetime = DateTime.Now,
                Pair      = order.Pair,
                Status    = Status.WaitSell,
                StartDate = DateTime.Now
            };

            Add(newOrder);
        }
Exemplo n.º 3
0
        public void CancelOrder_Should_RespondWithCanceledOrder()
        {
            // arrange
            var canceled = new BinanceCanceledOrder()
            {
                ClientOrderId         = "test",
                OrderId               = 100000000000,
                Symbol                = "BNBBTC",
                OriginalClientOrderId = "test2"
            };

            var client = PrepareClient(JsonConvert.SerializeObject(canceled));

            // act
            var result = client.CancelOrder("BNBBTC");

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(canceled, result.Data));
        }
Exemplo n.º 4
0
        private void ManagePartiallyFilledSell(Order order, BinanceCanceledOrder orderStatus)
        {
            var quantity         = orderStatus.OriginalQuantity;
            var executedQuantity = orderStatus.ExecutedQuantity;

            var amountToPlace = quantity - executedQuantity;
            var buyOrder      = CloneBinancePlaceOrder(order.BuyOrder);

            buyOrder.ExecutedQuantity = amountToPlace;
            buyOrder.OriginalQuantity = amountToPlace;

            var newOrder = new Order()
            {
                Amount     = amountToPlace,
                AmountUSDT = order.AmountUSDT,
                BAlfa      = order.BAlfa,
                BAlfaUSDT  = order.BAlfaUSDT,
                BBeta      = order.BBeta,
                SAlfa      = order.SAlfa,
                SAlfaUSDT  = order.SAlfaUSDT,
                SBeta      = order.SBeta,
                Processing = false,
                TickUp     = order.TickUp,
                Guid       = Guid.NewGuid().ToString(),
                BuyOrder   = buyOrder,
                BuyPrice   = buyOrder.Price,
                BuyOrderCompletedDatetime = DateTime.Now,
                Pair      = order.Pair,
                Status    = Status.WaitSell,
                StartDate = order.StartDate
            };

            Add(newOrder);

            order.Amount = executedQuantity;
            order.BuyOrder.ExecutedQuantity  = executedQuantity;
            order.BuyOrder.OriginalQuantity  = executedQuantity;
            order.SellOrderCompletedDatetime = DateTime.Now;
            CompleteOrder(order);
        }
Exemplo n.º 5
0
        public static ExchangeOrder ToOrder(this BinanceCanceledOrder externalOrder)
        {
            if (externalOrder == null)
            {
                return(null);
            }

            ExchangeOrder order = new ExchangeOrder();

            order.Symbol           = externalOrder.Symbol;
            order.Status           = externalOrder.Status.ToStatus();
            order.OriginalQuantity = externalOrder.OriginalQuantity;
            order.OrderId          = long.Parse(externalOrder.ClientOrderId);
            order.ExchangeOrderId  = externalOrder.OrderId.ToString();
            order.OrderSideCode    = externalOrder.Side.ToCode();
            order.OrderTypeCode    = externalOrder.Type.ToCode();
            order.FillPoliticsCode = externalOrder.TimeInForce.ToCode();
            order.ExecutedQuantity = externalOrder.ExecutedQuantity;
            order.Price            = externalOrder.Price;

            return(order);
        }
Exemplo n.º 6
0
        public void CancelOrder_Should_RespondWithCanceledOrder()
        {
            // arrange
            var canceled = new BinanceCanceledOrder()
            {
                ClientOrderId         = "test",
                OrderId               = 100000000000,
                Symbol                = "BNBBTC",
                OriginalClientOrderId = "test2"
            };

            var objects = TestHelpers.PrepareClient(() => Construct(new BinanceClientOptions()
            {
                ApiCredentials = new ApiCredentials("Test", "Test")
            }), JsonConvert.SerializeObject(canceled));

            // act
            var result = objects.Client.CancelOrder("BNBBTC");

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(TestHelpers.PublicInstancePropertiesEqual(canceled, result.Data));
        }
Exemplo n.º 7
0
        public void CancelOrder_Should_RespondWithCanceledOrder()
        {
            // arrange
            var canceled = new BinanceCanceledOrder()
            {
                ClientOrderId         = "test",
                OrderId               = 100000000000,
                Symbol                = "BNBBTC",
                OriginalClientOrderId = "test2"
            };

            var client = TestHelpers.CreateResponseClient(canceled, new BinanceClientOptions()
            {
                ApiCredentials = new ApiCredentials("Test", "Test"),
                AutoTimestamp  = false
            });

            // act
            var result = client.CancelOrder("BNBBTC", orderId: 123);

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(TestHelpers.AreEqual(canceled, result.Data));
        }
Exemplo n.º 8
0
 private void ManagePartiallyFilledBuy(Order order, BinanceCanceledOrder orderStatus)
 {
     BuyPartiallyFilled(order, orderStatus);
     SellPartiallyFilled(order, orderStatus);
 }