Ccxt: support of IP/socks/http proxy in node version of the ccxt library

Created on 6 Apr 2018  Â·  3Comments  Â·  Source: ccxt/ccxt

kroitor,
First of all, thanks and salute to your great work!!

I am looking for the ways to implement proxying the IP to send concurrent fetchOrderBook requests in node code (using promise.all).

you guided the methods in php (curl_option in #2302 ) and python (python proxing in #906) versions, but I could not the find the same for node.js.

Currently I know php and node languages, and I will have to learn python for this feature if this is the case.

I don't want to use php either as it does not support asynch/concurrency, so node version is my only option.

I save "Improved proxy support" and "WebSocket interfaces:" in your pending list, but can't wait for my project, please guide available options.

Highly appreciated

duplicate question

Most helpful comment

Hi! )

but can't wait for my project, please guide available options.

Available options:

  1. You can pass your fetch implementation to the exchange constructor, and, basically, override everything you want in the networking internals, including proxies, tunnelAgents, etc...
const ccxt = require ('ccxt')
const fetch = require ('node-fetch')
const yourImplementationOfFetchInterface = async function (url, options) {
    // you can set all options supported by Node fetch here
    // all fetch options are listed here: https://www.npmjs.com/package/node-fetch#options
    return fetch (url, Object.assign ({}, options, { agent : yourProxyAgent })
}
const exchange = new ccxt.kraken ({'fetchImplementation': yourImplementationOfFetchInterface})
  1. You can pass the agent parameter to constructor to override it partially with just the proxying agent...
const ccxt = require ('ccxt')
const https = require ('https')
class YourAgent extends https.Agent {
   // ... add your proxy/ip overrides here according to `node-fetch` and `http(s).Agent` docs...
}
const exchange = new ccxt.kraken ({'agent': new YourAgent ()})

Let us know if this does not answer your question. Thx!

All 3 comments

Hi! )

but can't wait for my project, please guide available options.

Available options:

  1. You can pass your fetch implementation to the exchange constructor, and, basically, override everything you want in the networking internals, including proxies, tunnelAgents, etc...
const ccxt = require ('ccxt')
const fetch = require ('node-fetch')
const yourImplementationOfFetchInterface = async function (url, options) {
    // you can set all options supported by Node fetch here
    // all fetch options are listed here: https://www.npmjs.com/package/node-fetch#options
    return fetch (url, Object.assign ({}, options, { agent : yourProxyAgent })
}
const exchange = new ccxt.kraken ({'fetchImplementation': yourImplementationOfFetchInterface})
  1. You can pass the agent parameter to constructor to override it partially with just the proxying agent...
const ccxt = require ('ccxt')
const https = require ('https')
class YourAgent extends https.Agent {
   // ... add your proxy/ip overrides here according to `node-fetch` and `http(s).Agent` docs...
}
const exchange = new ccxt.kraken ({'agent': new YourAgent ()})

Let us know if this does not answer your question. Thx!

https://www.npmjs.com/package/https-proxy-agent

const ccxt = require ('ccxt')
    , HttpsProxyAgent = require ('https-proxy-agent')

const proxy = process.env.http_proxy || 'http://168.63.76.32:3128' // HTTP/HTTPS proxy to connect to
const agent = new HttpsProxyAgent (proxy)

const kraken = new ccxt.kraken ({ agent })

Hello kroitor,

Thanks for the solutions, I am going to work on it as this is really a
life-saving help!

2 items I forgot to ask in the question:

  1. Can Socks 5 be used in above solutions? I don't have detailed
    understanding on types of proxies.
  2. I need to implement the unique proxy on every fetchOrderBook requests
    for the same exchange... ie. Let's say I have 20 pairs in an exchange, I
    will be rotating 20 unique/different proxies for each fetchOrderBook
    request in for..loop with concurrency (promise.all)... please confirm if I
    am correct.

Bunch of thanks.

On Fri, Apr 6, 2018 at 9:41 PM, Igor Kroitor notifications@github.com
wrote:

Hi! )

but can't wait for my project, please guide available options.

Available options:

  1. You can pass your fetch implementation to the exchange constructor,
    and, basically, override everything you want in the networking internals,
    including proxies, tunnelAgents, etc...

const ccxt = require ('ccxt')
const yourImplementationOfFetchInterface = async function (url, options) {
// you can set all options supported by Node fetch here
}
const exchange = new ccxt.kraken ({'fetchImplementation': yourImplementationOfFetchInterface})

  1. You can pass the agent parameter to constructor to override it
    partially with just the proxying agent...

https://www.npmjs.com/package/node-fetch#options

Let us know if this does not answer your question. Thx!

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/ccxt/ccxt/issues/2480#issuecomment-379309437, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AhOtfH0JBGWmTVm6NF51_iporJt4ozgdks5tl5rAgaJpZM4TKVl_
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jjhesk picture jjhesk  Â·  3Comments

jackyxie picture jackyxie  Â·  3Comments

shnhrrsn picture shnhrrsn  Â·  3Comments

wannesdemaeght picture wannesdemaeght  Â·  3Comments

nashse picture nashse  Â·  3Comments