コード例 #1
0
        public void UpdateTickersInfo()
        {
            string address = "https://poloniex.com/public?command=returnTicker";
            string text    = GetDownloadString(address);

            if (string.IsNullOrEmpty(text))
            {
                return;
            }
            JObject res = (JObject)JsonConvert.DeserializeObject(text);

            foreach (JProperty prop in res.Children())
            {
                PoloniexTicker t   = Tickers.FirstOrDefault((i) => i.CurrencyPair == prop.Name);
                JObject        obj = (JObject)prop.Value;
                t.Last       = obj.Value <double>("last");
                t.LowestAsk  = obj.Value <double>("lowestAsk");
                t.HighestBid = obj.Value <double>("highestBid");
                t.Change     = obj.Value <double>("percentChange");
                t.BaseVolume = obj.Value <double>("baseVolume");
                t.Volume     = obj.Value <double>("quoteVolume");
                t.IsFrozen   = obj.Value <int>("isFrozen") != 0;
                t.Hr24High   = obj.Value <double>("high24hr");
                t.Hr24Low    = obj.Value <double>("low24hr");
            }
        }
コード例 #2
0
        public void GetOrderBook(PoloniexTicker ticker, int depth)
        {
            string address = string.Format("https://poloniex.com/public?command=returnOrderBook&currencyPair={0}&depth={1}",
                                           Uri.EscapeDataString(ticker.CurrencyPair), depth);
            string text;

            using (WebClient client = new WebClient()) {
                text = client.DownloadString(address);
            }
            ticker.OrderBook.Bids.Clear();
            ticker.OrderBook.Asks.Clear();

            JObject res = (JObject)JsonConvert.DeserializeObject(text);

            foreach (JProperty prop in res.Children())
            {
                if (prop.Name == "asks" || prop.Name == "bids")
                {
                    OrderBookEntryType type  = prop.Name == "asks" ? OrderBookEntryType.Ask : OrderBookEntryType.Bid;
                    JArray             items = prop.Value.ToObject <JArray>();
                    foreach (JArray item in items.Children())
                    {
                        OrderBookUpdateInfo info = new OrderBookUpdateInfo();
                        info.Type   = prop.Name == "asks" ? OrderBookEntryType.Ask : OrderBookEntryType.Bid;
                        info.Entry  = new OrderBookEntry();
                        info.Action = OrderBookUpdateType.Modify;
                        JEnumerable <JToken> values = (JEnumerable <JToken>)item.Children();
                        JValue rateValue            = (JValue)values.First();
                        info.Entry.Value  = rateValue.ToObject <double>();
                        info.Entry.Amount = rateValue.Next.ToObject <double>();
                        if (type == OrderBookEntryType.Ask)
                        {
                            ticker.OrderBook.ForceAddAsk(info);
                        }
                        else
                        {
                            ticker.OrderBook.ForceAddBid(info);
                        }
                    }
                }
                else if (prop.Name == "seq")
                {
                    ticker.OrderBook.SeqNumber = prop.Value.ToObject <int>();
                    Console.WriteLine("Snapshot seq no = " + ticker.OrderBook.SeqNumber);
                }
                else if (prop.Name == "isFrozen")
                {
                    ticker.IsFrozen = prop.Value.ToObject <int>() == 0;
                }
            }
            ticker.OrderBook.ApplyQueueUpdates();
        }
コード例 #3
0
        protected void RaiseTickerUpdate(PoloniexTicker t)
        {
            TickerUpdateEventArgs e = new TickerUpdateEventArgs()
            {
                Ticker = t
            };

            if (TickerUpdate != null)
            {
                TickerUpdate(this, e);
            }
            t.RaiseChanged();
        }
コード例 #4
0
        public IDisposable ConnectOrderBook(PoloniexTicker ticker)
        {
            ticker.OrderBook.Updates.Clear();
            DefaultWampChannelFactory channelFactory =
                new DefaultWampChannelFactory();

            IWampChannel wampChannel = channelFactory.CreateJsonChannel(PoloniexServerAddress, "realm1");

            wampChannel.Open().Wait();

            ISubject <OrderBookUpdateInfo> subject = wampChannel.RealmProxy.Services.GetSubject <OrderBookUpdateInfo>(ticker.OrderBook.Owner.Name, new OrderBookUpdateInfoConverter());

            return(subject.Subscribe(x => ticker.OrderBook.OnRecvUpdate(x)));
        }
コード例 #5
0
 public void Assign(PoloniexTicker ticker)
 {
     CurrencyPair = ticker.CurrencyPair;
     Last         = ticker.Last;
     LowestAsk    = ticker.LowestAsk;
     HighestBid   = ticker.HighestBid;
     Change       = ticker.Change;
     BaseVolume   = ticker.BaseVolume;
     Volume       = ticker.Volume;
     IsFrozen     = ticker.IsFrozen;
     Hr24High     = ticker.Hr24High;
     Hr24Low      = ticker.Hr24Low;
     Time         = ticker.Time;
 }
コード例 #6
0
 private void GetTickerItem(PoloniexTicker item)
 {
     lock (Tickers) {
         PoloniexTicker t = Tickers.FirstOrDefault((i) => i.CurrencyPair == item.CurrencyPair);
         if (t != null)
         {
             lock (t) {
                 t.Assign(item);
                 t.UpdateHistoryItem();
                 RaiseTickerUpdate(t);
             }
         }
         else
         {
             Tickers.Add(item);
             RaiseTickerUpdate(item);
         }
     }
 }
コード例 #7
0
 public void UpdateTrades(PoloniexTicker ticker)
 {
     throw new NotImplementedException();
 }
コード例 #8
0
        void UpdateGrid(PoloniexTicker info)
        {
            int rowHandle = this.gridView1.GetRowHandle(info.Index);

            this.gridView1.RefreshRow(rowHandle);
        }