v3.10.3: feat(#340) fix pass-through headers for proxying via nginx. add second proxy example.
This commit is contained in:
@@ -17,7 +17,12 @@ const client = new RestClientV5(
|
|||||||
// recv_window: 10000,
|
// recv_window: 10000,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Axios has a native way of supporting http/https proxies. It works for most proxy services but not all.
|
||||||
|
* If you have issues making any proxied requests this way, take a look at the rest-v5-proxies2.ts example using the https-proxy-agent.
|
||||||
|
*/
|
||||||
proxy: {
|
proxy: {
|
||||||
|
protocol: 'http', // or 'https'
|
||||||
host: 'proxyhost',
|
host: 'proxyhost',
|
||||||
port: Number('proxyport'),
|
port: Number('proxyport'),
|
||||||
auth: {
|
auth: {
|
||||||
|
|||||||
54
examples/rest-v5-proxies2.ts
Normal file
54
examples/rest-v5-proxies2.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
// @ts-ignore
|
||||||
|
import { HttpsProxyAgent } from 'https-proxy-agent';
|
||||||
|
|
||||||
|
import { RestClientV5 } from '../src/index';
|
||||||
|
|
||||||
|
// or
|
||||||
|
// import { RestClientV5 } from 'bybit-api';
|
||||||
|
|
||||||
|
const key = process.env.API_KEY_COM;
|
||||||
|
const secret = process.env.API_SECRET_COM;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some proxy services don't work with the proxy configuration that axios supports.
|
||||||
|
*
|
||||||
|
* For these, you can try using HttpsProxyAgent or SocksProxyAgent (depending on your proxy type, HTTP or SOCKS).
|
||||||
|
*
|
||||||
|
* The following example uses the HttpsProxyAgent (via the npm module https-proxy-agent).
|
||||||
|
*/
|
||||||
|
|
||||||
|
const proxyDetails = {
|
||||||
|
user: 'yourProxyUser',
|
||||||
|
pass: 'yourProxyPassword',
|
||||||
|
host: '127.0.0.1',
|
||||||
|
port: 31413,
|
||||||
|
};
|
||||||
|
|
||||||
|
const proxyURL = `http://${proxyDetails.user}:${proxyDetails.pass}@${proxyDetails.host}:${proxyDetails.port}`;
|
||||||
|
const proxyAgent = new HttpsProxyAgent(proxyURL);
|
||||||
|
|
||||||
|
const client = new RestClientV5(
|
||||||
|
{
|
||||||
|
key: key,
|
||||||
|
secret: secret,
|
||||||
|
parseAPIRateLimits: true,
|
||||||
|
testnet: true,
|
||||||
|
// Sometimes using a proxy introduces recv timestamp errors (due to the extra latency)
|
||||||
|
// If that happens, you can try increasing the recv window (which is 5000ms by default)
|
||||||
|
// recv_window: 10000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
httpAgent: proxyAgent,
|
||||||
|
httpsAgent: proxyAgent,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const res = await client.getWalletBalance({ accountType: 'UNIFIED' });
|
||||||
|
|
||||||
|
console.log('response: ', JSON.stringify(res, null, 2));
|
||||||
|
} catch (e) {
|
||||||
|
console.error('request failed: ', e);
|
||||||
|
}
|
||||||
|
})();
|
||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "bybit-api",
|
"name": "bybit-api",
|
||||||
"version": "3.10.1",
|
"version": "3.10.3",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "bybit-api",
|
"name": "bybit-api",
|
||||||
"version": "3.10.1",
|
"version": "3.10.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.6.6",
|
"axios": "^1.6.6",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "bybit-api",
|
"name": "bybit-api",
|
||||||
"version": "3.10.2",
|
"version": "3.10.3",
|
||||||
"description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
|
"description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ export default abstract class BaseRestClient {
|
|||||||
// custom request options based on axios specs - see: https://github.com/axios/axios#request-config
|
// custom request options based on axios specs - see: https://github.com/axios/axios#request-config
|
||||||
...networkOptions,
|
...networkOptions,
|
||||||
headers: {
|
headers: {
|
||||||
|
...networkOptions.headers,
|
||||||
'x-referer': APIID,
|
'x-referer': APIID,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user