tiagosiebler / bybit-api

Node.js SDK for the Bybit APIs and WebSockets, with TypeScript & browser support.
https://www.npmjs.com/package/bybit-api
MIT License
233 stars 79 forks source link

Error when config axios request #342

Open phongtran2309 opened 2 months ago

phongtran2309 commented 2 months ago

const { RestClientV5 } = require('bybit-api');

const client = new RestClientV5( { testnet: true, key: key, secret: secret, }, { proxy: { host: host, port: port, auth: { username: username, password: password, }, }, }, ); client.submitOrder({ category: 'spot', symbol: 'ETHUSDT', side: 'Buy', orderType: 'Market', qty: '0.1', }) .then((response) => { console.log(JSON.stringify(response, null, 2)); }) .catch((error) => { console.error(error); }); i got error "Error: Client network socket disconnected before secure TLS connection was established" when i make a api call

"headers: Object [AxiosHeaders] { Accept: 'application/json, text/plain, /', 'Content-Type': 'application/json', 'X-BAPI-SIGN-TYPE': '2', 'X-BAPI-API-KEY': 'vTxZJiHCNDBCBIzaYe', 'X-BAPI-TIMESTAMP': '1715069550287', 'X-BAPI-SIGN': 'a52550de4c44fcdfb30d251a769973d515e4acc0c4618ea38f6713e69dd46a52', 'X-BAPI-RECV-WINDOW': '5000', 'x-referer': 'bybitapinode', 'User-Agent': 'axios/1.6.8', 'Content-Length': '84', 'Accept-Encoding': 'gzip, compress, deflate, br' },"

tiagosiebler commented 2 months ago

Proxying is handled via axios (which is used for all HTTP request building in my SDKs). There's a few ways to configure proxies, and the correct way depends on the proxy you're trying to use. Ideally the provider of your proxy can explain how to use it / what kind of proxy it is. Typically this method will work for most HTTP/HTTPS proxies: https://github.com/tiagosiebler/bybit-api/blob/master/examples/rest-v5-proxies.ts#L20-L32

In some cases, some HTTP/HTTPS proxies will only work by using a proxy agent such as HttpsProxyAgent: https://github.com/tiagosiebler/bybit-api/blob/master/examples/rest-v5-proxies2.ts#L41-L42

If you're using a SOCKS or SOCKS5 proxy, there's also a SocksProxyAgent on npm.