/// <summary> /// Buy on market exchange /// </summary> /// <param name="pair">the target pair</param> /// <param name="rate">the price in the original currency</param> /// <param name="amount">the amount in the original currency</param> /// <returns></returns> public TradeDone Buy(Pair pair, Double rate, Double Initialamount) { //convert to the target currency because this is amount required in target currency for all exchange Double amount = Initialamount / rate; WebClient client = new WebClient(); client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; client.Headers["key"] = ApiKey; String PostData = String.Concat("command=buy&nonce=", DateTime.Now.getUnixTime() , "¤cyPair=", pair.ToString() , "&rate=", String.Format(CultureInfo.InvariantCulture, "{0:F20}", rate).TrimEnd('0') , "&amount=", String.Format(CultureInfo.InvariantCulture, "{0:F20}", amount).TrimEnd('0') , "&immediateorcancel=1"); EncryptPost(client, PostData); if (!DryRun) { String content = client.UploadString(PostUrl, "POST", PostData); return(JsonConvert.DeserializeObject <TradeDone>(content)); } else { TradeDone fake = new TradeDone(); fake.orderNumber = "1"; fake.resultingTrades = new List <ResultingTrade>(); fake.resultingTrades.Add(new ResultingTrade { amount = amount, rate = rate, date = DateTime.Now, type = "buy" }); return(fake); } }
public Boolean Sell() { MarketOrderBook ob = _broker.returnMarketOrderBook(_TradedPair, 20); Double amount = TargetWallet.amount; while (amount > Convert.ToDouble(ConfigurationManager.AppSettings["Minimum_trade"])) { TradeDone order = _broker.Sell(_TradedPair, ob.GetTheNextBids().rate, amount); amount = amount - order.totalAmountDoneTargetCurrency; } return(false); }
public override void run() { L2Player player = Client.CurrentPlayer; if (player.TradeState < 3)// умник { player.sendActionFailed(); return; } if (player.requester == null) { player.sendMessage("Your trade requestor has logged off."); player.sendActionFailed(); player.TradeState = 0; if (player.currentTrade != null) { player.currentTrade.Clear(); } return; } if (bDone) { player.TradeState = 4; player.requester.sendPacket(new SystemMessage(121).addPlayerName(player.Name));//$c1 has confirmed the trade. if (player.requester.TradeState == 4) { TradeManager.getInstance().PersonalTrade(player, player.requester); } } else { TradeDone end = new TradeDone(false); player.TradeState = 0; player.currentTrade.Clear(); player.sendPacket(end); player.requester.sendPacket(new SystemMessage(124).addPlayerName(player.Name));//$c1 has cancelled the trade. player.requester.TradeState = 0; player.requester.currentTrade.Clear(); player.requester.sendPacket(end); player.requester = null; } }
public override async Task RunImpl() { await Task.Run(() => { L2Player player = _client.CurrentPlayer; if (player.TradeState < 3) // умник { player.SendActionFailedAsync(); return; } if (player.Requester == null) { player.SendMessageAsync("Your trade requestor has logged off."); player.SendActionFailedAsync(); player.TradeState = 0; player.CurrentTrade?.Clear(); return; } if (_bDone) { player.TradeState = 4; player.Requester.SendPacketAsync(new SystemMessage(SystemMessageId.S1ConfirmedTrade).AddPlayerName(player.Name)); if (player.Requester.TradeState == 4) { TradeManager.GetInstance().PersonalTrade(player, player.Requester); } } else { TradeDone end = new TradeDone(false); player.TradeState = 0; player.CurrentTrade.Clear(); player.SendPacketAsync(end); player.Requester.SendPacketAsync(new SystemMessage(SystemMessageId.S1CanceledTrade).AddPlayerName(player.Name)); player.Requester.TradeState = 0; player.Requester.CurrentTrade.Clear(); player.Requester.SendPacketAsync(end); player.Requester = null; } }); }