예제 #1
0
 private async Task ElicitConditions()
 {
     var implementConditions = Task.Run(async() => {
         if (!build.StopLoss && !build.TakeProfit)
         {
             // Buy Only --------------------------------------------------------------------- Done
             trade.DisplayType = "BOVC";
             TradeDB tradeDB   = new TradeDB();
             await tradeDB.UpdateAsync(trade);
         }
         else if (!build.StopLoss && build.TakeProfit && !build.TrailingTakeProfit)
         {
             // Take Profit
             // --------------------------------------------------------------------- Done
             Sell sell = new Sell(build, api);
             trade     = await sell.LimitAsync(trade, build.TakeProfitPrice);
             if (trade.Success)
             {
                 trade.DisplayType = "TPVC";
                 TradeDB tradeDB   = new TradeDB();
                 await tradeDB.UpdateAsync(trade);
                 Scan scan          = new Scan(build);
                 TradeResult result = await scan.ConclusionTakeProfitAsync(trade);
                 trade.Status       = false;
                 await tradeDB.UpdateAsync(trade);
                 if (result.Success)
                 {
                     TradeResultDB resultDB = new TradeResultDB();
                     resultDB.Add(result);
                 }
             }
         }
         else if (!build.StopLoss && build.TakeProfit && build.TrailingTakeProfit)
         {
             // Take Profit
             // Trailing Take Profit
             // --------------------------------------------------------------------- Done
             int priceDecimal            = BitConverter.GetBytes(decimal.GetBits(trade.TakeProfitPrice)[3])[2];
             decimal tempTakeProfitPrice = decimal.Round(build.TakeProfitPrice * 2, priceDecimal);
             Sell sell = new Sell(build, api);
             trade     = await sell.LimitAsync(trade, tempTakeProfitPrice);
             if (trade.Success)
             {
                 trade.TakeProfitPrice = build.TakeProfitPrice;
                 trade.DisplayType     = "TPVC";
                 TradeDB tradeDB       = new TradeDB();
                 await tradeDB.UpdateAsync(trade);
                 Scan scan          = new Scan(build, api);
                 TradeResult result = scan.TrailingTakeProfit(trade);
                 trade.Status       = false;
                 await tradeDB.UpdateAsync(trade);
                 if (result.Success)
                 {
                     TradeResultDB resultDB = new TradeResultDB();
                     resultDB.Add(result);
                 }
             }
         }
         else if (build.StopLoss && !build.TrailingStopLoss && !build.TakeProfit)
         {
             // Stop Loss
             // --------------------------------------------------------------------- Done
             Sell sell = new Sell(build, api);
             trade     = await sell.LimitStopAsync(trade, build.StopLossPrice);
             if (trade.Success)
             {
                 trade.DisplayType = "SLVC";
                 TradeDB tradeDB   = new TradeDB();
                 await tradeDB.UpdateAsync(trade);
                 Scan scan          = new Scan(build, api);
                 TradeResult result = await scan.ConclusionStopLossAsync(trade);
                 trade.Status       = false;
                 await tradeDB.UpdateAsync(trade);
                 if (result.Success)
                 {
                     TradeResultDB resultDB = new TradeResultDB();
                     resultDB.Add(result);
                 }
             }
         }
         else if (build.StopLoss && build.TrailingStopLoss && !build.TakeProfit)
         {
             // Stop Loss
             // Trailing Stop Loss
             // --------------------------------------------------------------------------------------- Done
             Sell sell = new Sell(build, api);
             trade     = await sell.LimitStopAsync(trade, trade.StopLossPrice);
             if (trade.Success)
             {
                 trade.DisplayType = "TSLVC";
                 TradeDB tradeDB   = new TradeDB();
                 await tradeDB.UpdateAsync(trade);
                 var trailingStop = Task.Run(async() =>
                 {
                     Scan scan          = new Scan(build, api);
                     TradeResult result = scan.TrailingStopLoss(trade);
                     trade.Status       = false;
                     await tradeDB.UpdateAsync(trade);
                     if (result.Success)
                     {
                         TradeResultDB resultDB = new TradeResultDB();
                         resultDB.Add(result);
                     }
                 });
             }
         }
         else if (build.StopLoss && build.TakeProfit && !build.TrailingStopLoss && !build.TrailingTakeProfit)
         {
             // Stop Loss
             // Take Profit
             // --------------------------------------------------------------------------------------- Done
             Sell sell = new Sell(build, api);
             trade     = await sell.LimitAsync(trade, build.TakeProfitPrice);
             if (trade.Success)
             {
                 trade.DisplayType = "TPSLVC";
                 TradeDB tradeDB   = new TradeDB();
                 await tradeDB.UpdateAsync(trade);
                 var scanStop = Task.Run(async() => {
                     Scan scan          = new Scan(build, api);
                     TradeResult result = scan.MiddleOrderFlip(trade);
                     trade.Status       = false;
                     await tradeDB.UpdateAsync(trade);
                     if (result.Success)
                     {
                         TradeResultDB resultDB = new TradeResultDB();
                         resultDB.Add(result);
                     }
                 });
             }
         }
         else if (build.StopLoss && build.TakeProfit && build.TrailingStopLoss && !build.TrailingTakeProfit)
         {
             // Stop Loss
             // Take Profit
             // Trailing Stop Loss
             //
             Sell sell = new Sell(build, api);
             trade     = await sell.LimitAsync(trade, build.TakeProfitPrice);
             if (trade.Success)
             {
                 trade.DisplayType = "TPSLVC";
                 TradeDB tradeDB   = new TradeDB();
                 await tradeDB.UpdateAsync(trade);
                 var scanStop = Task.Run(async() => {
                     Scan scan          = new Scan(build, api);
                     TradeResult result = scan.MiddleOrderFlip(trade);
                     trade.Status       = false;
                     await tradeDB.UpdateAsync(trade);
                     if (result.Success)
                     {
                         TradeResultDB resultDB = new TradeResultDB();
                         resultDB.Add(result);
                     }
                 });
             }
         }
         else if (build.StopLoss && build.TakeProfit && !build.TrailingStopLoss && build.TrailingTakeProfit)
         {
             // Stop Loss
             // Take Profit
             // Trailing Take Profit
             Sell sell = new Sell(build, api);
             trade     = await sell.LimitAsync(trade, build.TakeProfitPrice);
             if (trade.Success)
             {
                 trade.DisplayType = "TPSLVC";
                 TradeDB tradeDB   = new TradeDB();
                 await tradeDB.UpdateAsync(trade);
                 var scanStop = Task.Run(async() => {
                     Scan scan          = new Scan(build, api);
                     TradeResult result = scan.MiddleOrderFlip(trade);
                     trade.Status       = false;
                     await tradeDB.UpdateAsync(trade);
                     if (result.Success)
                     {
                         TradeResultDB resultDB = new TradeResultDB();
                         resultDB.Add(result);
                     }
                 });
             }
         }
         else if (build.StopLoss && build.TakeProfit && build.TrailingStopLoss && build.TrailingTakeProfit)
         {
             // Stop Loss
             // Take Profit
             // Trailing Stop Loss
             // Trailing Take Profit
             Sell sell = new Sell(build, api);
             trade     = await sell.LimitAsync(trade, build.TakeProfitPrice);
             if (trade.Success)
             {
                 trade.DisplayType = "TPSLVC";
                 TradeDB tradeDB   = new TradeDB();
                 await tradeDB.UpdateAsync(trade);
                 var scanStop = Task.Run(async() => {
                     Scan scan          = new Scan(build, api);
                     TradeResult result = scan.MiddleOrderFlip(trade);
                     trade.Status       = false;
                     await tradeDB.UpdateAsync(trade);
                     if (result.Success)
                     {
                         TradeResultDB resultDB = new TradeResultDB();
                         resultDB.Add(result);
                     }
                 });
             }
         }
     });
 }