I tried to interact in Node js with the Binance Testnet Spot Api. I use "node-binance-api" but it prints only weird stuff when I want to buy sell or get the balance. Can you help me with that issue. I also set up a raspberry pi with the same code and it works on the raspberry pi but why not on windows. Here is my code:
const Binance = require('node-binance-api');
const binance = new Binance().options({
APIKEY: '#####',
APISECRET: '#####',
verbose: true,
urls: {
base: "https://testnet.binance.vision/api/", // remove this to trade on mainnet
combineStream: 'wss://testnet.binance.vision/stream?streams=',
stream: 'wss://testnet.binance.vision/ws/'
},
});
binance.balance((error, balances) => {
if ( error ) return console.log(error);
console.info("balances()", balances);
if(balances.USDT.available != undefined){
console.info("USDT balance: ", balances.USDT.available);
}
});
And here is the output:
proxyHeaderExclusiveList: []
},
setHeader: [Function (anonymous)],
hasHeader: [Function (anonymous)],
getHeader: [Function (anonymous)],
removeHeader: [Function (anonymous)],
pool: { 'https:': [Agent] },
dests: [],
__isRequestRequest: true,
_callback: [Function (anonymous)],
uri: Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'testnet.binance.vision',
port: null,
hostname: 'testnet.binance.vision',
hash: null,
search: '?timestamp=1629799331717&recvWindow=5000&signature=cc76599a0f29728adcd76cb0a009c8e42e6d65e4944abc12d701ebc494c59538',
query: 'timestamp=1629799331717&recvWindow=5000&signature=cc76599a0f29728adcd76cb0a009c8e42e6d65e4944abc12d701ebc494c59538',
pathname: '/api/v3/account',
path: '/api/v3/account?timestamp=1629799331717&recvWindow=5000&signature=cc76599a0f29728adcd76cb0a009c8e42e6d65e4944abc12d701ebc494c59538',
href: 'https://testnet.binance.vision/api/v3/account?timestamp=1629799331717&recvWindow=5000&signature=cc76599a0f29728adcd76cb0a009c8e42e6d65e4944abc12d701ebc494c59538'
},
proxy: null,
tunnel: true,
setHost: true,
originalCookieHeader: undefined,
_disableCookies: true,
_jar: undefined,
port: 443,
host: 'testnet.binance.vision',
url: Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'testnet.binance.vision',
port: null,
hostname: 'testnet.binance.vision',
hash: null,
search: '?timestamp=1629799331717&recvWindow=5000&signature=cc76599a0f29728adcd76cb0a009c8e42e6d65e4944abc12d701ebc494c59538',
query: 'timestamp=1629799331717&recvWindow=5000&signature=cc76599a0f29728adcd76cb0a009c8e42e6d65e4944abc12d701ebc494c59538',
pathname: '/api/v3/account',
path: '/api/v3/account?timestamp=1629799331717&recvWindow=5000&signature=cc76599a0f29728adcd76cb0a009c8e42e6d65e4944abc12d701ebc494c59538',
href: 'https://testnet.binance.vision/api/v3/account?timestamp=1629799331717&recvWindow=5000&signature=cc76599a0f29728adcd76cb0a009c8e42e6d65e4944abc12d701ebc494c59538'
},
path: '/api/v3/account?timestamp=1629799331717&recvWindow=5000&signature=cc76599a0f29728adcd76cb0a009c8e42e6d65e4944abc12d701ebc494c59538',
httpModule: {
Agent: [Function: Agent],
globalAgent: [Agent],
Server: [Function: Server],
createServer: [Function: createServer],
get: [Function (anonymous)],
request: [Function (anonymous)]
},
agentClass: [Function: Agent],
agentOptions: { keepAlive: true },
agent: Agent {
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object],
requests: {},
sockets: [Object],
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: true,
maxSockets: Infinity,
maxFreeSockets: 256,
scheduling: 'lifo',
maxTotalSockets: Infinity,
totalSocketCount: 1,
maxCachedSessions: 100,
_sessionCache: [Object],
[Symbol(kCapture)]: false
},
_started: true,
href: 'https://testnet.binance.vision/api/v3/account?timestamp=1629799331717&recvWindow=5000&signature=cc76599a0f29728adcd76cb0a009c8e42e6d65e4944abc12d701ebc494c59538',
req: <ref *3> ClientRequest {
_events: [Object: null prototype],
_eventsCount: 6,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: true,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [TLSSocket],
_header: 'GET /api/v3/account?timestamp=1629799331717&recvWindow=5000&signature=cc76599a0f29728adcd76cb0a009c8e42e6d65e4944abc12d701ebc494c59538 HTTP/1.1\r\n' +
'User-Agent: Mozilla/4.0 (compatible; Node Binance API)\r\n' +
'Content-type: application/x-www-form-urlencoded\r\n' +
'X-MBX-APIKEY: VaL2HWmy6TpwD5UVwZ53XWIpSpTBuYuIHN5bSuMRAHcdapLwZRqdW0JYM8UuNIkX\r\n' +
'host: testnet.binance.vision\r\n' +
'Connection: keep-alive\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: {},
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/api/v3/account?timestamp=1629799331717&recvWindow=5000&signature=cc76599a0f29728adcd76cb0a009c8e42e6d65e4944abc12d701ebc494c59538',
_ended: true,
res: [Circular *2],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'testnet.binance.vision',
protocol: 'https:',
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
ntick: true,
timeoutTimer: null,
response: [Circular *2],
originalHost: 'testnet.binance.vision',
originalHostHeaderName: 'host',
responseContent: [Circular *2],
_destdata: true,
_ended: true,
_callbackCalled: true,
[Symbol(kCapture)]: false
},
toJSON: [Function: responseToJSON],
caseless: Caseless {
dict: {
'content-type': 'application/json;charset=UTF-8',
'content-length': '88',
connection: 'keep-alive',
date: 'Tue, 24 Aug 2021 10:02:10 GMT',
server: 'nginx',
'x-mbx-uuid': '07e06b9a-8a30-4b81-a8e7-02bb3452ef16',
'x-mbx-used-weight': '12',
'x-mbx-used-weight-1m': '12',
'strict-transport-security': 'max-age=31536000; includeSubdomains',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '1; mode=block',