Exemple #1
0
        private static void WaitForBuy(Deal deal)
        {
            var buyOrder = TradeInterface.GetOrderById(deal.Symbol, deal.BuyOrder.ClientOrderId);

            if (OrderWorked(buyOrder))
            {
                // Download actual order
                var actualOrders = TradeInterface.GetActualTrades(buyOrder.Symbol, buyOrder.OrderId);
                deal.BuyOrder.FilledOrders = actualOrders.Select(x => x.OrderId).ToList();

                decimal quantity = (actualOrders.Sum(x => x.Quantity) * FEEMODIFIER).Normalize();

                // Set leftovers
                deal.Leftovers = quantity;

                // Calculate Sell points
                decimal price = actualOrders.EffectivePrice();

                // We put 50 % sell on 1 % profit
                var order1 = TradeInterface.PlaceTakeProfitOrder(deal.Symbol, quantity: quantity * 0.5m, limit: price * (1 + deal.Sell1Perc), orderSide: OrderSide.Sell);

                // And we put another 50 % sell on 2 % profit
                var order2 = TradeInterface.PlaceTakeProfitOrder(deal.Symbol, quantity: quantity * 0.5m, limit: price * (1 + deal.Sell2Perc), orderSide: OrderSide.Sell);

                deal.Goal1SellOrder = new ClientServerOrder()
                {
                    ClientOrderId = order1.ClientOrderId
                };
                deal.Goal2SellOrder = new ClientServerOrder()
                {
                    ClientOrderId = order2.ClientOrderId
                };

                // Set next state
                deal.CurrentState = Deal.State.WaitForGoal1;
            }
            else if (OrderCancelled(buyOrder))
            {
                StateTransistion_Cancelled(deal);
            }
        }
Exemple #2
0
        private static void WaitForGoal2(Deal deal)
        {
            var sellOrder = TradeInterface.GetOrderById(deal.Symbol, deal.Goal2SellOrder.ClientOrderId);

            if (OrderWorked(sellOrder))
            {
                // Download actual order
                var actualOrders = TradeInterface.GetActualTrades(sellOrder.Symbol, sellOrder.OrderId);
                deal.Goal2SellOrder.FilledOrders = actualOrders.Select(x => x.OrderId).ToList();

                deal.Leftovers -= actualOrders.Select(x => x.Quantity).Sum();

                // Set next state
                deal.CurrentState  = Deal.State.Done;
                deal.CurrentResult = Deal.Result.GoalsArchived;
            }
            else if (OrderCancelled(sellOrder))
            {
                StateTransistion_Cancelled(deal);
            }
        }