public static void CheckThereIsNotOpenOrders() { bool hasOpenOrders = true; while (hasOpenOrders) { var hasException = false; MyThread.StartWithThread(() => { hasException = MyBinance._checkThereIsNotOpenOrders(out hasOpenOrders); }, _waitingForApiAnswer, "Get Binance Open Orders"); if (!hasException && hasOpenOrders) { MyConsole.WriteLine_Error($"\n\nThere is open orders. plaese close them to start.\n I will rechech on 120 seconds !!!!\n"); MyThread.GenerateConsoleWaiting(120); } if (hasException) { hasOpenOrders = true; MyConsole.WriteLine_Error($"\nThere is some error on Get Binance Open Orders.\n I will recheck on {_waitingAfterApiError} seconds !!!\n"); MyThread.GenerateConsoleWaiting(_waitingAfterApiError); } } }
public static decimal?GetLastBuyOrderPrice() { decimal?lastPrice = null; bool mustContinue = true; while (mustContinue) { mustContinue = false; var hasException = false; MyThread.StartWithThread(() => { hasException = _getLastBuyOrderPrice(out lastPrice); }, _waitingForApiAnswer, $"Get Last Buy OrderPrice"); if (hasException) { mustContinue = true; MyConsole.WriteLine_Error($"\nThere is some error on GetLastBuyOrderPrice.\n I will recheck on {_waitingAfterApiError} seconds !!!\n"); MyThread.GenerateConsoleWaiting(_waitingAfterApiError); } } return(lastPrice); }
public static decimal?PlaceOrder(string type, decimal value) { decimal?orderPrice = null; bool mustContinue = true; while (mustContinue) { mustContinue = false; var hasException = false; MyThread.StartWithThread(() => { hasException = _placeOrder(type, value, out orderPrice); }, _waitingForApiAnswer, $"Place Bainance Order type:{type} value:{value}"); if (hasException) { mustContinue = true; MyConsole.WriteLine_Error("\nThere is some error on Place Order.\n I will recheck on {_waitingAfterApiError} seconds !!!\n"); MyThread.GenerateConsoleWaiting(_waitingAfterApiError); } } return(orderPrice); }
public static void GetBalance(out decimal usdt, out decimal btc) { usdt = 0; btc = 0; decimal myUsdt = 0; decimal myBtc = 0; bool mustContinue = true; while (mustContinue) { mustContinue = false; var hasException = false; MyThread.StartWithThread(() => { hasException = _getBalance(out myUsdt, out myBtc); }, _waitingForApiAnswer, "Get My Binance Balance"); if (hasException) { mustContinue = true; MyConsole.WriteLine_Error($"\nThere is some error on Get Binance Balance.\n I will recheck on {_waitingAfterApiError} second !!!\n"); MyThread.GenerateConsoleWaiting(_waitingAfterApiError); } usdt = myUsdt; btc = myBtc; } }
internal static DateTime?CheckBuyEmail(string type, int validMinuteDuration, double recheckEmail_second, DateTime startTime) { var validSecondDuration = validMinuteDuration * 60; var searchSubject = "Alert: buy signal!!!"; var tokenAddress = "token_buy.json"; var credentialFile = "gmail_Buy_cridential.json"; if (type == "sell") { searchSubject = "Alert: sell signal!!!"; tokenAddress = "token_sell.json"; credentialFile = "gmail_Sell_cridential.json"; } DateTime?lastMessageDate = null; var co = 1; var maxChack = MyConfig.Config.numberOfEmailCheck ?? 5; bool mustContinue = true; while (mustContinue && co <= maxChack) { MyConsole.WriteLine_Info($"\n\nChecking Email {co} of {maxChack} \n\n"); mustContinue = false; var hasException = false; MyThread.StartWithThread(() => { hasException = checkEmail(credentialFile, tokenAddress, searchSubject, out lastMessageDate); }, 60, "Check Gmail"); if (hasException) { mustContinue = true; MyConsole.WriteLine_Error("\nThere is some error on Check Gmail.\n I will recheck on 60 second !!!\n"); MyThread.GenerateConsoleWaiting(60); } if (!hasException && !lastMessageDate.HasValue) { //کلا ایمیلی یافت نشد mustContinue = true; MyConsole.WriteLine_Info($"Dont Found any Email. Recheck on {recheckEmail_second} seconds "); MyThread.GenerateConsoleWaiting(recheckEmail_second); } if (!hasException && lastMessageDate.HasValue) { var a = DateTime.Now.Subtract(lastMessageDate.Value).TotalSeconds; if (a > validSecondDuration) { mustContinue = true; MyConsole.WriteLine_Error($"\nEmail time is {lastMessageDate} and Expired. More than {validSecondDuration} seconds have elapsed since the email arrived {a}\n"); MyConsole.WriteLine_Info($"Recheck on {recheckEmail_second} seconds"); MyThread.GenerateConsoleWaiting(recheckEmail_second); } else { if (lastMessageDate.Value > startTime) { return(lastMessageDate.Value); } MyConsole.WriteLine_Error($"\n\nEmail after start. start:{startTime} emailTime:{lastMessageDate.Value}. I wait {recheckEmail_second} for another one.\n\n"); MyThread.GenerateConsoleWaiting(recheckEmail_second); mustContinue = true; } } co++; } return(null); }