【发布时间】:2020-01-22 07:55:48
【问题描述】:
这是币安加密交易所 API。我试图获取帐户信息,但我做不到。它是官方的 C++ API。 This is github link。这是终端上的错误。回答问题时,请放轻松。我是新手
2020-01-22 10:32:04 085219 :
2020-01-22 10:32:04 085245:网址 = |https://api.binance.com/api/v1/userDataStream|
2020-01-22 10:32:04 085253:
2020-01-22 10:32:04 698466:
2020-01-22 10:32:04 698529:完成
2020-01-22 10:32:04 701234:完成
2020-01-22 10:32:04 701434:完成。
2020-01-22 10:32:04 701472:完成。
{ “代码”:-2015, "msg" : "API 密钥、IP 或操作权限无效。" }
[2020/01/22 10:32:04:7018] 注意:未编译 libuv 支持
[2020/01/22 10:32:04:7045] 注意:创建 Vhost 'default' 端口 -1, 1 个协议,IPv6 关闭
[2020/01/22 10:32:04:7046] 注意:为默认创建了客户端 ssl 上下文
[2020/01/22 10:32:04:7099] 注意:lws_client_connect_2: 0x239f3e0: 地址 stream.binance.com
[2020/01/22 10:32:05:3128] 注意:lws_client_connect_2: 0x239f3e0: 地址stream.binance.com
我在这里输入了我的密钥。
using namespace std;
#define API_KEY "my api key here,deleted for security"
#define SECRET_KEY "secret key is here, deleted for security"
主要功能
int main() {
Json::Value result;
long recvWindow = 10000;
string api_key = API_KEY;
string secret_key = SECRET_KEY;
BinaCPP::init( api_key , secret_key );
// User Balance
BinaCPP::get_account( recvWindow , result );
for ( int i = 0 ; i < result["balances"].size() ; i++ ) {
string symbol = result["balances"][i]["asset"].asString();
userBalance[symbol]["f"] = atof( result["balances"][i]["free"].asString().c_str() );
userBalance[symbol]["l"] = atof( result["balances"][i]["locked"].asString().c_str() );
}
print_userBalance();
// User data stream
BinaCPP::start_userDataStream(result );
cout << result << endl;
string ws_path = string("/ws/");
ws_path.append( result["listenKey"].asString() );
BinaCPP_websocket::init();
BinaCPP_websocket::connect_endpoint( ws_userStream_OnData , ws_path.c_str() );
BinaCPP_websocket::enter_event_loop();
}
这是 BinaCPP.cpp 的一部分
#include "binacpp.h"
#include "binacpp_logger.h"
#include "binacpp_utils.h"
string BinaCPP::api_key = "my api key here";
string BinaCPP::secret_key = "secret key here";
CURL* BinaCPP::curl = NULL;
//---------------------------------
void
BinaCPP::init( string &api_key, string &secret_key )
{
curl_global_init(CURL_GLOBAL_DEFAULT);
BinaCPP::curl = curl_easy_init();
BinaCPP::api_key = api_key;
BinaCPP::secret_key = secret_key;
}
【问题讨论】:
-
您是否也将
BinaCPP::api_key填写为API_KEY?很难说。 -
@Botje 是的,先生,我做到了。
-
您能否对来自同一 IP 的
curl执行相同的操作?这排除了您的 API 密钥对于链接的操作/IP 组合无效。 -
@Botje 我想找到了原因,但我使用的是官方 API 和示例。我完全不懂。 pastebin.pl/view/f4e0e9cf
-
您如何在编译示例失败的同时产生错误消息?