Skip to content

Commit

Permalink
feat(js) - load modules async (ccxt#20685)
Browse files Browse the repository at this point in the history
* feat(js) - disable proxy temporarily

* reorg

* remove ioFileExistsAsync

* remove fetch try

* fetch - move to nodejs

* error exception

* update loading modules with nested way

[ci skip]
  • Loading branch information
Travis CI committed Jan 9, 2024
1 parent 4a9f7e1 commit b774a71
Show file tree
Hide file tree
Showing 349 changed files with 290,907 additions and 247 deletions.
4 changes: 2 additions & 2 deletions README.md

Large diffs are not rendered by default.

92 changes: 62 additions & 30 deletions dist/ccxt.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2693,28 +2693,28 @@ class alpaca extends _abstract_alpaca_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
'trading': {
'tierBased': true,
'percentage': true,
'maker': this.parseNumber('0.003'),
'taker': this.parseNumber('0.003'),
'maker': this.parseNumber('0.0015'),
'taker': this.parseNumber('0.0025'),
'tiers': {
'taker': [
[this.parseNumber('0'), this.parseNumber('0.003')],
[this.parseNumber('500000'), this.parseNumber('0.0028')],
[this.parseNumber('1000000'), this.parseNumber('0.0025')],
[this.parseNumber('5000000'), this.parseNumber('0.002')],
[this.parseNumber('10000000'), this.parseNumber('0.0018')],
[this.parseNumber('25000000'), this.parseNumber('0.0015')],
[this.parseNumber('50000000'), this.parseNumber('0.00125')],
[this.parseNumber('0'), this.parseNumber('0.0025')],
[this.parseNumber('100000'), this.parseNumber('0.0022')],
[this.parseNumber('500000'), this.parseNumber('0.0020')],
[this.parseNumber('1000000'), this.parseNumber('0.0018')],
[this.parseNumber('10000000'), this.parseNumber('0.0015')],
[this.parseNumber('25000000'), this.parseNumber('0.0013')],
[this.parseNumber('50000000'), this.parseNumber('0.0012')],
[this.parseNumber('100000000'), this.parseNumber('0.001')],
],
'maker': [
[this.parseNumber('0'), this.parseNumber('0.003')],
[this.parseNumber('500000'), this.parseNumber('0.0028')],
[this.parseNumber('1000000'), this.parseNumber('0.0025')],
[this.parseNumber('5000000'), this.parseNumber('0.002')],
[this.parseNumber('10000000'), this.parseNumber('0.0018')],
[this.parseNumber('25000000'), this.parseNumber('0.0015')],
[this.parseNumber('50000000'), this.parseNumber('0.00125')],
[this.parseNumber('100000000'), this.parseNumber('0.001')],
[this.parseNumber('0'), this.parseNumber('0.0015')],
[this.parseNumber('100000'), this.parseNumber('0.0012')],
[this.parseNumber('500000'), this.parseNumber('0.001')],
[this.parseNumber('1000000'), this.parseNumber('0.0008')],
[this.parseNumber('10000000'), this.parseNumber('0.0005')],
[this.parseNumber('25000000'), this.parseNumber('0.0002')],
[this.parseNumber('50000000'), this.parseNumber('0.0002')],
[this.parseNumber('100000000'), this.parseNumber('0.00')],
],
},
},
Expand Down Expand Up @@ -7649,10 +7649,28 @@ class Exchange {
console.log(...args);
}
async loadProxyModules() {
if (this.proxyModulesLoaded) {
return;
}
this.proxyModulesLoaded = true;
// todo: possible sync alternatives: https://stackoverflow.com/questions/51069002/convert-import-to-synchronous
this.httpProxyAgentModule = await import(/* webpackIgnore: true */ '../static_dependencies/proxies/http-proxy-agent/index.js');
this.httpsProxyAgentModule = await import(/* webpackIgnore: true */ '../static_dependencies/proxies/https-proxy-agent/index.js');
// we have to handle it with below nested way, because of dynamic
// import issues (https://github.com/ccxt/ccxt/pull/20687)
try {
// todo: possible sync alternatives: https://stackoverflow.com/questions/51069002/convert-import-to-synchronous
this.httpProxyAgentModule = await import(/* webpackIgnore: true */ '../static_dependencies/proxies/http-proxy-agent/index.js');
this.httpsProxyAgentModule = await import(/* webpackIgnore: true */ '../static_dependencies/proxies/https-proxy-agent/index.js');
}
catch (e) {
// if several users are using those frameworks which cause exceptions,
// let them to be able to load modules still, by installing them
try {
// @ts-ignore
this.httpProxyAgentModule = await import(/* webpackIgnore: true */ 'http-proxy-agent');
// @ts-ignore
this.httpProxyAgentModule = await import(/* webpackIgnore: true */ 'https-proxy-agent');
}
catch { }
}
if (this.socksProxyAgentModuleChecked === false) {
this.socksProxyAgentModuleChecked = true;
try {
Expand Down Expand Up @@ -7744,11 +7762,10 @@ class Exchange {
// proxy agents
const [httpProxy, httpsProxy, socksProxy] = this.checkProxySettings(url, method, headers, body);
this.checkConflictingProxies(httpProxy || httpsProxy || socksProxy, proxyUrl);
// skip proxies on the browser
if (isNode) {
// skip this on the browser
if (!this.proxyModulesLoaded) {
await this.loadProxyModules(); // this is needed in JS, independently whether proxy properties were set or not, we have to load them because of necessity in WS, which would happen beyond 'fetch' method (WS/etc)
}
// this is needed in JS, independently whether proxy properties were set or not, we have to load them because of necessity in WS, which would happen beyond 'fetch' method (WS/etc)
await this.loadProxyModules();
}
const chosenAgent = this.setProxyAgents(httpProxy, httpsProxy, socksProxy);
// user-agent
Expand All @@ -7770,13 +7787,29 @@ class Exchange {
// end of proxies & headers
if (this.fetchImplementation === undefined) {
if (isNode) {
const module = await import(/* webpackIgnore: true */ '../static_dependencies/node-fetch/index.js');
if (this.agent === undefined) {
this.agent = this.httpsAgent;
}
this.AbortError = module.AbortError;
this.fetchImplementation = module.default;
this.FetchError = module.FetchError;
try {
const module = await import(/* webpackIgnore: true */ '../static_dependencies/node-fetch/index.js');
this.AbortError = module.AbortError;
this.fetchImplementation = module.default;
this.FetchError = module.FetchError;
}
catch (e) {
// some users having issues with dynamic imports (https://github.com/ccxt/ccxt/pull/20687)
// so let them to fallback to node's native fetch
if (typeof fetch === 'function') {
this.fetchImplementation = fetch;
// as it's browser-compatible implementation ( https://nodejs.org/dist/latest-v20.x/docs/api/globals.html#fetch )
// it throws same error types
this.AbortError = DOMException;
this.FetchError = TypeError;
}
else {
throw new Error('Seems, "fetch" function is not available in your node-js version, please use latest node-js version');
}
}
}
else {
this.fetchImplementation = self.fetch;
Expand Down Expand Up @@ -189374,8 +189407,7 @@ class okx extends _abstract_okx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
'referral': {
// old reflink 0% discount https://www.okx.com/join/1888677
// new reflink 20% discount https://www.okx.com/join/CCXT2023
// okx + ccxt campaign reflink with 20% discount https://www.okx.com/activities/ccxt-trade-and-earn?channelid=CCXT2023
'url': 'https://www.okx.com/activities/ccxt-trade-and-earn?channelid=CCXT2023',
'url': 'https://www.okx.com/join/CCXT2023',
'discount': 0.2,
},
'test': {
Expand Down
4 changes: 2 additions & 2 deletions dist/ccxt.browser.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit b774a71

Please sign in to comment.