-
-
Save Coding-Enthusiast/863f46ceef57ff2e1cf18adb8b34d926 to your computer and use it in GitHub Desktop.
Polo API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change line 6 to