简体   繁体   English

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

[英]How to fix Invalid API-key, IP, or permissions for action error?

This is Binance cryptoexchange api.这是币安密码交换 API。 Im trying to get account informations but I could not do that.我试图获取帐户信息,但我做不到。 It's official C++ Api.它是官方的 C++ API。 This is github link .这是 github 链接 This is error on terminal.这是终端上的错误。 When you answering the question, Please be easy.回答问题时,请放轻松。 I am newbie我是新手

2020-01-22 10:32:04 085219 : 2020-01-22 10:32:04 085219 :

2020-01-22 10:32:04 085245 : url = | 2020-01-22 10:32:04 085245:网址 = | https://api.binance.com/api/v1/userDataStream| https://api.binance.com/api/v1/userDataStream|

2020-01-22 10:32:04 085253 : 2020-01-22 10:32:04 085253 :

2020-01-22 10:32:04 698466 : 2020-01-22 10:32:04 698466 :

2020-01-22 10:32:04 698529 : done 2020-01-22 10:32:04 698529:完成

2020-01-22 10:32:04 701234 : done 2020-01-22 10:32:04 701234:完成

2020-01-22 10:32:04 701434 : Done. 2020-01-22 10:32:04 701434:完成。

2020-01-22 10:32:04 701472 : Done. 2020-01-22 10:32:04 701472:完成。

{ "code" : -2015, "msg" : "Invalid API-key, IP, or permissions for action." { "code" : -2015, "msg" : "API 密钥、IP 或操作权限无效。" } }

[2020/01/22 10:32:04:7018] NOTICE: libuv support not compiled in [2020/01/22 10:32:04:7018] 注意:未编译 libuv 支持

[2020/01/22 10:32:04:7045] NOTICE: Creating Vhost 'default' port -1, 1 protocols, IPv6 off [2020/01/22 10:32:04:7045] 注意:创建 Vhost 的“默认”端口 -1、1 协议,关闭 IPv6

[2020/01/22 10:32:04:7046] NOTICE: created client ssl context for default [2020/01/22 10:32:04:7046] 注意:为默认创建了客户端 ssl 上下文

[2020/01/22 10:32:04:7099] NOTICE: lws_client_connect_2: 0x239f3e0: address stream.binance.com [2020/01/22 10:32:04:7099] 注意:lws_client_connect_2: 0x239f3e0: 地址 stream.binance.com

[2020/01/22 10:32:05:3128] NOTICE: lws_client_connect_2: 0x239f3e0: address stream.binance.com [2020/01/22 10:32:05:3128] 通知:lws_client_connect_2: 0x239f3e0: 地址 stream.binance.com

Here i entered my keys.在这里,我输入了我的钥匙。

 using namespace std;


#define API_KEY         "my api key here,deleted for security"
#define SECRET_KEY      "secret key is here, deleted for security"

and main function和主要功能

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


}

and this is a part of BinaCPP.cpp这是 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;
}

I believe this was the error I was running across in python.我相信这是我在 python 中遇到的错误。 If you set up your binance account with binance.us instead of binance.com you need to make sure that you change it in the scource files.如果您使用 binance.us 而不是 binance.com 设置您的币安账户,您需要确保在源文件中进行更改。 In python it was as easy as passing the 'tld="us"' parameter when initializing the client class.在 python 中,它就像在初始化客户端类时传递 'tld="us"' 参数一样简单。

I saw that you had " url = | https://api.binance .com /api/v1/userDataStream|"我看到你有“ url = | https://api.binance .com /api/v1/userDataStream|” You may need " url = | https://api.binance .us /api/v1/userDataStream|"您可能需要“ url = | https://api.binance .us /api/v1/userDataStream|”

Also, I noticed that your url had api/v1, just wanted to make sure that when you are grabbing account information or other requests that require your api_secret key it should roll over api/v2 or api/v3.另外,我注意到您的 url 有 api/v1,只是想确保当您获取帐户信息或其他需要您的 api_secret 密钥的请求时,它应该翻转 api/v2 或 api/v3。

I am not familiar with C++ but here is a solution to perform a find/replace in python.我不熟悉 C++,但这是在 python 中执行查找/替换的解决方案。 Hope this information helps you!希望这些信息对您有所帮助!

You will need to navigate to the directory your github-downloaded files are located and try the following:您需要导航到您的 github 下载文件所在的目录,然后尝试以下操作:

check this code to make sure it is not replacing any .com's you may need.检查此代码以确保它不会替换您可能需要的任何 .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')

For me, I had to log into the Binance API Management page and update my whitelisted IP addresses as I had since changed my Internet provider.对我来说,我必须登录 Binance API 管理页面并更新我的白名单 IP 地址,因为我已经更改了我的互联网提供商。 Always worth checking!总是值得检查!

Looks like you have to reactivate the trading permissions every 90 days.看起来您必须每 90 天重新激活一次交易许可。 Make sure all the required boxes are ticked on the API management page (reading, spot/margin trading, etc.).确保在 API 管理页面(阅读、现货/保证金交易等)上勾选了所有必需的框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复“无效操作数到二进制表达式”错误? - How to fix a “invalid operands to binary expression” error? 如何修复错误无效的inirection和左值 - how to fix error invalid inirection and lvalue 如何修复无效的比较器错误? - How do I fix an Invalid Comparator error? 如何解决这个错误:className::className 的使用无效? - How to fix this- error: Invalid use of className::className? 如何在C ++中修复“二进制表达式的无效操作数”错误 - How to fix 'Invalid operands to binary expression' error in C++ 如何修复:错误:从&#39;const MyClass *&#39;到&#39;MyClass *&#39;的无效转换 - How to fix: error: invalid conversion from 'const MyClass*' to 'MyClass*' 如何修复“从‘char*’到‘char’的无效转换”错误? - How to fix "invalid conversion from 'char*' to 'char'" error? 如何解决代码中的“无效的内存引用”错误? - How can I fix the “Invalid memory reference” error in my code? 如何修复从 'char' 到 'const char*' [-fpermissive] 的错误无效转换? - How to fix error invalid conversion from 'char' to 'const char*' [-fpermissive]? 什么是 glibc free/malloc/realloc invalid next size/invalid pointer 错误以及如何解决? - What is a glibc free/malloc/realloc invalid next size/invalid pointer error and how to fix it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM