コード例 #1
0
        //public static void GetStatus(string username, string message)
        //{

        //    string connectionToSendMessage;
        //    Connections.TryGetValue(username, out connectionToSendMessage);

        //    //hubContext.Clients.All.acknowledgeMessage(message);

        //    var _test = new HubResponseModel()
        //    {
        //        EmpId = "123",
        //        Message = "sadasd",
        //        IsSuccess = true
        //    };

        //    if (!string.IsNullOrWhiteSpace(connectionToSendMessage))
        //    {
        //        hubContext.Clients.Client(connectionToSendMessage).acknowledgeMessage(_test);
        //    }


        //}

        public static void GetStatus(string id, string message)
        {
            //string connectionToSendMessage;
            //Connections.TryGetValue(username, out connectionToSendMessage);

            //hubContext.Clients.All.acknowledgeMessage(message);
            var _test = new HubResponseModel()
            {
                EmpId     = "123",
                Message   = "sadasd",
                IsSuccess = true
            };

            if (!string.IsNullOrWhiteSpace(id))
            {
                hubContext.Clients.Client(id).acknowledgeMessage(_test);
            }
        }
コード例 #2
0
        /// <summary>
        /// Conversions for the retrieved data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="currentutc"></param>
        /// <returns></returns>
        public DataPointImpl[] ParseData(object data, DateTime currentutc)
        {
            //Check data update type
            var result   = JSON.DeserializeDynamic(data.ToString());
            var toreturn = new List <DataPointImpl>();

            //Only do exchangeModel updates
            if (result.M == "updateExchangeState")
            {
                //Deserialize
                HubResponseModel <ExchangeStateModel> exchangeupdate = JSON.Deserialize <HubResponseModel <ExchangeStateModel> >(data.ToString(), Options.ISO8601);

                //Go trough all items
                foreach (var item in exchangeupdate.Content)
                {
                    //Check NOUNCE
                    string nounce = $"{item.MarketName}.{item.Nounce}";
                    if (_nouncememory.Contains(nounce))
                    {
                        continue;
                    }
                    else
                    {
                        _nouncememory.Enqueue(nounce);
                    }

                    //Check data
                    if (!_orderbook.TryGetValue(item.MarketName, out var orderbook))
                    {
                        //Set order book instance
                        orderbook = new OrderBook(item.MarketName);
                        _orderbook[item.MarketName] = orderbook;
                    }

                    //Update function
                    bool ProcessUpdate(int type, bool isbid, double price, double quantity) =>
                    (type == 0 && orderbook.AddQuote(isbid, price, quantity)) ||
                    (type == 1 && orderbook.RemoveQuote(isbid, price, quantity)) ||
                    (type == 2 && orderbook.UpdateQuote(isbid, price, quantity));

                    //Check for quote updates in the order book (size == 0 = remove from order book)
                    bool update = item.Sells.Count(x => ProcessUpdate(x.Type, false, x.Rate, x.Quantity)) > 0;
                    update = item.Buys.Count(x => ProcessUpdate(x.Type, true, x.Rate, x.Quantity)) > 0 | update;

                    //If update, send
                    if (update)
                    {
                        toreturn.Add(new Tick(GetQuantlerTicker(item.MarketName), DataSource)
                        {
                            AskPrice = Convert.ToDecimal(orderbook.BestAsk),
                            AskSize  = Convert.ToDecimal(orderbook.AskSize),
                            BidPrice = Convert.ToDecimal(orderbook.BestBid),
                            BidSize  = Convert.ToDecimal(orderbook.BidSize),
                            TimeZone = TimeZone.Utc,
                            Occured  = currentutc,
                            Depth    = 0
                        });
                    }

                    //Trades
                    foreach (var x in item.Fills)
                    {
                        toreturn.Add(new Tick(GetQuantlerTicker(item.MarketName), DataSource)
                        {
                            TradePrice = Convert.ToDecimal(x.Rate),
                            Size       = Convert.ToDecimal(x.Quantity),
                            Occured    = x.TimeStamp,
                            TimeZone   = TimeZone.Utc,
                            Price      = Convert.ToDecimal(x.Rate)
                        });
                    }
                }
            }
            else if (result.M == "updateSummaryState")
            {
                //Deserialize
                HubResponseModel <SummaryStateModel> updatesummary = JSON.Deserialize <HubResponseModel <SummaryStateModel> >(data.ToString(), Options.ISO8601);

                //Set all data
                foreach (var item in updatesummary.Content)
                {
                    //Check NOUNCE
                    string nounce = $"Summary.{item.Nounce}";
                    if (_nouncememory.Contains(nounce))
                    {
                        continue;
                    }
                    else
                    {
                        _nouncememory.Enqueue(nounce);
                    }

                    foreach (var x in item.Deltas)
                    {
                        //Check data
                        if (!_orderbook.TryGetValue(x.MarketName, out var orderbook))
                        {
                            //Set order book instance
                            orderbook = new OrderBook(x.MarketName);
                            _orderbook[x.MarketName] = orderbook;

                            //Set initial best bid and ask
                            orderbook.SetBestBook(true, x.Bid, x.BaseVolume);
                            orderbook.SetBestBook(false, x.Ask, x.BaseVolume);
                        }
                        else
                        {
                            //Update order book (best bid and ask)
                            orderbook.SetBestBook(true, x.Bid, orderbook.BidSize);
                            orderbook.SetBestBook(false, x.Ask, orderbook.AskSize);
                        }

                        //Summary data
                        toreturn.Add(new Tick(GetQuantlerTicker(x.MarketName), DataSource)
                        {
                            AskPrice   = Convert.ToDecimal(x.Ask),
                            AskSize    = Convert.ToDecimal(orderbook.AskSize),
                            BidPrice   = Convert.ToDecimal(x.Bid),
                            BidSize    = Convert.ToDecimal(orderbook.BidSize),
                            Depth      = 0,
                            Occured    = x.TimeStamp,
                            Price      = Convert.ToDecimal(x.Last),
                            Size       = Convert.ToDecimal(x.BaseVolume),
                            TradePrice = Convert.ToDecimal(x.Last),
                            TimeZone   = TimeZone.Utc
                        });
                    }
                }
            }

            //Return result
            return(toreturn.ToArray());
        }