Пример #1
0
        public override bool UpdateCurrencies()
        {
            string address = "https://bittrex.com/api/v1.1/public/getcurrencies";

            byte[] bytes = null;
            try {
                bytes = GetDownloadBytes(address);
            }
            catch (Exception) {
                return(false);
            }
            if (bytes == null)
            {
                return(false);
            }

            int startIndex = 1;

            if (!JSonHelper.Default.SkipSymbol(bytes, ':', 3, ref startIndex))
            {
                return(false);
            }

            List <string[]> res = JSonHelper.Default.DeserializeArrayOfObjects(bytes, ref startIndex, new string[] { "Currency", "CurrencyLong", "MinConfirmation", "TxFee", "IsActive", "CoinType", "BaseAddress", "Notice" });

            foreach (string[] item in res)
            {
                string currency        = item[0];
                BitFinexCurrencyInfo c = (BitFinexCurrencyInfo)Currencies.FirstOrDefault(curr => curr.Currency == currency);
                if (c == null)
                {
                    c                 = new BitFinexCurrencyInfo();
                    c.Currency        = item[0];
                    c.CurrencyLong    = item[1];
                    c.MinConfirmation = int.Parse(item[2]);
                    c.TxFee           = FastValueConverter.Convert(item[3]);
                    c.CoinType        = item[5];
                    c.BaseAddress     = item[6];

                    Currencies.Add(c);
                }
                c.IsActive = item[4].Length == 4;
            }
            return(true);
        }
Пример #2
0
        public bool UpdateOrderBook(Ticker ticker, byte[] bytes, bool raiseChanged, int depth)
        {
            if (bytes == null)
            {
                return(false);
            }

            int startIndex = 0;

            List <string[]> items = JSonHelper.Default.DeserializeArrayOfArrays(bytes, ref startIndex, 3);

            ticker.OrderBook.GetNewBidAsks();
            int bidIndex = 0, askIndex = 0;
            List <OrderBookEntry> bids = ticker.OrderBook.Bids;
            List <OrderBookEntry> asks = ticker.OrderBook.Asks;

            foreach (string[] item in items)
            {
                OrderBookEntry entry = null;
                if (item[2][0] == '-')
                {
                    entry        = asks[askIndex];
                    entry.Amount = -FastValueConverter.Convert(item[2]);
                    askIndex++;
                }
                else
                {
                    entry = bids[bidIndex];
                    entry.AmountString = item[2];
                    bidIndex++;
                }
                entry.ValueString = item[0];

                if (bidIndex >= bids.Count || askIndex >= asks.Count)
                {
                    break;
                }
            }
            ticker.OrderBook.UpdateEntries();
            return(true);
        }
        bool UpdateOrderBook(Ticker ticker, byte[] bytes)
        {
            if (bytes == null)
            {
                return(false);
            }

            int startIndex = 0; // skip {

            List <string[]> items = JSonHelper.Default.DeserializeArrayOfObjects(bytes, ref startIndex, OrderBookItems);

            List <OrderBookEntry> bids  = ticker.OrderBook.Bids;
            List <OrderBookEntry> asks  = ticker.OrderBook.Asks;
            List <OrderBookEntry> iasks = ticker.OrderBook.AsksInverted;

            foreach (string[] item in items)
            {
                OrderBookEntry entry = new OrderBookEntry();

                entry.Id           = FastValueConverter.ConvertPositiveLong(item[1]);
                entry.ValueString  = item[4];
                entry.AmountString = item[3];

                if (item[2][0] == 'S')
                {
                    iasks.Add(entry);
                    asks.Insert(0, entry);
                }
                else
                {
                    bids.Add(entry);
                }
            }
            ticker.OrderBook.UpdateEntries();
            return(true);
        }
Пример #4
0
        bool OnGetAccountTrades(AccountInfo account, Ticker ticker, byte[] bytes)
        {
            if (bytes == null)
            {
                return(false);
            }

            int startIndex = 1;

            if (!JSonHelper.Default.SkipSymbol(bytes, ':', 3, ref startIndex))
            {
                return(false);
            }

            string          tradeUuid = ticker.MyTradeHistory.Count == 0 ? null : ticker.MyTradeHistory.First().IdString;
            List <string[]> res       = JSonHelper.Default.DeserializeArrayOfObjects(bytes, ref startIndex, new string[] {
                "OrderUuid",         // 0
                "Exchange",          // 1
                "TimeStamp",         // 2
                "OrderType",         // 3
                "Limit",             // 4
                "Quantity",          // 5
                "QuantityRemaining", // 6
                "Commission",        // 7
                "Price",             // 8
                "PricePerUnit",      // 9
                "IsConditional",
                "Condition",
                "ConditionTarget",
                "ImmediateOrCancel",
            },
                                                                                     (itemIndex, paramIndex, value) => {
                return(paramIndex != 0 || value != tradeUuid);
            });

            if (res == null)
            {
                return(false);
            }
            if (res.Count == 0)
            {
                return(true);
            }
            int index = 0;

            foreach (string[] obj in res)
            {
                TradeInfoItem item = new TradeInfoItem(account, ticker);
                item.IdString     = obj[0];
                item.Type         = obj[3] == "LIMIT_BUY" ? TradeType.Buy : TradeType.Sell;
                item.AmountString = obj[5];
                item.RateString   = obj[9];
                item.Fee          = FastValueConverter.Convert(obj[7]);
                item.Total        = FastValueConverter.Convert(obj[8]);
                item.TimeString   = obj[2];
                ticker.MyTradeHistory.Insert(index, item);
                index++;
            }

            return(true);
        }