AMONRA75 (OP)
|
|
August 19, 2016, 04:00:03 PM Last edit: August 19, 2016, 05:02:36 PM by AMONRA75 |
|
hi, i need an help to connect to poloniex api (non public) with c# anyone can help me const string WEBSERVICE_URL = "https://poloniex.com/tradingApi"; try { var webRequest = System.Net.WebRequest.Create(WEBSERVICE_URL); if (webRequest != null) { webRequest.Method = "POST"; webRequest.Timeout = 12000; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.Headers.Add("Key", _apiKey); webRequest.Headers.Add("Sign", CreateSignature()); webRequest.Headers.Add("command", "returnDepositAddresses");
using (System.IO.Stream s = webRequest.GetResponse().GetResponseStream()) { using (System.IO.StreamReader sr = new System.IO.StreamReader(s)) { var jsonResponse = sr.ReadToEnd(); Console.WriteLine(String.Format("Response: {0}", jsonResponse)); } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); }
i see the error "Response: {"error":"Invalid command."}"
tnx a lot!
|
|
|
|
Coding Enthusiast
Legendary
Offline
Activity: 1039
Merit: 2783
Bitcoin and C♯ Enthusiast
|
|
August 19, 2016, 05:44:24 PM |
|
this header is extra webRequest.Headers.Add("command", "returnDepositAddresses"); i have WebRequest class you should put the "command" and "returnDepositAddresses" in httpcontent and sign that, then add the signature to the header "sign" i have no idea what you are doing here: webRequest.Headers.Add("Sign", CreateSignature()); what does that function sign without having any input variable?
PHP is the closest example you can see and kind of understand when using c# IMO: http://pastebin.com/iuezwGRZ (see line 28 and 29)
|
|
|
|
AMONRA75 (OP)
|
|
August 19, 2016, 10:39:06 PM |
|
i write the complete code private readonly string _apiKey = "N68R67PJ-BZ89CNWB-O2UOOH59-YYFSX9MB"; // Random numbers and letters private readonly string _apiSecret = "345eaefc0bf5fbb5a048de7f8dc728646b61249f9c8fd9c1a99319e3ed0d55a6b8e43702cea379b2d136fe9b877f132706ceebc2930b220322b23a207151ea78"; private long nonce = DateTime.Now.Ticks;
private string CreateSignature() { //string msg = string.Format("{0}{1}{2}", _apiKey);
return ByteArrayToString(SignHMACSHA512(_apiSecret, StringToByteArray(_apiKey))).ToUpper(); }
private static byte[] SignHMACSHA512(String key, byte[] data) { HMACSHA512 hashMaker = new HMACSHA512(Encoding.ASCII.GetBytes(key)); return hashMaker.ComputeHash(data); }
private static byte[] StringToByteArray(string str) { return System.Text.Encoding.ASCII.GetBytes(str); }
private static string ByteArrayToString(byte[] hash) //rimuove - e converte in bite { return BitConverter.ToString(hash).Replace("-", "").ToLower(); }
private void button5_Click(object sender, EventArgs e) {
const string WEBSERVICE_URL = "https://poloniex.com/tradingApi"; try {
var webRequest = System.Net.WebRequest.Create(WEBSERVICE_URL); if (webRequest != null) { webRequest.Method = "POST"; webRequest.Timeout = 12000; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.Headers.Add("Key", _apiKey); webRequest.Headers.Add("Sign", CreateSignature()); // keysecret var postData = "&nonce=&command=returnBalances"; var data = Encoding.ASCII.GetBytes(postData);
using (System.IO.Stream s = webRequest.GetResponse().GetResponseStream()) { using (System.IO.StreamReader sr = new System.IO.StreamReader(s)) { var jsonResponse = sr.ReadToEnd(); Console.WriteLine(String.Format("Response: {0}", jsonResponse)); } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); }
i have remove the extra headers but see the error
|
|
|
|
|
starmman
Legendary
Offline
Activity: 1484
Merit: 1029
|
|
February 17, 2017, 08:53:05 PM |
|
Thanks for sharing that link - you saved me a lot of time getting the signature generated, first API I tried since Cryptsy - seems line every API has its quirks.
|
|
|
|
Coding Enthusiast
Legendary
Offline
Activity: 1039
Merit: 2783
Bitcoin and C♯ Enthusiast
|
|
February 18, 2017, 05:18:58 AM |
|
Glad I could help ^^
|
|
|
|
Luser
Newbie
Offline
Activity: 1
Merit: 0
|
|
June 04, 2017, 05:05:47 PM |
|
Coding Enthusiast, I registered on this site only so I could say thank you for posting this! Dang, I would have been stuck for days on this, so thanks a big bunch to you!
Now I can proceed in automatically losing my altcoins instead of having to throw them away manually! =)
Best regards Luser
PS. Thanks to Amonra75 too for asking, of course. The web is truly awesome at times!
|
|
|
|
Coding Enthusiast
Legendary
Offline
Activity: 1039
Merit: 2783
Bitcoin and C♯ Enthusiast
|
|
June 06, 2017, 03:40:31 AM |
|
I am glad that this code is still helping people
|
|
|
|
matscol
Newbie
Offline
Activity: 49
Merit: 0
|
|
July 21, 2017, 11:26:54 PM |
|
I'll add my thanks. This helped set up CB/GDAX api access as well.
|
|
|
|
SomeOneMore
Newbie
Offline
Activity: 4
Merit: 0
|
|
January 05, 2018, 05:41:50 PM |
|
can you please put the code for call the command "returnOpenOrders"?
"Returns your open orders for a given market, specified by the "currencyPair" POST parameter, e.g. "BTC_XCP". Set "currencyPair" to "all" to return open orders for all markets. Sample output for single market:"
Thanks in advance
|
|
|
|
Coding Enthusiast
Legendary
Offline
Activity: 1039
Merit: 2783
Bitcoin and C♯ Enthusiast
|
|
January 06, 2018, 05:59:21 PM |
|
Just change line #6 command from "returnBalances" to "returnOpenOrders" and add an optional parameter after it and before nonce, "¤cyPair=BTC_XCP". It should work. I don't have a poloniex account anymore to test it.
|
|
|
|
SomeOneMore
Newbie
Offline
Activity: 4
Merit: 0
|
|
January 06, 2018, 09:30:13 PM |
|
Just change line #6 command from "returnBalances" to "returnOpenOrders" and add an optional parameter after it and before nonce, "¤cyPair=BTC_XCP". It should work. I don't have a poloniex account anymore to test it.
it works. thanks
|
|
|
|
|