我尝试使用仅给出订单符号的 formData 发送取消订单请求。但不幸的是,所有其他订单也从交易所中删除。我添加到请求中的 formData 似乎不起作用。
在 Dart 语言中,有没有人知道使用 formData 向服务器发送取消请求的正确方法是什么?
非常感谢你。
我花了将近 2 天的时间才弄清楚这一点:) 有一天,希望对像我这样需要的人有用..
这是我向 bitmex 发送取消订单的解决方案......用飞镖语言。
您还可以使用此代码创建有效的签名和身份验证..
干杯
var verb = "DELETE";
var path = "/api/v1/order";
var query = "orderID=$ordID";
if (query != "") path = path + "?" + query;
return await bitmexHttpService.authRequest(verb: verb, path: path);
Future<String> authRequest({String verb, String path, String data = ""}) async {
var _nonce = ((DateTime.now()).microsecondsSinceEpoch).toInt();
var _signature = signature(apiSecret, verb, path, _nonce);
var headerWithAuthCredentials = createHeader(verb, _nonce, _signature);
http.Response response;
try {
if (verb == "GET")
response = await http.get(baseUrl + path, headers: headerWithAuthCredentials);
else if (verb == "POST")
response = await http.post(baseUrl + path, body: data, headers: headerWithAuthCredentials);
else if (verb == "DELETE") {
response = await http.delete(baseUrl + path, headers: headerWithAuthCredentials);
}
if (response.statusCode == 200)
return response.body;
else {
var json = jsonDecode(response.body);
throw Failure(message: json["error"]["message"]);
}
} catch (e) {
print(e.toString());
}
}
Map<String, String> createHeader(String verb, int nonce, _signature) {
return {
"api-key": "$apiKey",
"api-expires": nonce.toString(),
"api-signature": "${_signature.toString()}",
'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
'accept': 'application/json',
'x-Requested-With': 'XMLHttpRequest',
};
}
signature(String apiSecret, String verb, String path, int nonce) {
var message = verb + path + nonce.toString();
var messageEncoded = utf8.encode(message.trim());
var apiSecretEncoded = utf8.encode(apiSecret);
var apiSecretAshMacSha256 = new Hmac(sha256, apiSecretEncoded);
var sign = apiSecretAshMacSha256.convert(messageEncoded);
return sign;
}