public void Clear() { BuyOrders.Clear(); SellOrders.Clear(); Position = 0; AvgPrice = 0; }
private async Task GetMarketDataOrders() { IsBusy = true; try { var marketOrders = await RestRepository.GetMarketOrdersData(Coin.Symbol); SourceList.Clear(); BuyOrders.Clear(); SourceList.AddRange(marketOrders.BuyOrders); BuyOrders.AddRange(LoadBuyOrders(0)); } catch (Exception e) { Crashes.TrackError(e); await PageDialogService.DisplayAlertAsync("Error", e.Message, "OK"); } finally { IsBusy = false; } }
public void UpdateWithExcel(List <Order> excelOrders, PositionInfo positionInfo, string symbol) { WriteToLogDB("UpdateWithExcel", "Started", symbol); // Updating CurrentState's Position if (!AvgPrice.Equals(positionInfo.AvgPrice)) { WriteToLogDB("UpdateWithExcel", "Changing AvgPrice from " + AvgPrice + " to " + positionInfo.AvgPrice, symbol); AvgPrice = positionInfo.AvgPrice; } int sideCoeff = (positionInfo.Side == "Long" ? 1 : -1); /*if (Planned != (int)positionInfo.Planned * sideCoeff) * { * WriteToLogDB("UpdateWithExcel", "Changing Planned from " + Planned + " to " + (int)positionInfo.Planned, symbol); * //Planned = ((int)positionInfo.Planned) * sideCoeff; * } */ int newPosition = ((int)positionInfo.Quantity) * sideCoeff; if (Position != newPosition) { WriteToLogDB("UpdateWithExcel", "Changing Position from " + Position + " to " + newPosition, symbol); Position = newPosition; } // Updating buy and sell orders List <int> indexesToDeleteFromCurrentState = new List <int>(); List <string> orderIds = BuyOrders.Select(order => order.OrderId).ToList(); List <int> cookies = BuyOrders.Select(order => order.Cookie).ToList(); orderIds.AddRange(SellOrders.Select(order => order.OrderId).ToList()); cookies.AddRange(SellOrders.Select(order => order.Cookie).ToList()); BuyOrders.Clear(); BuyOrders = excelOrders.Where(order => order.Action == ActionEnum.BUY).ToList(); SellOrders.Clear(); SellOrders = excelOrders.Where(order => order.Action == ActionEnum.SELL).ToList(); WriteToLogDB("UpdateWithExcel", "Buy and Sell orders from Current State Cleared. Updating from Excel", symbol); for (int i = 0; i < BuyOrders.Count; i++) { int index = orderIds.IndexOf(BuyOrders[i].OrderId); if (index >= 0) { BuyOrders[i].Cookie = cookies[index]; } else { WriteToLogDB("UpdateWithExcel", BuyOrders[i].OrderId + " not found. Order added to CurrentState from Excel", symbol); } } for (int i = 0; i < SellOrders.Count; i++) { int index = orderIds.IndexOf(SellOrders[i].OrderId); if (index >= 0) { SellOrders[i].Cookie = cookies[index]; } else { WriteToLogDB("UpdateWithExcel", SellOrders[i].OrderId + " not found. Order added to CurrentState from Excel", symbol); } } WriteToLogDB("UpdateWithExcel", "Finished", symbol); }