public async Task <string> GetTradePartnerName(TradeMethod tradeMethod, CancellationToken token) { var ofs = GetTrainerNameOffset(tradeMethod); var data = await Connection.ReadBytesAsync(ofs, 26, token).ConfigureAwait(false); return(StringConverter.GetString7(data, 0, 26)); }
public static uint GetTrainerNameOffset(TradeMethod tradeMethod) { return(tradeMethod switch { TradeMethod.LinkTrade => LinkTradePartnerNameOffset, TradeMethod.SupriseTrade => SurpriseTradePartnerNameOffset, _ => throw new ArgumentException(nameof(tradeMethod)), });
private void aBBFSideRb_CheckedChanged(object sender, EventArgs e) { if (aBBFSideRb.Checked) { tradeSide = TradeSide.BOTH_A_B_B_FIRST; tradeMethod = TradeMethod.B_TO_A; } }
public async Task <bool> CheckTradePartnerName(TradeMethod tradeMethod, string Name, CancellationToken token) { var name = await GetTradePartnerName(tradeMethod, token).ConfigureAwait(false); return(name == Name); }
public static uint GetTrainerNameOffset(TradeMethod tradeMethod) => tradeMethod switch {
/// <summary> /// Execute trading /// </summary> private void ExecTrading() { switch (tradeSide) { case TradeSide.A_TO_B: // If not trading now if (tradingThread == null || !tradingThread.IsAlive) { // If mine amount is unlimited if (mineAmountUnlimited) { var aMaxAmount = dragonExApiForA.UserAmounts.CoinAmount; var bMaxAmount = dragonExApiForB.UserAmounts.BaseAmount / (minePrice * (1 + ConfigTool.TradeFee)); mineAmount = Math.Min(aMaxAmount, bMaxAmount); } if (mineAmount * minePrice > ConfigTool.MinimumTradeUsdtAmount) { if (mineAmountUnlimited || (mineAmount <= dragonExApiForA.UserAmounts.CoinAmount && mineAmount * minePrice * (1 + ConfigTool.TradeFee) <= dragonExApiForB.UserAmounts.BaseAmount)) { // Do trading long currentTS = DateTime.Now.Ticks; if (tradeIntervalUnlimited || currentTS - lastTradeTime >= tradeInterval * 10000000) { lastTradeTime = currentTS; logTxt.Clear(); tradingEntity = new TradingEntity(); tradingEntity.Buy = minePrice; tradingEntity.Sell = minePrice; tradingEntity.Amount = mineAmount; tradingThread = new Thread(ExecTradingAB); tradingThread.Start(); } } else { if (!mineAmountUnlimited) { logTxt.Text = ""; ResetTradingLog("Trading A=>B is ended.No Coin or Base is available.", true); } } } else { logTxt.Text = ""; ResetTradingLog("Trading A=>B is ended.No Coin or Base is available.", true); } } break; case TradeSide.B_TO_A: // If not trading now if (tradingThread == null || !tradingThread.IsAlive) { // If mine amount is unlimited if (mineAmountUnlimited) { var aMaxAmount = dragonExApiForB.UserAmounts.CoinAmount; var bMaxAmount = dragonExApiForA.UserAmounts.BaseAmount / (minePrice * (1 + ConfigTool.TradeFee)); mineAmount = Math.Min(aMaxAmount, bMaxAmount); } if (mineAmount * minePrice > ConfigTool.MinimumTradeUsdtAmount) { if (mineAmountUnlimited || (mineAmount <= dragonExApiForB.UserAmounts.CoinAmount && mineAmount * minePrice * (1 + ConfigTool.TradeFee) <= dragonExApiForA.UserAmounts.BaseAmount)) { // Do trading long currentTS = DateTime.Now.Ticks; if (tradeIntervalUnlimited || currentTS - lastTradeTime >= tradeInterval * 10000000) { lastTradeTime = currentTS; logTxt.Clear(); tradingEntity = new TradingEntity(); tradingEntity.Buy = minePrice; tradingEntity.Sell = minePrice; tradingEntity.Amount = mineAmount; tradingThread = new Thread(ExecTradingBA); tradingThread.Start(); } } else { if (!mineAmountUnlimited) { logTxt.Text = ""; ResetTradingLog("Trading B=>A is ended.No Coin or Base is available.", true); } } } else { logTxt.Text = ""; ResetTradingLog("Trading B=>A is ended.No Coin or Base is available.", true); } } break; case TradeSide.BOTH_A_B_A_FIRST: case TradeSide.BOTH_A_B_B_FIRST: // If not trading now if (tradingThread == null || !tradingThread.IsAlive) { // If mine amount is unlimited if (mineAmountUnlimited) { var aMaxAmount = dragonExApiForA.UserAmounts.CoinAmount; var bMaxAmount = dragonExApiForB.UserAmounts.BaseAmount / (minePrice * (1 + ConfigTool.TradeFee)); var aToBMineAmount = Math.Min(aMaxAmount, bMaxAmount); aMaxAmount = dragonExApiForB.UserAmounts.CoinAmount; bMaxAmount = dragonExApiForA.UserAmounts.BaseAmount / (minePrice * (1 + ConfigTool.TradeFee)); var bToAMineAmount = Math.Min(aMaxAmount, bMaxAmount); if (aToBMineAmount * minePrice <= ConfigTool.MinimumTradeUsdtAmount && bToAMineAmount * minePrice <= ConfigTool.MinimumTradeUsdtAmount) { logTxt.Text = ""; ResetTradingLog("Trade is ended.Trade amount and price is under minimum.", true); return; } switch (tradeMethod) { case TradeMethod.A_TO_B: mineAmount = aToBMineAmount; break; case TradeMethod.B_TO_A: mineAmount = bToAMineAmount; break; } } if (mineAmount * minePrice > ConfigTool.MinimumTradeUsdtAmount) { if (mineAmountUnlimited || (tradeMethod == TradeMethod.A_TO_B && mineAmount <= dragonExApiForA.UserAmounts.CoinAmount && mineAmount * minePrice * (1 + ConfigTool.TradeFee) <= dragonExApiForB.UserAmounts.BaseAmount) || (tradeMethod == TradeMethod.B_TO_A && mineAmount <= dragonExApiForB.UserAmounts.CoinAmount && mineAmount * minePrice * (1 + ConfigTool.TradeFee) <= dragonExApiForA.UserAmounts.BaseAmount)) { // Do trading long currentTS = DateTime.Now.Ticks; if (tradeIntervalUnlimited || currentTS - lastTradeTime >= tradeInterval * 10000000) { lastTradeTime = currentTS; logTxt.Clear(); lastTradeTime = currentTS; tradingEntity = new TradingEntity(); tradingEntity.Buy = minePrice; tradingEntity.Sell = minePrice; tradingEntity.Amount = mineAmount; switch (tradeMethod) { case TradeMethod.A_TO_B: tradingThread = new Thread(ExecTradingAB); break; case TradeMethod.B_TO_A: tradingThread = new Thread(ExecTradingBA); break; } tradingThread.Start(); } } else { if (!mineAmountUnlimited) { // If mine amount is not unlimited, then go to another side switch (tradeMethod) { case TradeMethod.A_TO_B: tradeMethod = TradeMethod.B_TO_A; break; case TradeMethod.B_TO_A: tradeMethod = TradeMethod.A_TO_B; break; } } } } else { if (mineAmountUnlimited) { // If mine amount is unlimited, then go to another side switch (tradeMethod) { case TradeMethod.A_TO_B: tradeMethod = TradeMethod.B_TO_A; break; case TradeMethod.B_TO_A: tradeMethod = TradeMethod.A_TO_B; break; } } else { logTxt.Text = ""; ResetTradingLog("Trade is ended.Trade amount and price is under minimum.", true); } } } break; } }