public bool CanselOrder(BaseCurrencyPair cp, int order_id) { if (Username == null || Password == null) { LastErrorInfo = "Not Autorizated"; return(false); } WebConector wc = new WebConector(); string api_name = "/api/v3/order"; List <Tuple <string, string> > heder = new List <Tuple <string, string> >(); var jsontimestamp = wc.ReqwestGetAsync(string.Format("{0}/api/v3/time", base_url), new List <Tuple <string, string> >(), "").Result; string timestamp = (JObject.Parse(jsontimestamp))["serverTime"].ToString(); heder.Add(new Tuple <string, string>("X-MBX-APIKEY", Username)); string data_for_encript = "symbol=" + cp.PairName + "&orderId=" + order_id + "×tamp=" + timestamp; heder.Add(new Tuple <string, string>("signature", SignatureHelper.Sign(Password, data_for_encript, 256))); data_for_encript += "&signature=" + SignatureHelper.Sign(Password, data_for_encript, 256); string jsonRezalt = wc.ReqwestDeleteAsync(string.Format("{0}{1}", base_url, api_name), heder, data_for_encript).Result; var jsonRezaltArray = JObject.Parse(jsonRezalt); if (jsonRezaltArray["msg"] == null) { LastErrorInfo = ""; return(true); } else { LastErrorInfo = jsonRezaltArray["msg"].ToString(); return(false); } }
public List <BaseOrder> GetOrdersHistory(BaseCurrencyPair currencyPair, int top_count = 100) { if (Username == null || Password == null) { LastErrorInfo = "Not Autorizated"; return(new List <BaseOrder>()); } if (top_count > 1000) { top_count = 1000; } WebConector wc = new WebConector(); string api_name = "/api/v3/allOrders"; List <Tuple <string, string> > heder = new List <Tuple <string, string> >(); var jsontimestamp = wc.ReqwestGetAsync(string.Format("{0}/api/v3/time", base_url), new List <Tuple <string, string> >(), "").Result; string timestamp = (JObject.Parse(jsontimestamp))["serverTime"].ToString(); heder.Add(new Tuple <string, string>("X-MBX-APIKEY", Username)); string data_for_encript = "symbol=" + currencyPair.PairName + "&limit=" + top_count + "&recvWindow=" + "50000" + "×tamp=" + timestamp; heder.Add(new Tuple <string, string>("signature", SignatureHelper.Sign(Password, data_for_encript, 256))); data_for_encript += "&signature=" + SignatureHelper.Sign(Password, data_for_encript, 256); string jsonRezalt = wc.ReqwestPostAsync(string.Format("{0}{1}", base_url, api_name), heder, data_for_encript).Result; try { var jsonRezaltArray = JArray.Parse(jsonRezalt); LastErrorInfo = ""; var rezalt = new List <BaseOrder>(); foreach (var order in jsonRezaltArray) { BaseOrder bo = new BaseOrder(); bo.Id = order["orderId"].ToObject <int>(); bo.Pair = new BaseCurrencyPair(order["symbol"].ToString()); bo.Quantity = order["origQty"].ToObject <double>(); bo.Price = order["price"].ToObject <double>(); bo.Type = BinanceOrderType.SetValue(order["type"].ToString()); bo.Amount = order["executedQty"].ToObject <int>(); rezalt.Add(bo); } return(rezalt); } catch (Exception ex) { LastErrorInfo = jsonRezalt; return(new List <BaseOrder>()); } }
public List <BaseOrder> GetOrdersHistory(BaseCurrencyPair currencyPair, int top_count = 100) { if (Username == null || Password == null) { LastErrorInfo = "Not Authenticated"; return(new List <BaseOrder>()); } WebConector wc = new WebConector(); string api_name = "user_cancelled_orders"; List <Tuple <string, string> > heder = new List <Tuple <string, string> >(); string nonce = ((long)(DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds).ToString(); heder.Add(new Tuple <string, string>("Key", Username)); string data_for_encript = "limit=" + top_count + "&" + "nonce=" + nonce; heder.Add(new Tuple <string, string>("Sign", SignatureHelper.Sign(Password, data_for_encript))); var body = new NameValueCollection(); body.Add("limit", top_count.ToString()); body.Add("nonce", nonce); string jsonRezalt = wc.ReqwestPostAsync(string.Format(base_url, api_name), heder, body).Result; var jsonRezaltArray = JArray.Parse(jsonRezalt); if (jsonRezaltArray.Count != 0) { List <BaseOrder> rezaltlist = new List <BaseOrder>(); foreach (JObject record in jsonRezaltArray.Children <JObject>()) { BaseOrder bhr = new BaseOrder(); bhr.Id = int.Parse(record["order_id"].ToString()); bhr.Type = BaseOrderType.SetValue(record["order_type"].ToString()); bhr.Pair = new BaseCurrencyPair(record["pair"].ToString()); bhr.Price = double.Parse(record["price"].ToString()); bhr.Quantity = double.Parse(record["quantity"].ToString()); bhr.Amount = double.Parse(record["amount"].ToString()); rezaltlist.Add(bhr); } LastErrorInfo = ""; return(rezaltlist); } else { return(new List <BaseOrder>()); } }
public List <BaseCurrencyPair> GetCurrencyPair() { WebConector wc = new WebConector(); string api_name = "pair_settings/"; string jsonRezalt = wc.ReqwestGetAsync(string.Format(base_url, api_name), new List <Tuple <string, string> >(), "").Result; var jsonRezaltArray = JObject.Parse(jsonRezalt); List <BaseCurrencyPair> rezalt = new List <BaseCurrencyPair>(); if (jsonRezaltArray.Count > 0) { foreach (var cp_json in jsonRezaltArray) { BaseCurrencyPair cp = new BaseCurrencyPair(cp_json.Key); rezalt.Add(cp); } } return(rezalt); }
public List <BaseCurrencyPair> GetCurrencyPair() { WebConector wc = new WebConector(); string api_name = "/api/v3/ticker/price"; string jsonRezalt = wc.ReqwestGetAsync(string.Format("{0}{1}", base_url, api_name), new List <Tuple <string, string> >(), "").Result; var jsonRezaltArray = JArray.Parse(jsonRezalt); List <BaseCurrencyPair> rezalt = new List <BaseCurrencyPair>(); if (jsonRezaltArray.Count > 0) { foreach (var cp_json in jsonRezaltArray) { BaseCurrencyPair cp = new BaseCurrencyPair(cp_json["symbol"].ToString()); rezalt.Add(cp); } } return(rezalt); }
// public List <BaseCurrencyPair> GetCurrencyPair() { WebConector wc = new WebConector(); string api_name = "/conf/pub:list:pair:exchange"; string jsonRezalt = wc.ReqwestGetAsync(string.Format(base_url, api_name), new List <Tuple <string, string> >(), "").Result; var jsonRezaltArray = JArray.Parse(jsonRezalt); List <BaseCurrencyPair> rezalt = new List <BaseCurrencyPair>(); if (jsonRezaltArray.Count > 0) { foreach (var cp_json in jsonRezaltArray) { foreach (var cp_j in JArray.Parse(cp_json.ToString())) { BaseCurrencyPair cp = new BaseCurrencyPair(cp_j.ToString()); rezalt.Add(cp); } } } return(rezalt); }
public List <BaseOrder> GetOrdersHistory(BaseCurrencyPair currencyPair, int top_count = -1) { throw new NotImplementedException(); }
List <BaseOrder> ICryptoExchenge.GetOrdersHistory(BaseCurrencyPair currencyPair, int top_count) { return(GetOrdersHistory(currencyPair, top_count).Cast <BaseOrder>().ToList()); }
public List <KrakenOrder> GetOrdersHistory(BaseCurrencyPair currencyPair, int top_count = -1) { if (Username == null || Password == null) { LastErrorInfo = "Not Autorizated"; return(null); } List <KrakenOrder> rezalt = new List <KrakenOrder>(); WebConector wc = new WebConector(); string api_name = "private/OpenOrders"; Int64 nonce = DateTime.Now.Ticks; string data_transmit = string.Format("nonce={0}", nonce); var signature = SignatureFormat(api_name, data_transmit, nonce); List <Tuple <string, string> > heder = new List <Tuple <string, string> >(); heder.Add(new Tuple <string, string>("API-Key", Username)); heder.Add(new Tuple <string, string>("API-Sign", signature)); var jsonRezalt = wc.ReqwestPostAsync(string.Format(base_url, api_name), heder, data_transmit).Result; var jsonRezaltArray = JArray.Parse(jsonRezalt); if (jsonRezaltArray["error"] == null) { LastErrorInfo = ""; foreach (JObject record in jsonRezaltArray.Children <JObject>()) { KrakenOrder ko = new KrakenOrder(); BaseOrderStatus os = BaseOrderStatus.Exsist; os.Value = record["order_id"].ToString().FirstCharToUpper(); ko.Status = os; ko.Pair = new BaseCurrencyPair(record["descr"]["pair"].ToString()); ko.Type = KrakenOrderType.SetValue(record["descr"]["type"].ToString().FirstCharToUpper()); ko.Ordertype = KrakenOrderType.SetValue(record["descr"]["ordertype"].ToString().FirstCharToUpper()); ko.Price = double.Parse(record["descr"]["price"].ToString()); ko.Quantity = double.Parse(record["vol"].ToString()); ko.OpenTm = UnixTimestampToDateTime(double.Parse(record["opentm "].ToString())); rezalt.Add(ko); } } else { LastErrorInfo = jsonRezaltArray["error"].ToString(); } api_name = "private/OpenOrders"; nonce = DateTime.Now.Ticks; data_transmit = string.Format("nonce={0}", nonce); signature = SignatureFormat(api_name, data_transmit, nonce); heder = new List <Tuple <string, string> >(); heder.Add(new Tuple <string, string>("API-Key", Username)); heder.Add(new Tuple <string, string>("API-Sign", signature)); jsonRezalt = wc.ReqwestPostAsync(string.Format(base_url, api_name), heder, data_transmit).Result; jsonRezaltArray = JArray.Parse(jsonRezalt); if (jsonRezaltArray["error"] == null) { foreach (JObject record in jsonRezaltArray.Children <JObject>()) { KrakenOrder ko = new KrakenOrder(); BaseOrderStatus os = BaseOrderStatus.Exsist; os.Value = record["order_id"].ToString().FirstCharToUpper(); ko.Status = os; ko.Pair = new BaseCurrencyPair(record["descr"]["pair"].ToString()); ko.Type = KrakenOrderType.SetValue(record["descr"]["type"].ToString().FirstCharToUpper()); ko.Ordertype = KrakenOrderType.SetValue(record["descr"]["ordertype"].ToString().FirstCharToUpper()); ko.Price = double.Parse(record["descr"]["price"].ToString()); ko.Quantity = double.Parse(record["vol"].ToString()); ko.Amount = double.Parse(record["count"].ToString()); ko.OpenTm = UnixTimestampToDateTime(double.Parse(record["opentm "].ToString())); rezalt.Add(ko); } } else { LastErrorInfo += jsonRezaltArray["error"].ToString(); } rezalt = rezalt.Where(x => x.Pair.PairName == currencyPair.PairName).ToList(); rezalt.OrderBy(x => x.OpenTm); return((top_count > 0)?rezalt.Take(top_count).ToList():rezalt); }