public List <BaseBookWarrant> GetBookWarrants(List <BaseCurrencyPair> pairs, int limit = 100) { List <BaseBookWarrant> rezalt = new List <BaseBookWarrant>(); if (limit > 5000) { limit = 5000; } WebConector wc = new WebConector(); string api_name = "/api/v3/depth"; foreach (var pair in pairs) { string pair_name = pair.PairName; string paramtr = "?&symbol=" + pair_name + "&limit=" + limit; string jsonRezalt = wc.ReqwestGetAsync(string.Format("{0}{1}{2}", base_url, api_name, paramtr), new List <Tuple <string, string> >(), "").Result; var jsonRezaltArray = JObject.Parse(jsonRezalt); if (jsonRezaltArray.Count > 0) { BaseBookWarrant bbw = new BaseBookWarrant(); bbw.Name = pair_name; bbw.Ask = JArray.Parse(jsonRezaltArray["asks"].ToString()).ToObject <double[, ]>(); bbw.Bid = JArray.Parse(jsonRezaltArray["bids"].ToString()).ToObject <double[, ]>(); double ask_amount = 0.0; for (int i = 0; i < bbw.Ask.GetLength(0); i++) { ask_amount += bbw.Ask[i, 1]; } bbw.Ask_amount = ask_amount; bbw.Ask_quantity = ask_amount / bbw.Ask.GetLength(0); double bid_amount = 0.0; for (int i = 0; i < bbw.Bid.GetLength(0); i++) { bid_amount += bbw.Bid[i, 1]; } bbw.Bid_amount = bid_amount; bbw.Bid_quantity = bid_amount / bbw.Bid.GetLength(0); rezalt.Add(bbw); } } return(rezalt); }
public List <BaseBookWarrant> GetBookWarrants(List <BaseCurrencyPair> pairs, int limit) { if (pairs.Count > 1) { LastErrorInfo = "Suport only one pairs"; return(new List <BaseBookWarrant>()); } WebConector wc = new WebConector(); string api_name = "public/Depth?pair="; foreach (ICurrencyPair pair in pairs) { api_name += pair.PairName; } if (limit > 0 && limit <= 1000) { api_name += "&count=" + limit.ToString(); } string jsonRezalt = wc.ReqwestGetAsync(string.Format(base_url, api_name), new List <Tuple <string, string> >(), "").Result; var jsonRezaltArray = JObject.Parse(jsonRezalt); var books_json = JObject.Parse(jsonRezaltArray["result"].ToString()); List <BaseBookWarrant> rezalt = new List <BaseBookWarrant>(); if (books_json.Count > 0) { foreach (ICurrencyPair cp in pairs) { JToken jwarant = books_json[cp.PairName]; var jasks = JArray.Parse(jwarant["asks"].ToString()); var jbids = JArray.Parse(jwarant["bids"].ToString()); BaseBookWarrant bookWarrant = new BaseBookWarrant(); bookWarrant.Name = cp.PairName; bookWarrant.Ask = JArray.Parse(jasks.ToString()).ToObject <double[, ]>(); bookWarrant.Bid = JArray.Parse(jbids.ToString()).ToObject <double[, ]>(); rezalt.Add(bookWarrant); } } return(rezalt); }
// public List <BaseBookWarrant> GetBookWarrants(List <BaseCurrencyPair> pairs, int limit) { //if (pairs.Count > 1) //{ // LastErrorInfo = "Suport only one pairs"; // return new List<BaseBookWarrant>(); //} WebConector wc = new WebConector(); List <BaseBookWarrant> rezalt = new List <BaseBookWarrant>(); foreach (ICurrencyPair pair in pairs) { string api_name = "book/"; api_name += pair.PairName; api_name += "/P0"; if (limit == 25 || limit == 100) { api_name += "?len=" + limit.ToString(); } string jsonRezalt = wc.ReqwestGetAsync(string.Format(base_url, api_name), new List <Tuple <string, string> >(), "").Result; var jsonRezaltArray = JArray.Parse(jsonRezalt); if (jsonRezaltArray.Count > 0) { foreach (var cp in jsonRezaltArray) { BaseBookWarrant bookWarrant = new BaseBookWarrant(); bookWarrant.Name = pairs.First().PairName; var buff = JArray.Parse(cp.ToString()).ToObject <double[]>(); bookWarrant.Ask_amount = buff[2]; bookWarrant.Ask_quantity = buff[1]; bookWarrant.Ask_top = buff[0]; rezalt.Add(bookWarrant); } } } return(rezalt); }
public List <BaseBookWarrant> GetBookWarrants(List <BaseCurrencyPair> pairs, int limit) { WebConector wc = new WebConector(); string api_name = "order_book/?pair="; foreach (ICurrencyPair pair in pairs) { api_name += pair.PairName + ","; } if (limit > 0 && limit <= 1000) { api_name += "&limit=" + limit.ToString(); } string jsonRezalt = wc.ReqwestGetAsync(string.Format(base_url, api_name), new List <Tuple <string, string> >(), "").Result; var jsonRezaltArray = JObject.Parse(jsonRezalt); List <BaseBookWarrant> rezalt = new List <BaseBookWarrant>(); if (jsonRezaltArray.Count > 0) { foreach (ICurrencyPair cp in pairs) { BaseBookWarrant bookWarrant = new BaseBookWarrant(); bookWarrant.Name = cp.PairName; JToken jwarant = jsonRezaltArray[cp.PairName]; bookWarrant.Ask_quantity = (double)jwarant["ask_quantity"]; bookWarrant.Ask_amount = (double)jwarant["ask_amount"]; bookWarrant.Ask_top = (double)jwarant["ask_top"]; bookWarrant.Bid_quantity = (double)jwarant["bid_quantity"]; bookWarrant.Bid_amount = (double)jwarant["bid_amount"]; bookWarrant.Bid_top = (double)jwarant["bid_top"]; bookWarrant.Ask = JArray.Parse(jwarant["ask"].ToString()).ToObject <double[, ]>(); bookWarrant.Bid = JArray.Parse(jwarant["bid"].ToString()).ToObject <double[, ]>(); rezalt.Add(bookWarrant); } } return(rezalt); }