Author

Topic: C#AND POLONIEX API CONNECT (Read 3162 times)

newbie
Activity: 4
Merit: 0
January 06, 2018, 04:30:13 PM
#12
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
legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
January 06, 2018, 12:59:21 PM
#11
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.
newbie
Activity: 4
Merit: 0
January 05, 2018, 12:41:50 PM
#10
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
newbie
Activity: 49
Merit: 0
July 21, 2017, 06:26:54 PM
#9
I'll add my thanks. This helped set up CB/GDAX api access as well.
legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
June 05, 2017, 10:40:31 PM
#8
I am glad that this code is still helping people Smiley
newbie
Activity: 1
Merit: 0
June 04, 2017, 12:05:47 PM
#7
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!
legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
February 18, 2017, 12:18:58 AM
#6
Glad I could help ^^
legendary
Activity: 1484
Merit: 1029
February 17, 2017, 03:53:05 PM
#5
as i said i hate WebRequest it is too long Cheesy

but here i made you a complete code for it using HttpClient only in 30 lines
https://gist.github.com/Coding-Enthusiast/863f46ceef57ff2e1cf18adb8b34d926

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.
legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
August 21, 2016, 10:34:38 AM
#4
as i said i hate WebRequest it is too long Cheesy

but here i made you a complete code for it using HttpClient only in 30 lines
https://gist.github.com/Coding-Enthusiast/863f46ceef57ff2e1cf18adb8b34d926
full member
Activity: 148
Merit: 100
August 19, 2016, 05:39:06 PM
#3
i write the complete code

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
legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
August 19, 2016, 12:44:24 PM
#2
this header is extra
Code:
webRequest.Headers.Add("command", "returnDepositAddresses");

i have WebRequest class Cheesy

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:
Code:
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)
full member
Activity: 148
Merit: 100
August 19, 2016, 11:00:03 AM
#1
hi,

i need an help to connect to poloniex api (non public) with c#
anyone can help me Huh




Code:
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

Code:

"Response: {"error":"Invalid command."}"

tnx a lot!
Jump to: