首页 / C# / HitBTC api POST请求,C#
HitBTC api POST请求,C#
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了HitBTC api POST请求,C#,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2190字,纯文字阅读大概需要4分钟。
内容图文
![HitBTC api POST请求,C#](/upload/InfoBanner/zyjiaocheng/797/ec5274b33ee94b31b041ec485e3da870.jpg)
我知道如何执行GET请求,但POST不起作用:
public string Order()
{
var client = new RestClient("http://api.hitbtc.com");
var request = new RestRequest("/api/2/order", Method.POST);
request.AddQueryParameter("nonce", GetNonce().ToString());
request.AddQueryParameter("apikey", HapiKey);
// request.AddParameter("clientOrderId", "");
request.AddParameter("symbol", "BCNUSD");
request.AddParameter("side", "sell");
request.AddParameter("quantity", "10");
request.AddParameter("type", "market");
var body = string.Join("&", request.Parameters.Where(x => x.Type == ParameterType.GetOrPost));
string sign = CalculateSignature(client.BuildUri(request).PathAndQuery + body, HapiSecret);
request.AddHeader("X-Signature", sign);
var response = client.Execute(request);
return response.Content;
}
private static long GetNonce()
{
return DateTime.Now.Ticks * 10;
}
public static string CalculateSignature(string text, string secretKey)
{
using (var hmacsha512 = new HMACSHA512(Encoding.UTF8.GetBytes(secretKey)))
{
hmacsha512.ComputeHash(Encoding.UTF8.GetBytes(text));
return string.Concat(hmacsha512.Hash.Select(b => b.ToString("x2")).ToArray());
}
}
错误:代码:1001,“需要授权”.
我的失败在哪里?对于v2,“apikey”和“X-Signature”不正确吗?
非常感谢你帮助我!
解决方法:
请查看身份验证documentation.
您需要使用公钥和私钥使用基本身份验证.
RestSharp的示例:
var client = new RestClient("https://api.hitbtc.com")
{
Authenticator = new HttpBasicAuthenticator(<PublicKey>, <SecretKey>)
};
要创建API密钥,您需要访问设置页面.
此外,对于您的API操作,您需要将“放置/取消订单”权限设置为true.
截图详情:
这里还有完整的代码,对我很有用:
var client = new RestClient("https://api.hitbtc.com")
{
Authenticator = new HttpBasicAuthenticator(PublicKey, SecretKey)
};
var request = new RestRequest("/api/2/order", Method.POST)
{
RequestFormat = DataFormat.Json
};
request.AddParameter("symbol", "BCNUSD");
request.AddParameter("side", "sell");
request.AddParameter("quantity", "10");
request.AddParameter("type", "market");
request.AddParameter("timeInForce", "IOC");
var response = client.Execute(request);
if (!response.IsSuccessful)
{
var message = $"REQUEST ERROR (Status Code: {response.StatusCode}; Content: {response.Content})";
throw new Exception(message);
}
内容总结
以上是互联网集市为您收集整理的HitBTC api POST请求,C#全部内容,希望文章能够帮你解决HitBTC api POST请求,C#所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。