Exemple #1
0
        public static async Task <IList <OpenLoanOffer> > GetOpenLoanOffersAsync(this PoloniexClient clien)
        {
            Dictionary <String, OpenLoanOffer[]> CustomDeserializer(String value)
            {
                if (value == "[]")
                {
                    return(new Dictionary <String, OpenLoanOffer[]>());
                }

                return(JsonConvert.DeserializeObject <Dictionary <String, OpenLoanOffer[]> >(value));
            }

            var response = await clien.SendRequestAsync <Dictionary <String, OpenLoanOffer[]> >(new PoloniexRequest
            {
                Api     = PoloniexApi.Trading,
                Command = "returnOpenLoanOffers"
            }, CustomDeserializer);

            return(response.SelectMany(x =>
            {
                foreach (var value in x.Value)
                {
                    value.Symbol = x.Key;
                }

                return x.Value;
            }).ToList());
        }
Exemple #2
0
 public static async Task <IDictionary <String, Ticker> > GetTickersAsync(this PoloniexClient clien)
 {
     return(await clien.SendRequestAsync <Dictionary <String, Ticker> >(new PoloniexRequest
     {
         Api = PoloniexApi.Public,
         Command = "returnTicker"
     }));
 }
Exemple #3
0
        public static async Task <IList <AvailableBalance> > GetBalancesAsync(this PoloniexClient clien)
        {
            var response = await clien.SendRequestAsync <Dictionary <String, Decimal> >(new PoloniexRequest
            {
                Api     = PoloniexApi.Trading,
                Command = "returnBalances"
            });

            return(response.Select(x => new AvailableBalance()
            {
                Symbol = x.Key,
                Available = x.Value
            }).ToList());
        }
Exemple #4
0
        public static async Task <IList <CompleteBalance> > GetCompleteBalancesAsync(this PoloniexClient clien)
        {
            var response = await clien.SendRequestAsync <Dictionary <String, CompleteBalance> >(new PoloniexRequest
            {
                Api     = PoloniexApi.Trading,
                Command = "returnCompleteBalances"
            });

            foreach (var key in response.Keys)
            {
                response[key].Symbol = key;
            }

            return(response.Values.ToList());
        }
Exemple #5
0
        public static async Task <IList <ActiveLoan> > GetActiveLoansAsync(this PoloniexClient clien)
        {
            var response = await clien.SendRequestAsync <Dictionary <String, ActiveLoan[]> > (new PoloniexRequest
            {
                Api     = PoloniexApi.Trading,
                Command = "returnActiveLoans"
            });

            return(response.SelectMany(x =>
            {
                foreach (var value in x.Value)
                {
                    value.Status = x.Key;
                }

                return x.Value;
            }).ToList());
        }
Exemple #6
0
        public static async Task <IList <AvailableAccountBalance> > GetAvailableAccountBalancesAsync(this PoloniexClient clien)
        {
            var response = await clien.SendRequestAsync <Dictionary <String, Dictionary <String, Decimal> > > (new PoloniexRequest
            {
                Api     = PoloniexApi.Trading,
                Command = "returnAvailableAccountBalances"
            });

            var balances = new List <AvailableAccountBalance>();

            foreach (var account in response)
            {
                foreach (var symbol in account.Value)
                {
                    var balance = balances.FirstOrDefault(x => x.Symbol.Equals(symbol.Key, StringComparison.OrdinalIgnoreCase));
                    if (balance == null)
                    {
                        balance = new AvailableAccountBalance()
                        {
                            Symbol = symbol.Key
                        };
                        balances.Add(balance);
                    }

                    switch (account.Key.ToLower())
                    {
                    case "exchange":
                        balance.Exchange += symbol.Value;
                        break;

                    case "margin":
                        balance.Exchange += symbol.Value;
                        break;

                    case "lending":
                        balance.Exchange += symbol.Value;
                        break;
                    }
                }
            }

            return(balances);
        }