Esempio n. 1
0
 private void OnOrderbookCorrection(IScriptOrderbook e)
 {
     if (OrderbookCorrection != null)
     {
         OrderbookCorrection(this, e);
     }
 }
Esempio n. 2
0
        public IScriptOrderbook GetOrderbook(IScriptMarket market)
        {
            IScriptOrderbook orderbook = null;

            try
            {
                var response = Query(false, "/public/getorderbook?", new Dictionary <string, string>()
                {
                    { "market", market.SecondaryCurrency.ToUpper() + "-" + market.PrimaryCurrency.ToUpper() },
                    { "type", "both" },
                    { "depth", "50" }
                });

                if (response != null && response.Value <bool>("success"))
                {
                    orderbook = new Orderbook(response.Value <JObject>("result"));
                }
            }
            catch (Exception e)
            {
                OnError(e.Message);
            }

            return(orderbook);
        }
Esempio n. 3
0
 private void OnOrderbookUpdate(IScriptOrderbook e)
 {
     if (OrderbookUpdate != null)
     {
         OrderbookUpdate(this, e);
     }
 }
Esempio n. 4
0
        public IScriptOrderbook GetOrderbook(IScriptMarket market)
        {
            IScriptOrderbook orderbook = null;

            Console.Out.WriteLine("GetOrderbook");

            try
            {
                Market instrument = _markets.Find(c => c.PrimaryCurrency == market.PrimaryCurrency && c.SecondaryCurrency == market.SecondaryCurrency);
                JArray response   = (JArray)Call("GetL2Snapshot", new ApexL2SnapshotRequest(1, instrument.InstrumentId, 50));

                if (response != null)
                {
                    orderbook = new Orderbook(response);
                }

                if (_level2Subscriptions.Contains(market.PrimaryCurrency + market.SecondaryCurrency) == false)
                {
                    Call("SubscribeLevel2", new ApexSubscribeLevel2(1, market.PrimaryCurrency + market.SecondaryCurrency, 100));
                    _level2Subscriptions.Add(market.PrimaryCurrency + market.SecondaryCurrency);
                }
            }
            catch (Exception e)
            {
                OnError(e.Message);
            }

            return(orderbook);
        }
        private void AssertOrderbook(IScriptOrderbook orderbook)
        {
            Assert.IsNotNull(orderbook, "Bad API response");
            Assert.IsNotNull(orderbook.Asks, "Asks null");
            Assert.IsNotNull(orderbook.Bids, "Bids null");
            Assert.IsTrue(orderbook.Asks.Count > 0, "No asks found");
            Assert.IsTrue(orderbook.Bids.Count > 0, "No bids found");

            Assert.IsTrue(orderbook.Bids[0].Price > 0.0M, "Bid price zero");
            Assert.IsTrue(orderbook.Bids[0].Amount > 0.0M, "Bid amount zero");

            Assert.IsTrue(orderbook.Bids[0].Price < orderbook.Asks[0].Price, "Bid is higher than ask");
            Assert.IsTrue(orderbook.Asks[0].Price < orderbook.Asks[1].Price, "Sorting issue");
            Assert.IsTrue(orderbook.Bids[0].Price > orderbook.Bids[1].Price, "Sorting issue 2");

            var bids = new Dictionary <decimal, decimal>();
            var asks = new Dictionary <decimal, decimal>();

            foreach (var order in orderbook.Asks)
            {
                if (!asks.ContainsKey(order.Price))
                {
                    asks.Add(order.Price, order.Amount);
                }
                else
                {
                    Assert.IsFalse(true, "Double price in orderbook: " + order.Price);
                }
            }

            foreach (var order in orderbook.Bids)
            {
                if (!bids.ContainsKey(order.Price))
                {
                    bids.Add(order.Price, order.Amount);
                }
                else
                {
                    Assert.IsFalse(true, "Double price in orderbook: " + order.Price);
                }
            }
        }