Example #1
0
        public async Task <BaseTypes.TradeResult> GetOrderAmount(string OrderID, InvokePrint Print)
        {
            try
            {
                string[]         arrtmp = OrderID.Split(new char[] { '*' }, StringSplitOptions.RemoveEmptyEntries);
                BaseTypes.Market market = BaseTypes.Market.LoadFromString(arrtmp[0]);
                string           Uuid   = arrtmp[1];

                decimal amount                = -1;
                int     MaxRepeat             = 10;
                int     CurRepeat             = 0;
                BaseTypes.TradeResult tresult = new BaseTypes.TradeResult();
                while (amount == -1 && CurRepeat < MaxRepeat)
                {
                    try
                    {
                        List <HistoricOrder> OrderHistory = await GetOrderHistory(market, Print);

                        HistoricOrder needOrder = OrderHistory.Find(x => x.OrderUuid == Uuid);
                        if (needOrder != null)
                        {
                            tresult.BaseQty      = needOrder.Quantity;
                            tresult.AveragePrice = needOrder.Price;
                            tresult.IsFilled     = true;
                            amount = 2;
                        }
                        else
                        {
                            amount = 0;
                        }
                    }
                    catch
                    {
                        CurRepeat++;
                        Thread.Sleep(500); //что бы обновилась история ордеров на сервере
                    }
                }
                if (amount == -1)
                {
                    throw new Exception("Не удалось получить информацию про ордер!");
                }
                if (amount == 0)
                {
                    throw new Exception("Не удалось получить информацию про ордер, ордер не найдено!");
                }
                return(tresult);
            }
            catch (Exception ex)
            {
                System.Media.SystemSounds.Beep.Play();
                Print("Ошибка BittrexApi OrderAmount: " + ex.Message);
                return(null);
            }
        }
Example #2
0
        private static HistoricOrder ConvertBittrexCsvToCompletedOrder(IReadOnlyList <string> csvCurrentRecord)
        {
            var newOrder = new HistoricOrder()
            {
                OrderUuid  = csvCurrentRecord[0],
                Exchange   = csvCurrentRecord[1],
                Quantity   = decimal.Parse(csvCurrentRecord[3]),
                Limit      = decimal.Parse(csvCurrentRecord[4]),
                Commission = decimal.Parse(csvCurrentRecord[5]),
                Price      = decimal.Parse(csvCurrentRecord[6]),
                Timestamp  = DateTime.Parse(csvCurrentRecord[8], CultureInfo.CreateSpecificCulture("en-US"))
            };

            if (csvCurrentRecord[2] == "LIMIT_BUY")
            {
                newOrder.OrderType = BittrexSharp.Domain.OrderType.Buy;
            }
            else if (csvCurrentRecord[2] == "LIMIT_SELL")
            {
                newOrder.OrderType = BittrexSharp.Domain.OrderType.Sell;
            }

            return(newOrder);
        }