public IEnumerable <Order> OpenedOrders(Market market)
        {
            // todo: test it
            var result  = new List <Order>();
            var apiKeys = market.ApiKeys(ApiKeyRole.Trade);

            var parameters = new Tuple <string, string> [2];

            parameters[0] = Tuple.Create(EndPoints.CommandTag, EndPoints.GetBalances);
            parameters[1] = Tuple.Create("currencyPair", "all");

            var query = Connection.PrivateGetQuery <Dictionary <string, List <PoloniexOpenedOrdersDataType> > >(
                EndPoints.GetOpenedOrders, apiKeys, PostParameters(apiKeys.PublicKey, parameters));

            foreach (var key in query.Keys)
            {
                Pair pair;
                if (!PoloniexPairs.TryParsePair(key, out pair))
                {
                    continue;
                }

                var orders = query[key];
                result.AddRange(orders.Select(order => order.ToOrder(market, pair)));
            }

            return(result);
        }
        public IEnumerable <Balance> Balances(Market market)
        {
            var result = new List <Balance>();

            var apiKeys           = market.ApiKeys(ApiKeyRole.Trade);
            var balanceParameters = new Tuple <string, string> [1];

            balanceParameters[0] = Tuple.Create(EndPoints.CommandTag, EndPoints.GetBalances);

            var queryBalance = Connection.PrivatePostQuery <Dictionary <string, PoloniexBalanceDataType> >(
                EndPoints.Trading, apiKeys, PostParameters(apiKeys.PublicKey, balanceParameters));

            var purseParameters = new Tuple <string, string> [1];

            purseParameters[0] = Tuple.Create(EndPoints.CommandTag, EndPoints.GetPurseAddress);
            var queryPurse = Connection.PrivatePostQuery <Dictionary <string, string> >(
                EndPoints.Trading, apiKeys, PostParameters(apiKeys.PublicKey, purseParameters));

            foreach (var currencyName in queryBalance.Keys)
            {
                string purse;
                queryPurse.TryGetValue(currencyName, out purse);
                result.Add(
                    queryBalance[currencyName].ToBalance(
                        market.Currencies.First(c => c.Currency.Name == currencyName), purse));
            }

            return(result);
        }
        public IEnumerable <Order> OpenedOrders(Market market, Pair pair)
        {
            // todo: test it
            var result  = new List <Order>();
            var apiKeys = market.ApiKeys(ApiKeyRole.Trade);

            var parameters = new Tuple <string, string> [2];

            parameters[0] = Tuple.Create(EndPoints.CommandTag, EndPoints.GetBalances);
            parameters[1] = Tuple.Create("currencyPair", PoloniexPairs.AsString(pair));

            var query = Connection.PrivateGetQuery <List <PoloniexOpenedOrdersDataType> >(
                EndPoints.GetOpenedOrders, apiKeys, PostParameters(apiKeys.PublicKey, parameters));

            result.AddRange(query.Select(order => order.ToOrder(market, pair)));

            return(result);
        }
        public IEnumerable <Order> OpenedOrders(Market market, Pair pair)
        {
            var result  = new List <Order>();
            var apiKeys = market.ApiKeys(ApiKeyRole.Info);

            var parameters = pair == null ? null : new List <Tuple <string, string> > {
                Tuple.Create("market", BittrexPairs.AsString(pair))
            };

            var query = Connection.PrivateGetQuery <BittrexOpenedOrdersDataType>(
                EndPoints.GetOpenedOrders, apiKeys, GetParameters(apiKeys.PublicKey, parameters));

            if (query.Success && query.Orders != null)
            {
                result.AddRange(query.Orders.Select(order => order.ToOrder(market)));
            }

            return(result);
        }
        public Balance Balance(Market market, Currency currency)
        {
            Balance balance    = null;
            var     parameters = new Tuple <string, string> [1];

            parameters[0] = Tuple.Create("currency", currency.Name);

            var apiKeys = market.ApiKeys(ApiKeyRole.Info);

            var query = Connection.PrivateGetQuery <BittrexBalanceDataType>(
                EndPoints.GetBalance, apiKeys, GetParameters(apiKeys.PublicKey, parameters));

            if (query != null && query.Success && query.Balance != null)
            {
                balance = query.Balance.ToBalance(market, currency);
            }

            return(balance);
        }
        public IEnumerable <Balance> Balances(Market market)
        {
            var apiKeys = market.ApiKeys(ApiKeyRole.Info);

            var result = new List <Balance>();
            var query  = Connection.PrivateGetQuery <BittrexBalancesDataType>(
                EndPoints.GetBalances, apiKeys, GetParameters(apiKeys.PublicKey));

            if (query.Success && query.Balances != null)
            {
                result.AddRange(
                    query.Balances.Select(
                        balanceDataType =>
                        balanceDataType.ToBalance(
                            market,
                            market.Currencies.First(c => c.Currency.Name == balanceDataType.Currency).Currency)));
            }

            return(result);
        }
예제 #7
0
        public bool Cancel(Market market, OrderId orderId, out string errorMessage)
        {
            var apiKeys = market.ApiKeys(ApiKeyRole.TradeLimit);

            var parameters = new List <Tuple <string, string> >
            {
                Tuple.Create("uuid", orderId.ToString()),
            };

            var query = Connection.PrivateGetQuery <BittrexLimitOrderDataType>(
                EndPoints.CancelOrder, apiKeys, GetParameters(apiKeys.PublicKey, parameters));

            if (query.Success)
            {
                errorMessage = string.Empty;
                return(true);
            }

            errorMessage = query.Message;
            return(false);
        }