Ejemplo n.º 1
0
        protected void BuildOrderBook(Dictionary <string, dynamic> jsonDict, object amountPosition, object pricePosition, int?maxSize, string askKey = "asks", string bidKey = "bids")
        {
            if (OrderBook != null)
            {
                OrderBook.ClearOrderBook();
            }

            if (jsonDict != null)
            {
                OrderBook.Asks = ConvertOrderArrayListToOrderList((ArrayList)jsonDict[askKey], amountPosition, pricePosition, maxSize);
                OrderBook.Bids = ConvertOrderArrayListToOrderList((ArrayList)jsonDict[bidKey], amountPosition, pricePosition, maxSize);
            }
        }
Ejemplo n.º 2
0
        protected void BuildOrderBook(ArrayList ordersJsonStruct, int?MaxSize = null)
        {
            if (OrderBook != null)
            {
                OrderBook.ClearOrderBook();
            }

            if (ordersJsonStruct != null && ordersJsonStruct.Count > 0)
            {
                foreach (Dictionary <string, dynamic> order in ordersJsonStruct)
                {
                    string  orderType = (string)GetValueFromResponseResult(order, "type");
                    decimal amount    = (decimal)GetValueFromResponseResult(order, "amount");
                    decimal price     = (decimal)GetValueFromResponseResult(order, "price");
                    Order   newOrder  = new Order(amount, price);

                    if (orderType == "buy")
                    {
                        OrderBook.Bids.Add(newOrder);
                    }
                    else if (orderType == "sell")
                    {
                        OrderBook.Asks.Add(newOrder);
                    }
                    else
                    {
                        throw new ArgumentException("Unknown order type found in order book response from " + Name + ": " + orderType);
                    }
                }

                //UseCryptos isn't nice and doesn't supply ordered bids/asks, so reorder them with an in-place sort.
                //Bids are sorted by descending price, asks are orded by ascending price.
                OrderBook.Bids.Sort((order1, order2) => - 1 * order1.Price.CompareTo(order2.Price));
                OrderBook.Asks.Sort((order1, order2) => order1.Price.CompareTo(order2.Price));

                //If necessary, trim down the lists to the given size.
                if (MaxSize != null)
                {
                    OrderBook.Asks.RemoveRange(MaxSize.Value, OrderBook.Asks.Count - MaxSize.Value);
                    OrderBook.Bids.RemoveRange(MaxSize.Value, OrderBook.Bids.Count - MaxSize.Value);
                }
            }
        }
Ejemplo n.º 3
0
        private void ConvertOrderBookToEuro()
        {
            try
            {
                decimal conversionRate = GetUsdEurConversionRate();

                foreach (Order ask in OrderBook.Asks)
                {
                    ask.ConvertPrice(Decimal.Divide(1.0m, conversionRate));
                }

                foreach (Order bid in OrderBook.Bids)
                {
                    bid.ConvertPrice(Decimal.Divide(1.0m, conversionRate));
                }
            }
            catch (Exception)
            {
                OrderBook.ClearOrderBook();
                throw;
            }
        }