public static bool Start(OrderHandling orderHandling) { bool result = false; bool orderIsLeft = false; decimal cutAmountFee = 1; orderHandling.StartOrderHandling(); /// buy orderHandling.OrderToCare = orderHandling.Buy; if (!HandlingOneOrderTrade(orderHandling, true)) { return(false); } if (orderHandling.OrderToCare.amountFilled > orderHandling.AmountTrade) { string warningMessage = String.Format("orderHandling.OrderToCare.amountFilled - {0}, orderHandling.AmountTrade - {1},", orderHandling.OrderToCare.amountFilled, orderHandling.AmountTrade); PrintTable.PrintConsole(warningMessage); PrintFunc.AddLine(StaticVariables.pathWithDate + "WARNING_amountFilled Greater than AmountTrade.txt", warningMessage); PrintTable.Start(StaticVariables.pathWithDate + "WARNING_amountFilledOrderHandlingData.csv", orderHandling.PrintResult_2(), "OrderHandling"); } else if (orderHandling.OrderToCare.amountFilled <= orderHandling.AmountTrade) { if (StaticVariables.CurrencyTradingFeeReduction) { cutAmountFee = StaticVariables.api.FeeTrade(orderHandling.OrderToCare.originalMaxOrMinPrice == orderHandling.OrderToCare.request.Price); orderHandling.AmountTrade = orderHandling.OrderToCare.amountFilled * cutAmountFee; } else { orderHandling.AmountTrade = orderHandling.OrderToCare.amountFilled; } orderHandling.Sell.Request.Amount = orderHandling.AmountTrade; if (orderHandling.itsBuyArbitrage) { orderHandling.Arbitrage.Request.Amount = orderHandling.AmountTrade * orderHandling.Buy.request.Price; } else { orderHandling.Arbitrage.Request.Amount = orderHandling.AmountTrade * orderHandling.Sell.request.Price; } if (orderHandling.Arbitrage.request.Amount < orderHandling.arbitrageSymbolsDate.MinAmount) { orderHandling.Arbitrage.request.Amount = orderHandling.arbitrageSymbolsDate.MinAmount; } } if (orderHandling.AmountTrade < orderHandling.minAmountTrade) { return(false); } // sell orderHandling.percent_2 = orderHandling.revnuCalculation(orderHandling.percent_1); orderHandling.ChangeMaxOrMinPriceSell((StaticVariables.revnuTrade / 100)); orderHandling.OrderToCare = orderHandling.Sell; orderHandling.OrderToCare.UpExtraPercent(); if (!HandlingOneOrderTrade(orderHandling, false)) { orderIsLeft = true; orderHandling.buySymbolsDate.magicNumber.Buy.WaitingTimeForNextPriceUpdate -= 300; // USE to ML_4 orderHandling.sellSymbolsDate.magicNumber.Sell.WaitingTimeForNextPriceUpdate -= 300; // USE to ML_4 } result = true; #if DEBUG orderHandling.debug += String.Format("\n\n{0},cutAmountFee,\n{1},Buy.extraPercent.Percent,\n{2},AmountTrade,\n{3},Sell.request.Amount,", cutAmountFee, orderHandling.Buy.extraPercent.Percent, orderHandling.AmountTrade, orderHandling.OrderToCare.request.Amount); PrintFunc.AddLine(StaticVariables.pathDebug + orderHandling.currency + "/sell_" + orderHandling.currency + ".csv", orderHandling.debug); #endif if (StaticVariables.CurrencyTradingFeeReduction) { cutAmountFee = StaticVariables.api.FeeTrade(orderHandling.OrderToCare.originalMaxOrMinPrice == orderHandling.OrderToCare.request.Price); orderHandling.AmountTrade = orderHandling.AmountTrade * cutAmountFee; } if (orderHandling.itsBuyArbitrage) { orderHandling.Arbitrage.Request.Amount = orderHandling.AmountTrade * orderHandling.Buy.request.Price; } else { orderHandling.Arbitrage.Request.Amount = orderHandling.AmountTrade * orderHandling.Sell.request.Price; } if (orderHandling.Arbitrage.request.Amount < orderHandling.arbitrageSymbolsDate.MinAmount) { orderHandling.Arbitrage.request.Amount = orderHandling.arbitrageSymbolsDate.MinAmount; } // arbitrage orderHandling.percent_3 = orderHandling.revnuCalculation(orderHandling.percent_2); orderHandling.ChangeMaxOrMinPriceArbitrage((StaticVariables.revnuTrade / 100)); orderHandling.OrderToCare = orderHandling.Arbitrage; orderHandling.OrderToCare.UpExtraPercent(); try { if (!HandlingOneOrderTrade(orderHandling, false)) { orderIsLeft = true; if (orderHandling.itsBuyArbitrage) { orderHandling.arbitrageSymbolsDate.magicNumber.Buy.WaitingTimeForNextPriceUpdate -= 300; // USE to ML_4 } else { orderHandling.arbitrageSymbolsDate.magicNumber.Sell.WaitingTimeForNextPriceUpdate -= 300; // USE to ML_4 } } CancellationFunc.Cancellation99(orderHandling); } catch (Exception ex) { DateTime localDate = DateTime.Now; string printResult = String.Format("{0}\n{1}", localDate.ToString(), ex.ToString()); string fileName = String.Format("ExceptionArbitrage_{0}_{1}", (orderHandling.OrderToCare.request.IsBuy ? "Buy" : "Sell"), orderHandling.OrderToCare.request.Symbol); PrintException.Start(fileName, printResult); // TODU Send to a function to check if step b (sell) has been performed. And resubmit arbitrage order. The function should use a database to restore if the boot is shut down and restarted } #if DEBUG orderHandling.debug += String.Format("\n\n{0},cutAmountFee,\n{1},Sell.extraPercent.Percent,\n{2},AmountTrade,\n{3},Sell.request.Amount,", cutAmountFee, orderHandling.Sell.extraPercent.Percent, orderHandling.AmountTrade, orderHandling.OrderToCare.request.Amount); PrintFunc.AddLine(StaticVariables.pathDebug + orderHandling.currency + "/Arbitrage_" + orderHandling.currency + ".csv", orderHandling.debug); #endif // TODO Add a unique id variable to OrderHandling and send to a function that handles incomplete orders (orderLeft) if (!orderIsLeft) { PrintTable.PrintConsole("yes"); orderHandling.buySymbolsDate.magicNumber.Buy.WaitingTimeForNextPriceUpdate += 500; // USE to ML_4 orderHandling.sellSymbolsDate.magicNumber.Sell.WaitingTimeForNextPriceUpdate += 500; // USE to ML_4 if (orderHandling.itsBuyArbitrage) { orderHandling.arbitrageSymbolsDate.magicNumber.Buy.WaitingTimeForNextPriceUpdate += 500; // USE to ML_4 } else { orderHandling.arbitrageSymbolsDate.magicNumber.Sell.WaitingTimeForNextPriceUpdate += 500; // USE to ML_4 } } orderHandling.percent_end = orderHandling.revnuCalculation(orderHandling.percent_3); orderHandling.WalletResultEnd(); PrintTable.Start(StaticVariables.pathWithDate + "WalletResultReal.csv", orderHandling.summaryTradeReal, "WalletResultReal"); PrintTable.Start(StaticVariables.pathWithDate + "WalletResult.csv", orderHandling.summaryTrade, "WalletResult"); PrintFunc.AddLine(StaticVariables.pathWithDate + "main.txt", orderHandling.PrintResult()); PrintTable.Start(StaticVariables.pathWithDate + "OrderHandlingData.csv", orderHandling.PrintResult_2(), "OrderHandling"); #if DEBUG PrintFunc.AddLine(StaticVariables.pathDebug + orderHandling.currency + "/end_" + orderHandling.currency + ".csv", orderHandling.debug); #endif result = orderHandling.succsseTrade; return(result); }