Witam Wszystkich!
Jestem w trakcie pisania aplikacji bazującej na REST API udostępnionym przez giełdę BitBay.net
Przy próbie złożenia nowej oferty zakupu na giełdzie otrzymuję zwrotkę:
Result: StatusCode: 415, ReasonPhrase: 'Unsupported Media Type',
Poniżej fragment kodu:
static void Main(string[] args)
{
string timestamp = DateTime.Now.ToString("yyyyMMddHHmmssffff");
string APIKey = "";
string PrivateAPIKey = "";
string APIHash = GenerateHash(PrivateAPIKey, APIKey, timestamp);
var request = SendRequest(APIKey, APIHash, timestamp);
Console.WriteLine("Status: " + request.Status);
Console.WriteLine("Result: " + request.Result);
Console.ReadLine();
}
static string GenerateHash(string privateKey, string apiKey, string timestamp)
{
try
{
StringBuilder _stringBuilder = new StringBuilder();
byte[] privateBytes = Encoding.UTF8.GetBytes(privateKey);
byte[] bytes = Encoding.UTF8.GetBytes(apiKey + timestamp);
using (HMACSHA512 _hmac = new HMACSHA512(privateBytes))
{
byte[] hash = _hmac.ComputeHash(bytes);
foreach (byte b in hash)
{
_stringBuilder.Append(b.ToString("X2"));
}
}
return _stringBuilder.ToString();
}
catch (Exception ex)
{
return ex.ToString();
}
}
static async Task<HttpResponseMessage> SendRequest(string apiKey, string apiHash, string timestamp)
{
try
{
HttpClient client = new HttpClient();
var values = new Dictionary<string, string>
{
{"API-Key", apiKey},
{"API-Hash", apiHash},
{"operation-id", Guid.NewGuid().ToString() },
{"Request-Timestamp", timestamp},
{"Content-Type","application/json"},
{"Body","{amount:0.45,rate:23000,offerType:sell,mode:limit,postOnly:false,fillOrKill:false}"}
};
var content = new FormUrlEncodedContent(values);
return await client.PostAsync("https://api.bitbay.net/rest/trading/offer/BTC-PLN", content);
}
catch (Exception ex)
{
return null;
}
}
Dodam, że podczas prób wywołania metod "GET", które również wymagają autoryzacji wszystko przebiega bez kłopotu.
Z góry dziękuję za pomoc. Pozdrawiam,
Michał.