Open skliarovartem opened 2 years ago
You can try passing this in the first parameter (REST client options) in any of the rest clients:
baseUrl: "https://testnet.binance.vision"
Hi there, any way to use it for the websocket also ?
Spot API URL | Spot Test Network URL |
---|---|
https://api.binance.com/api | https://testnet.binance.vision/api |
wss://stream.binance.com:9443/ws | wss://testnet.binance.vision/ws |
wss://stream.binance.com:9443/stream | wss://testnet.binance.vision/stream |
Thank you in advance !
Actually it s very easy, by using the wsUrl in the options
let _opts:WSClientConfigurableOptions={
// api_key: this.keys.API_Key,
// api_secret: this.keys.Secret_Key,
beautify: true,
// Disable ping/pong ws heartbeat mechanism (not recommended)
// disableHeartbeat: true
wsUrl:'wss://testnet.binance.vision/ws',
restOptions:{
baseUrl:'https://testnet.binance.vision'
}
}
in case some one have the same question
did anything change in the meantime by any chance?
I'm trying to connect to testnet via;
const baseUrL = (testnet ? "https://testnet.binance.vision/api" : "https://api.binance.com/api");
const client = new MainClient({
api_key: apikey,
api_secret: secret,
baseUrl: baseUrL
});
The response I'm getting is:
{ "body": "
more or less the same reply without /api:
{ "body": "", "headers": { "content-type": "text/plain; charset=utf-8", "content-length": "0", "connection": "close", "date": "Thu, 17 Nov 2022 14:12:16 GMT", "server": "nginx", "x-content-type-options": "nosniff", "x-frame-options": "DENY", "x-xss-protection": "1; mode=block", "referrer-policy": "strict-origin-when-cross-origin", "cache-control": "no-cache, no-store, must-revalidate, no-cache, no-store, must-revalidate", "pragma": "no-cache, no-cache", "expires": "0", "content-security-policy": "style-src 'sha256-mcBXr4VjWlBf3SfyQ5+Wm92/O81FeZGc85fmmbhjj+k=' 'sha256-wSI3cAJwzKV+dPAgXMCTat869o5mA0HfdnKphAm7Gr8=' https://bin.bnbstatic.com; font-src https://bin.bnbstatic.com; img-src https://bin.bnbstatic.com; default-src 'self'", "strict-transport-security": "max-age=31536000; includeSubdomains", "x-cache": "Error from cloudfront", "via": "1.1 7b80fdb7de25e1eb41eb907750147f34.cloudfront.net (CloudFront)", "x-amz-cf-pop": "AMS1-P2", "x-amz-cf-id": "m5ucT6codf0PboVMStwuehuJvgdFcLDjyHVhr75uXuYwjYuSgltvSA==" }, "requestUrl": "https://testnet.binance.vision/sapi/v1/account/apiRestrictions?timestamp=1668694335777&recvWindow=5000&signature=cd79c6edf09708187c0212cb4dd7d5e1695fcc120e5518ba558cc0aff241d329", "requestOptions": { "recvWindow": 5000, "syncIntervalMs": 3600000, "strictParamValidation": false, "baseUrl": "https://testnet.binance.vision" } }
I believe it is still working
I was getting 404s too but this was from using the wrong client for the operation - I was trying use the CoinMClient
to get account information which won't work - you have to use MainClient
(!) Here's a complete example that works at time of posting:
import {CoinMClient, MainClient, USDMClient} from "binance";
const testnet = true;
const baseUrl = (testnet ? "https://testnet.binance.vision" : "https://api.binance.com");
const client = new MainClient({
api_key: process.env["BINANCE_API_KEY"],
api_secret: process.env["BINANCE_API_SECRET"],
baseUrl
});
// Get the account balance
client
.getAccountInformation()
.then((result) => {
console.log('getSymbolOrderBookTicker result: ', result);
console.log("time to die!");
process.exit()
})
.catch((err) => {
console.error('getSymbolOrderBookTicker error: ', err);
});
Seems MainClient.getBalances() is using /sapi endpoints and when we are connecting to testnet , is not working..
How to connect to https://testnet.binance.vision/api instead of main net?