我正在尝试使用Binance api和以下Objective-c代码进行订购。
- (void)order {
double unixtime = [[NSDate date] timeIntervalSince1970];
NSString *time = [@( floor(unixtime * 1000) ) stringValue];
NSURLComponents *components = [NSURLComponents componentsWithString:@"https://api.binance.com"];
components.path = @"/api/v3/order";
NSURLQueryItem *symbol = [NSURLQueryItem queryItemWithName:@"symbol" value:@"BTCUSDT"];
NSURLQueryItem *side = [NSURLQueryItem queryItemWithName:@"side" value:@"BUY"];
NSURLQueryItem *type = [NSURLQueryItem queryItemWithName:@"type" value:@"MARKET"];
NSURLQueryItem *quantity = [NSURLQueryItem queryItemWithName:@"quantity" value:@"0.01"];
NSURLQueryItem *timestamp = [NSURLQueryItem queryItemWithName:@"timestamp" value:time];
NSURLQueryItem *recvWindow = [NSURLQueryItem queryItemWithName:@"recvWindow" value:@"5000"];
components.queryItems = @[symbol,side,type,quantity,recvWindow,timestamp];
NSURLQueryItem *signature = [NSURLQueryItem queryItemWithName:@"signature"
value:[self HMACStringForKey:secret dataString:components.query]];
components.queryItems = @[symbol,side,type,quantity,recvWindow,timestamp,signature];
NSURL *url = [components URL];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"GET"];
[request setValue:apikey forHTTPHeaderField:@"X-MBX-APIKEY"];
[[[NSURLSession sharedSession] dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (response && ! error) {
NSLog(@"%@", [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]);
} else {
NSLog(@"%@", error);
}
}] resume];
}
但是我收到以下错误。 请让我知道如何使用binance api订购。
{
code = "-1101";
msg = "Too many parameters; expected '6' and received '7'.";
}
可以在此处找到Binance API的文档:https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md。我做错了什么?
环境
macOS HighSierra XCode 9.0.1 目标C
答案 0 :(得分:1)
您的HTTP动词为GET
,文档说明您应该使用POST
/api/v3/order
端点。
将[request setHTTPMethod:@"GET"];
更改为[request setHTTPMethod:@"POST"];