コード例 #1
0
ファイル: Program.cs プロジェクト: PayZhang/HBTester
        static void Main(string[] args)
        {
            tickDatas = new Dictionary <string, TickData>();
            HuobiMarket market = new HuobiMarket();

            market.OnMessage    += TickUpdate;
            market.OnConnecteed += HBConnected;
            string url = "wss://api.huobipro.com/ws";

            try
            {
                market.Init(url);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            List <string> symbols = new List <string>()
            {
                "btcusdt", "eosbtc", "eosusdt"
            };

            foreach (var item in symbols)
            {
                tickDatas[item] = new TickData();
                string str = "market." + item + ".depth.step0";
                market.Subscribe(str, "33233011");
            }

            //thread = new Thread(new ThreadStart(RecordeDatas));


            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: PayZhang/HBTester
        static private void TickUpdate(object sender, HuoBiMessageReceivedEventArgs args)
        {
            var msg = args.Message;

            try
            {
                if (msg.Contains("bid"))
                {
                    HuoBiTick tick;
                    int       tickCount = 0;
                    JObject   jo        = (JObject)JsonConvert.DeserializeObject(msg);
                    string    symbol    = jo["ch"].ToString().Split('.')[1];
                    tick = JsonConvert.DeserializeObject <HuoBiTick>(jo["tick"].ToString());

                    if (!tickDatas.TryGetValue(symbol, out TickData quote))
                    {
                        quote = new TickData();
                    }

                    List <string> list       = msg.Split(':').ToList();
                    List <string> listSymbol = list[1].Split('.').ToList();

                    quote.UpdateTime      = DateTime.Now;
                    quote.Exchange        = "HB";
                    quote.BestBid         = (decimal)tick.bids[0][0];
                    quote.BestBidQuantity = (decimal)tick.bids[0][1];
                    quote.BestAsk         = (decimal)tick.asks[0][0];
                    quote.BestAskQuantity = (decimal)tick.asks[0][1];

                    if (tick.asks.Count > 10)
                    {
                        tickCount = 10;
                    }
                    else
                    {
                        tickCount = tick.asks.Count;
                    }
                    quote.AskPriceQueue         = new decimal[tickCount];
                    quote.AskQuantityQueue      = new decimal[tickCount];
                    quote.AskPriceQueueCount    = tickCount;
                    quote.AskQuantityQueueCount = tickCount;
                    quote.BidPriceQueue         = new decimal[tickCount];
                    quote.BidQuantityQueue      = new decimal[tickCount];
                    quote.BidPriceQueueCount    = tickCount;
                    quote.BidQuantityQueueCount = tickCount;
                    for (int i = 0; i < tickCount; i++)
                    {
                        quote.AskPriceQueue[i]    = (decimal)tick.asks[i][0];
                        quote.AskQuantityQueue[i] = (decimal)tick.asks[i][1];
                        quote.BidPriceQueue[i]    = (decimal)tick.bids[i][0];
                        quote.BidQuantityQueue[i] = (decimal)tick.bids[i][1];
                    }

                    //var instrument = instrumentList.Where(x => x.Symbol == symbolDict[listSymbol[1]]).FirstOrDefault();
                    quote.InstrumentId = 0;
                    quote.Symbol       = symbol;

                    tickDatas[symbol] = quote;

                    Console.WriteLine("TickData > Symbol : " + quote.Symbol + ", BestBid : " + quote.BestBid + ", BestAsk : " + quote.BestAsk);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }