示例#1
0
        public Depth GetDepth(Currency currency)
        {
            DepthResponse depthResponse = restClient.GetResponse <DepthResponse>(String.Format("BTC{0}/money/depth/fetch", currency.ToString()), Method.GET, null, AccessType.Public);

            if (depthResponse.Depth == null)
            {
                throw new Exception("Failed to deserialize JSON object of type " + typeof(Depth) + ". " + MtGoxRestClient.lastResponse);
            }
            return(depthResponse.Depth);
        }
示例#2
0
        /// <summary>
        /// пришел обновленный стакан
        /// </summary>
        private void UpdateMarketDepth(DepthResponse myDepth)
        {
            try
            {
                lock (_depthLocker)
                {
                    if (_depths == null)
                    {
                        _depths = new List <MarketDepth>();
                    }

                    var needDepth = _depths.Find(depth =>
                                                 depth.SecurityNameCode == myDepth.stream.Split('@')[0].ToUpper());

                    if (needDepth == null)
                    {
                        needDepth = new MarketDepth();
                        needDepth.SecurityNameCode = myDepth.stream.Split('@')[0].ToUpper();
                        _depths.Add(needDepth);
                    }

                    List <MarketDepthLevel> ascs = new List <MarketDepthLevel>();
                    List <MarketDepthLevel> bids = new List <MarketDepthLevel>();

                    for (int i = 0; i < myDepth.data.asks.Count; i++)
                    {
                        ascs.Add(new MarketDepthLevel()
                        {
                            Ask = Convert.ToDecimal(
                                myDepth.data.asks[i][1].ToString().Replace(".",
                                                                           CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator),
                                CultureInfo.InvariantCulture),
                            Price = Convert.ToDecimal(
                                myDepth.data.asks[i][0].ToString().Replace(".",
                                                                           CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator),
                                CultureInfo.InvariantCulture)
                        });

                        bids.Add(new MarketDepthLevel()
                        {
                            Bid = Convert.ToDecimal(
                                myDepth.data.bids[i][1].ToString().Replace(".",
                                                                           CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator),
                                CultureInfo.InvariantCulture),
                            Price = Convert.ToDecimal(
                                myDepth.data.bids[i][0].ToString().Replace(".",
                                                                           CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator),
                                CultureInfo.InvariantCulture),
                        });
                    }

                    needDepth.Asks = ascs;
                    needDepth.Bids = bids;
                    needDepth.Time = ServerTime;

                    if (NewMarketDepthEvent != null)
                    {
                        _marketDepthsToSend.Enqueue(needDepth.GetCopy());

                        if (needDepth.Asks.Count != 0 && needDepth.Bids.Count != 0)
                        {
                            _bidAskToSend.Enqueue(new BidAskSender
                            {
                                Ask      = needDepth.Bids[0].Price,
                                Bid      = needDepth.Asks[0].Price,
                                Security = myDepth.stream.Split('@')[0] != null
                                    ? GetSecurityForName(myDepth.stream.Split('@')[0].ToUpper())
                                    : null
                            });
                        }
                    }
                }
            }
            catch (Exception error)
            {
                SendLogMessage(error.ToString(), LogMessageType.Error);
            }
        }
示例#3
0
        void _client_UpdateMarketDepth(DepthResponse myDepth)
        {
            try
            {
                lock (_depthLocker)
                {
                    if (_depths == null)
                    {
                        _depths = new List <MarketDepth>();
                    }

                    if (myDepth.data.asks == null || myDepth.data.asks.Count == 0 ||
                        myDepth.data.bids == null || myDepth.data.bids.Count == 0)
                    {
                        return;
                    }

                    var needDepth = _depths.Find(depth =>
                                                 depth.SecurityNameCode == myDepth.stream.Split('@')[0].ToUpper());

                    if (needDepth == null)
                    {
                        needDepth = new MarketDepth();
                        needDepth.SecurityNameCode = myDepth.stream.Split('@')[0].ToUpper();
                        _depths.Add(needDepth);
                    }

                    List <MarketDepthLevel> ascs = new List <MarketDepthLevel>();
                    List <MarketDepthLevel> bids = new List <MarketDepthLevel>();

                    for (int i = 0; i < myDepth.data.asks.Count; i++)
                    {
                        ascs.Add(new MarketDepthLevel()
                        {
                            Ask =
                                myDepth.data.asks[i][1].ToString().ToDecimal()
                            ,
                            Price =
                                myDepth.data.asks[i][0].ToString().ToDecimal()
                        });
                    }

                    for (int i = 0; i < myDepth.data.bids.Count; i++)
                    {
                        bids.Add(new MarketDepthLevel()
                        {
                            Bid =
                                myDepth.data.bids[i][1].ToString().ToDecimal()
                            ,
                            Price =
                                myDepth.data.bids[i][0].ToString().ToDecimal()
                        });
                    }

                    needDepth.Asks = ascs;
                    needDepth.Bids = bids;
                    needDepth.Time = ServerTime;

                    if (needDepth.Time == DateTime.MinValue)
                    {
                        return;
                    }

                    if (MarketDepthEvent != null)
                    {
                        MarketDepthEvent(needDepth.GetCopy());
                    }
                }
            }
            catch (Exception error)
            {
                SendLogMessage(error.ToString(), LogMessageType.Error);
            }
        }