コード例 #1
0
ファイル: KrakenProvider.cs プロジェクト: Snake4life/prime
        private async Task <OrderBook> GetOrderBookLocalAsync(IKrakenApi api, AssetPair assetPair, int?maxCount)
        {
            var pair       = assetPair;
            var remotePair = new AssetPair(pair.Asset1.ToRemoteCode(this), pair.Asset2.ToRemoteCode(this));

            var r = await api.GetOrderBookAsync(remotePair.ToTicker(this), maxCount ?? 0).ConfigureAwait(false);

            CheckResponseErrors(r);

            var data      = r.result.FirstOrDefault();
            var orderBook = new OrderBook(Network, assetPair);

            var asks = maxCount.HasValue ? data.Value.asks.Take(maxCount.Value / 2).ToArray() : data.Value.asks;
            var bids = maxCount.HasValue ? data.Value.bids.Take(maxCount.Value / 2).ToArray() : data.Value.bids;

            foreach (var i in bids.Select(GetBidAskData))
            {
                orderBook.Add(OrderType.Bid, i.Price, i.Volume);
            }

            foreach (var i in asks.Select(GetBidAskData))
            {
                orderBook.Add(OrderType.Ask, i.Price, i.Volume);
            }

            return(orderBook);
        }
コード例 #2
0
        /// <summary>
        /// Returns list of currently open orders.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="market"></param>
        /// <returns></returns>
        private async Task <IEnumerable <TradeOrderStatus> > GetOpenOrders(NetworkProviderPrivateContext context, AssetPair market = null)
        {
            var api = ApiProvider.GetApi(context);

            var body = CreatePoloniexBody(PoloniexBodyType.ReturnOpenOrders);

            body.Add("currencyPair", market != null ? market.ToTicker(this) : "all");

            var rRaw = await api.GetOpenOrdersAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            var openOrders = new List <TradeOrderStatus>();

            foreach (var rMarketOrders in r)
            {
                var orderMarket = rMarketOrders.Key.ToAssetPair(this);

                foreach (var rOrder in rMarketOrders.Value)
                {
                    var isBuy = rOrder.type.Equals("buy", StringComparison.OrdinalIgnoreCase);
                    openOrders.Add(new TradeOrderStatus(Network, rOrder.orderNumber.ToString(), isBuy, true, false)
                    {
                        Market        = orderMarket,
                        AmountInitial = rOrder.amount,
                        Rate          = rOrder.rate
                    });
                }
            }

            return(openOrders);
        }