public ActionResult BalanceOne() { var v = new TradeInput(); v.NoOfTrades = 200; return(View(v)); }
public ActionResult BalanceOne(TradeInput inp) { TradeData tradedata = CalculateTradeData(inp); //ViewBag.Result = outp; ViewBag.TradeData = tradedata; return(View(inp)); }
// GET: Mpa/Recharge public async Task <ActionResult> Index(TradeInput input) { RechargeViewModel model = new RechargeViewModel(); model.Users = await GetUserList(); model.TradeTypeList = GetTradeType(); return(View(model)); }
public ActionResult Index() { var cookieKey = Request.Cookies["apikey"]; var cookiesecret = Request.Cookies["apisecret"]; var ti = new TradeInput { ApiKey = cookieKey?.Value, ApiSecret = cookiesecret?.Value }; return(View("GetAllBalances", ti)); }
public PagedResultDto <TradeDetailsDto> GetUserTradeRecordList(TradeInput input) { var dbSrc = _financeTradeDetail.GetAll().WhereIf(input.userID.HasValue, m => m.UserId == input.userID) .WhereIf(input.StartDate.HasValue, m => m.CreationTime >= input.StartDate.Value) .WhereIf(input.EndDate.HasValue, m => m.CreationTime <= input.EndDate.Value) .WhereIf(!input.TradeType.IsNullOrWhiteSpace(), m => m.TradeType == input.TradeType) .OrderBy(input.Sorting); var count = dbSrc.Count(); var lists = dbSrc.Skip(input.SkipCount).Take(input.MaxResultCount).ToList(); var dtoList = Mapper.Map <List <TradeDetailsDto> >(lists); return(new PagedResultDto <TradeDetailsDto>(count, dtoList)); }
public Result Trade([FromBody] TradeInput input) { switch (input.Type) { case TranType.Bid: return(service.Bid(input.UID, input.Price, input.Size)); case TranType.Ask: return(service.Ask(input.UID, input.Price, input.Size)); default: return(Result.Fail("transaction failed.")); } }
public ActionResult TradesPerCoin(string id, string basecurrency) { string apikey = (string)Session["apikey"]; string apisecret = (string)Session["apisecret"]; if (string.IsNullOrEmpty(apikey) || string.IsNullOrEmpty(apisecret)) { return(RedirectToAction("Index")); } var inp = new TradeInput { ApiKey = apikey, ApiSecret = apisecret, Coin = id, BaseCurrency = basecurrency, NoOfTrades = 200 }; TradeData tradedata = CalculateTradeData(inp); //ViewBag.Result = outp; ViewBag.TradeData = tradedata; return(View(inp)); }
private static TradeData CalculateTradeData(TradeInput inp) { var bittrex = new Exchange(); var coin = inp.Coin.ToUpper(); var basecurr = inp.BaseCurrency; bittrex.Initialise(new ExchangeContext { ApiKey = inp.ApiKey, Secret = inp.ApiSecret, QuoteCurrency = basecurr.ToUpper(), Simulate = false }); var tick = bittrex.GetTicker(coin); var hist = bittrex.GetOrderHistory(coin, inp.NoOfTrades).OrderBy(x => x.TimeStamp).Take(inp.NoOfTrades); string outp = ""; // var buys = hist.Where(x=>x.OrderType == OpenOrderType.Limit_Buy); // var sells = hist.Where(x=>x.OrderType == OpenOrderType.Limit_Sell); // var buyQuantity = buys.Sum(x=>x.Quantity-x.QuantityRemaining); // buyQuantity.Dump("buyq"); decimal averageBuy = 0; decimal buyQuantity = 0; decimal totalBuyQuantity = 0; decimal averageSell = 0; bool first = true; var tradedata = new TradeData() { RealizedTrades = new List <RealizedTradeData>() }; foreach (var h in hist) { if (h.OrderType == OpenOrderType.Limit_Buy) { decimal prevBuyQ = buyQuantity; buyQuantity += h.Quantity - h.QuantityRemaining; totalBuyQuantity += h.Quantity - h.QuantityRemaining; averageBuy = (averageBuy * prevBuyQ) / buyQuantity + (h.PricePerUnit * ((h.Quantity - h.QuantityRemaining) / buyQuantity)); //outp += $"Bought {h.Quantity - h.QuantityRemaining} {coin} at {h.PricePerUnit} - averagebuy: {averageBuy:0.#########} Value:{h.Price} date:{h.TimeStamp}<br/>"; tradedata.RealizedTrades.Add(new RealizedTradeData { Quantity = h.Quantity - h.QuantityRemaining, AverageBuy = averageBuy, PricePerUnit = h.PricePerUnit, TotalPrice = h.Price, TimeStamp = h.TimeStamp, BuySell = "Buy" }); first = false; } else { var sold = h.Quantity - h.QuantityRemaining; if (first) { //outp += $"First order is sell, ignoring!!! Sold {sold} at {h.PricePerUnit} date: {h.TimeStamp}<br/>"; } else { var pl = ((h.PricePerUnit - averageBuy) / averageBuy) * 100; var plValue2 = h.PricePerUnit * h.Quantity - (averageBuy * h.Quantity); buyQuantity -= sold; // averageSell = (averageSell * prevBuyQ) / buyQuantity + (h.PricePerUnit * ((h.Quantity - h.QuantityRemaining) / buyQuantity)); // outp += $"Sold {sold} at {h.PricePerUnit} P/L:{pl:0.##}% remaining:{buyQuantity} Value: {h.Price} date: {h.TimeStamp}<br/>"; tradedata.RealizedTrades.Add(new RealizedTradeData { Quantity = sold, RemainingQuantity = buyQuantity, AverageBuy = averageBuy, ProfitLoss = pl, PricePerUnit = h.PricePerUnit, TotalPrice = h.Price, TimeStamp = h.TimeStamp, ProfitLossValue = plValue2, BuySell = "Sell" }); } } } if (buyQuantity > 0) { decimal unrealized = ((tick.Last - averageBuy) / averageBuy) * 100; outp += $"<h3>Unrealized P/L: last:{tick.Last} {unrealized:0.##} Quantity: {buyQuantity} Value: {buyQuantity * tick.Last}</h3>"; tradedata.UnrealizedTrade = new TotalTrade { ProfitLoss = unrealized, ProfitLossValue = (tick.Last * buyQuantity) - (averageBuy * buyQuantity), RemainingQuantity = buyQuantity, Value = buyQuantity * tick.Last, LastPrice = tick.Last }; } // realized p/l //var soldTotalPrice = tradedata.RealizedTrades.Where(x => x.BuySell == "Sell").Sum(x => x.TotalPrice); //var soldTotalQuantity = tradedata.RealizedTrades.Where(x => x.BuySell == "Sell").Sum(x => x.Quantity); //var totalPriceFromAverageBuy = averageBuy * soldTotalQuantity; //var realizedPL = ((soldTotalPrice-totalPriceFromAverageBuy)/totalPriceFromAverageBuy)*100; IEnumerable <RealizedTradeData> sells = tradedata.RealizedTrades.Where(x => x.BuySell == "Sell").ToList(); var soldTotalQuantity = sells.Sum(x => x.Quantity); var realizedPL = sells.Sum(x => x.ProfitLoss * (x.Quantity / soldTotalQuantity)); var realizedPLValue = sells.Sum(x => x.ProfitLossValue); var value = sells.Sum(x => x.TotalPrice); tradedata.RealizedTrade = new TotalTrade { ProfitLoss = realizedPL, RemainingQuantity = soldTotalQuantity, Value = value, ProfitLossValue = realizedPLValue }; return(tradedata); }