public bool eliminaOrden(string sMoneda, string sOid) { bool bregresa = false; // string APIKEY = "JkkXaYKKDo"; string API_SECRET = "578d14362dd2d68d05cb4dd0b2a92012";// Bitso_Trading string SIGNATURE = string.Empty; string AUTH_HEADER = string.Empty; string MESSAGE = string.Empty; string REQUESTPATH = "";// "/v3/orders/"; string sURL = string.Format(@"https://api.bitso.com/api/v3/orders/{0}", sOid); string DNONCE = Convert.ToInt64(new TimeSpan(DateTime.UtcNow.Ticks).TotalMilliseconds).ToString(); string JSONPayload = ""; // JsonConvert.SerializeObject(buym); //Dataos obtenido de una clase que al momento de la instancia se pasan los parametros. MESSAGE = DNONCE + REQUESTPATH + JSONPayload; ASCIIEncoding encoder = new ASCIIEncoding(); HMACSHA256 hmSha256 = new HMACSHA256(encoder.GetBytes(API_SECRET)); byte[] hm256Byte = hmSha256.ComputeHash(encoder.GetBytes(MESSAGE)); SIGNATURE = ToHexString(hm256Byte); AUTH_HEADER = "Bitso " + APIKEY + ":" + DNONCE + ":" + SIGNATURE; CResTradingjson resTrading = null; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sURL); request.Method = "DELETE"; request.Headers.Add("Authorization", AUTH_HEADER); request.ContentType = "application/json"; //request.Accept = "application/json"; var httpResponse = (HttpWebResponse)request.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); resTrading = JsonConvert.DeserializeObject <CResTradingjson>(result); if (resTrading.success) { Dictionary <bool, string> res = new Dictionary <bool, string>(); } //MessageBox.Show("Resultado del Treadin: \n" + result ); } } catch (WebException e) { using (WebResponse response = e.Response) { HttpWebResponse httpResponse = (HttpWebResponse)response; //Console.WriteLine("Error code: {0}", httpResponse.StatusCode); using (Stream data = response.GetResponseStream()) using (var reader = new StreamReader(data)) { string text = reader.ReadToEnd(); MessageBox.Show(text + " : " + httpResponse.StatusCode); } } } catch (Exception ex) { MessageBox.Show("Ocurrio un error: " + ex.Message); } return(bregresa); }
public CMoney_Trading_oid bitsoTrading(string sMoneda) { //bool bRegresa = false; //string APIKEY = "jGahwvgWpc"; string APIKEY = "JkkXaYKKDo"; //string API_SECRET = "f3ed245422cafaab020059a0f78e37fc"; string API_SECRET = "578d14362dd2d68d05cb4dd0b2a92012";// Bitso_Trading string SIGNATURE = string.Empty; string AUTH_HEADER = string.Empty; string MESSAGE = string.Empty; string REQUESTPATH = "/v3/orders/"; string sURL = @"https://api.bitso.com/v3/orders/"; string DNONCE = Convert.ToInt64(new TimeSpan(DateTime.UtcNow.Ticks).TotalMilliseconds).ToString(); //string DNONCE = (CurrentUnixTimeMillis()).ToString(); string JSONPayload = JsonConvert.SerializeObject(buym); // string json = @"{ // 'book': 'xrp_mxn', // 'side': 'buy', // 'major': '1', // 'price': '19', // 'type': 'limit'}"; //string JSONPayload = JsonConvert.SerializeObject(json); //Dataos obtenido de una clase que al momento de la instancia se pasan los parametros. MESSAGE = DNONCE + "POST" + REQUESTPATH + JSONPayload; ASCIIEncoding encoder = new ASCIIEncoding(); HMACSHA256 hmSha256 = new HMACSHA256(encoder.GetBytes(API_SECRET)); byte[] hm256Byte = hmSha256.ComputeHash(encoder.GetBytes(MESSAGE)); SIGNATURE = ToHexString(hm256Byte); AUTH_HEADER = "Bitso " + APIKEY + ":" + DNONCE + ":" + SIGNATURE; CResTradingjson resTrading = null; CMoney_Trading_oid moneyResult = new CMoney_Trading_oid(); try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sURL); request.Method = "POST"; request.Headers.Add("Authorization", AUTH_HEADER); request.ContentType = "application/json"; //request.ContentType = "application/json; charset=UTF-8"; request.Accept = "application/json"; //request.ProtocolVersion = HttpVersion.Version11; /// ejemplo 2 using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(JSONPayload); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)request.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); resTrading = JsonConvert.DeserializeObject <CResTradingjson>(result); if (resTrading.success) { moneyResult.moneda = sMoneda; moneyResult.oid = resTrading.payload.oid; } //MessageBox.Show("Resultado del Treadin: \n" + result ); } //aqui termina ejemplo 2 } catch (WebException e) { using (WebResponse response = e.Response) { HttpWebResponse httpResponse = (HttpWebResponse)response; //Console.WriteLine("Error code: {0}", httpResponse.StatusCode); using (Stream data = response.GetResponseStream()) using (var reader = new StreamReader(data)) { string text = reader.ReadToEnd(); MessageBox.Show(text + " : " + httpResponse.StatusCode); } } } catch (Exception ex) { MessageBox.Show("Ocurrio un error: " + ex.Message); } return(moneyResult); }