我正在尝试在 Binance 上下订单。
根据文档做所有事情 文档链接
代码 :
public void PlaceOrder(string baseCurrency, string quoteCurrency, OrderType orderType, decimal quantity, decimal price, OrderSubType orderSubType)
{
string timestamp = GetTimestamp().ToString();
string assetPair = baseCurrency.ToUpper() + quoteCurrency.ToUpper();
string orderSubTypeId = "";
if (orderSubType == OrderSubType.LimitOrder)
{
orderSubTypeId = "LIMIT";
}
if (orderSubType == OrderSubType.MarketOrder)
{
orderSubTypeId = "MARKET";
}
string type = "";
if (orderType == OrderType.Sell)
{
type = "SELL";
}
else
{
type = "BUY";
}
string paramString = String.Format(
"symbol={0}&side={1}&type={2}&quantity={3}&recvWindow=60000×tamp={4}",
assetPair, type, orderSubTypeId, quantity.ToString(), timestamp);
string signature = Encode(paramString, secretKey);
string url = string.Format("https://api.binance.com/api/v3/order?{0}&signature={1}", paramString, signature);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("X-MBX-APIKEY", apiKey);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = WebRequestMethods.Http.Post;
}
字符串 url 是正确的。因为,我将它复制粘贴到 URL 中并且运行 curl 命令有效。
卷曲:
curl -H "X-MBX-APIKEY: API_KEY_GOES_HERE" -X POST " https://api.binance.com/api/v3/order?symbol=ETHUSDT&side=SELL&type=MARKET&quantity=0.10000000&recvWindow=60000×tamp=1583924648428&signature=SIGNATURE_GOES_HERE (签名是正确的,我检查了它)”
传递给方法的参数是正确的,因为代码中的 url 字符串是正确的。请求本身有问题。