Skip to content

Instantly share code, notes, and snippets.

@Coding-Enthusiast
Created August 21, 2016 15:33
Show Gist options
  • Save Coding-Enthusiast/863f46ceef57ff2e1cf18adb8b34d926 to your computer and use it in GitHub Desktop.
Save Coding-Enthusiast/863f46ceef57ff2e1cf18adb8b34d926 to your computer and use it in GitHub Desktop.
Polo API
const string ApiKey = "YourAPIKey";
const string ApiSecret = "YourAPISecret";
public async void MyFunc()
{
string url = "https://poloniex.com/tradingApi";
string myParam = "command=returnBalances&nonce=" + nonce();
string result = await SendPrivateApiRequestAsync(url, myParam);
//deserialize the result string to your liking
}
private async Task<string> SendPrivateApiRequestAsync(string privUrl, string myParam)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(privUrl);
StringContent myContent = new StringContent(myParam);
myContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
client.DefaultRequestHeaders.Add("Key", ApiKey);
client.DefaultRequestHeaders.Add("Sign", genHMAC(myParam));
var result = await client.PostAsync(privUrl, myContent);
return await result.Content.ReadAsStringAsync();
}
}
private string genHMAC(string message)
{
var hmac = new HMACSHA512(Encoding.ASCII.GetBytes(ApiSecret));
var messagebyte = Encoding.ASCII.GetBytes(message);
var hashmessage = hmac.ComputeHash(messagebyte);
var sign = BitConverter.ToString(hashmessage).Replace("-", "").ToLower();
return sign;
}
@Coding-Enthusiast
Copy link
Author

Coding-Enthusiast commented Jan 6, 2018

Change line 6 to

string myParam = "command=returnOpenOrders&currencyPair=BTC_XCP&nonce=" + nonce();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment