Apikey is not authorize

Hi I can not connect to the binance’s testnet.

  • OS: Ubuntu 20.04
  • country Brazil
    I tried to connect using the API using the library node-binance-api and also the cctx library for javascript. For both of them I get:
{"code":-2015,"msg":"Invalid API-key, IP, or permissions for action."}

So the error is related to the test server. It is a new account and I am new at market currency. I just copy and paste the key and the secret from the API section in the bottom of the test dashboard. Is anything I need to do like activate the API?

these are both the codes:

const Binance = require(‘node-binance-api’);
const binance = new Binance().options({
APIKEY: “XXXXXXXXXXXX”,
APISECRET: “XXXXXXXXXX”,
test: true
});
binance.balance((error, balances) => {
if (error)
return console.error(error.body);
console.info(“balances()”, balances);
console.info("ETH balance: ", balances.ETH.available);
});

cctx

‘use strict’;
const ccxt = require(‘ccxt’);

(async function () {
console.log(ccxt.version)
const exchange = new ccxt.binance({
apiKey: “XXXXXXXXXXXXXXXXXXX”,
secret: “XXXXXXXXXXXXXXXXXXXXXXXX”,
verbose: true,
defaultType: ‘future’
})
exchange.setSandboxMode(true)
console.log(exchange.requiredCredentials) // prints required credentials
try {
exchange.checkRequiredCredentials() // throw AuthenticationError
console.log(exchange.id)
console.log(exchange.id, await exchange.fetchBalance())
} catch (error) {
console.log(error)
}
})();

The test API Keys do not work outside of the test environment.

SPOT Testnet Base URL https://testnet.binance.vision
SPOT Live Base URL https://api.binance.com

Thanks for the response.
I am sorry I didn’t understand well. I am using the test enviroment
on the cctx code I add:
exchange.setSandboxMode(true)

and on the node-binance-api I add the
test: true
option

Is not the proper way to work on the test enviroment?

Please confirm that the Spot Testnet API Key was generated from this site

https://testnet.binance.vision/

1 Like

thanks you @tantialex … you are right.
Now it works

I must ask. I think this is a different account from the futures test api https://testnet.binancefuture.com/
… where is the dashboard of this new account ?
where I can buy and sold with this account?
Also, how can I test future API if the already registered account’s keys from there don’t work
I am sorry for the silly question… I am really new at this.

I think this is a different account from the futures test api

Correct. The SPOT Testnet is independent of the Futures Testnet

where is the dashboard of this new account ? where I can buy and sold with this account?

There is no UI for this testnet, trading must be done via the API.

Also, how can I test future API if the already registered account’s keys from there don’t work

The Futures Testnet keys work with the Futures API only.

I suggest have a look at the postman collection to get familiar the API with limited code needed.

Please note, the Spot testnet does not support /sapi/* endpoints.

thanks again for the response. it saves me a lot of time. But How can access to the future API that was the first reason that brings me here… I have registered an account in the future testnet, I am using the API key automatically created in the dashboard and I get the invalid key error. Now I can connect to the spot/margin API thanks to you, but how connect to the future testnet API where I have already an account?

I got this now. I was incorrectly use both codes for futures
in the cctx case I need to ask for the balance in the future API explicitly since the default type is “spot”

let balance = await exchange.fetchBalance({
type: ‘future’
})

thanks

It worked for me too thank you !

But how can I view my order on the Gui testnet.binance ?