如何修复无效的 API 密钥、IP 或权限错误?

Sac*_*ler 2 c++ api websocket

这是 Binance 加密货币交易所 api。我试图获取帐户信息,但我无法做到。这是官方的 C++ Api。这是 github 链接。这是终端上的错误。当你回答问题时,请轻松。我是新手

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:完成。

{ "code" : -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"
Run Code Online (Sandbox Code Playgroud)

和主要功能

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(); 


}
Run Code Online (Sandbox Code Playgroud)

这是 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;
}
Run Code Online (Sandbox Code Playgroud)

Tan*_*tin 5

我相信这是我在 python 中遇到的错误。如果您使用 binance.us 而不是 binance.com 设置您的币安账户,您需要确保在源文件中更改它。在 python 中,它就像在初始化客户端类时传递 'tld="us"' 参数一样简单。

我看到你有“ url = | https://api.binance .com /api/v1/userDataStream|” 您可能需要“ url = | https://api.binance .us /api/v1/userDataStream|”

另外,我注意到您的 url 有 api/v1,只是想确保当您获取帐户信息或其他需要 api_secret 密钥的请求时,它应该翻转 api/v2 或 api/v3。

我不熟悉 C++,但这里有一个在 python 中执行查找/替换的解决方案。希望这些信息对你有帮助!

您需要导航到 github 下载文件所在的目录,然后尝试以下操作:

检查此代码以确保它不会替换您可能需要的任何 .com。

import os
for root, dirs, files in os.walk(os.curdir):
    for f in files:
        file_name = os.path.join(root, f):
            try:
                with open(file_name, 'r') as fp:
                    data = fp.read().replace('.com', '.us')
                with open(file_name, 'w') as fp:
                    fp.write(data)
            except:
                print(f.ljust(20), 'failed')
Run Code Online (Sandbox Code Playgroud)