ig-trading-api
Advanced tools
Comparing version 0.9.1 to 0.10.0
@@ -0,1 +1,15 @@ | ||
### 0.10.0 (2021-04-14) | ||
##### Chores | ||
- Update docsify ([681aec93](https://github.com/bennycode/ig-trading-api/commit/681aec93e4ba7b932a3161ba9eafd74c69448b8d)) | ||
##### Documentation Changes | ||
- Add links to limits & commissions ([2dd175d5](https://github.com/bennycode/ig-trading-api/commit/2dd175d5b22a2e64cf87799c513ce6920b1a3d8c)) | ||
##### New Features | ||
- Add rate-limiting ([#139](https://github.com/bennycode/ig-trading-api/pull/139)) ([7347e3a9](https://github.com/bennycode/ig-trading-api/commit/7347e3a96de327f880743195cbc3de0780421a88)) | ||
#### 0.9.1 (2021-04-13) | ||
@@ -2,0 +16,0 @@ |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -21,2 +40,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
const account_1 = require("../account"); | ||
const axios_retry_1 = __importStar(require("axios-retry")); | ||
class RESTClient { | ||
@@ -30,2 +50,26 @@ constructor(baseURL, apiKey) { | ||
}); | ||
function randomNum(min, max) { | ||
return Math.floor(Math.random() * (max - min + 1) + min); | ||
} | ||
axios_retry_1.default(this.httpClient, { | ||
retries: Infinity, | ||
retryCondition: (error) => { | ||
var _a, _b, _c, _d, _e, _f; | ||
const gotRateLimited = ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.errorCode) === 'error.public-api.exceeded-api-key-allowance'; | ||
const expiredSecurityToken = ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.errorCode) === 'error.security.oauth-token-invalid'; | ||
const missingToken = ((_f = (_e = error.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.errorCode) === 'error.security.client-token-missing'; | ||
if (gotRateLimited) { | ||
return true; | ||
} | ||
else if (expiredSecurityToken || missingToken) { | ||
void this.login.refreshToken(); | ||
return true; | ||
} | ||
return axios_retry_1.isNetworkOrIdempotentRequestError(error); | ||
}, | ||
retryDelay: (retryCount) => { | ||
/** Rate limits: https://labs.ig.com/faq */ | ||
return randomNum(1000, 3000) * retryCount; | ||
}, | ||
}); | ||
this.httpClient.interceptors.request.use((config) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -43,15 +87,2 @@ const updatedHeaders = Object.assign(Object.assign({}, config.headers), { 'X-IG-API-KEY': this.apiKey }); | ||
})); | ||
this.httpClient.interceptors.response.use(response => { | ||
return response; | ||
}, (error) => { | ||
if (error.response.status == 401 && error.response.data.errorCode == 'error.security.oauth-token-invalid') { | ||
const config = error.config; | ||
return this.login.refreshToken().then(_ => { | ||
const { accessToken } = this.auth; | ||
config.headers.Authorization = 'Bearer ' + accessToken; | ||
return axios_1.default(config); | ||
}); | ||
} | ||
return Promise.reject(error.config); | ||
}); | ||
this.login = new login_1.LoginAPI(this.httpClient, this.auth); | ||
@@ -58,0 +89,0 @@ this.market = new market_1.MarketAPI(this.httpClient); |
@@ -8,2 +8,3 @@ { | ||
"axios": "0.21.1", | ||
"axios-retry": "3.1.9", | ||
"lightstreamer-client-node": "8.0.3", | ||
@@ -98,3 +99,3 @@ "luxon": "1.26.0" | ||
}, | ||
"version": "0.9.1" | ||
"version": "0.10.0" | ||
} |
@@ -60,2 +60,4 @@ # IG Trading API | ||
- [IG Streaming Companion](https://labs.ig.com/sample-apps/streaming-companion/index.html) | ||
- [IG REST Trading API Limits](https://labs.ig.com/faq) | ||
- [Spreads, commissions and margins](https://www.ig.com/en/cfd-trading/charges-and-margins) ([in Germany](https://www.ig.com/de/hilfe-und-support/cfds/kosten-und-gebuehren/wie-lauten-die-produktinformationen-fuer-aktien-cfds#information-banner-dismiss)) | ||
@@ -62,0 +64,0 @@ ### IG instrument identifier (epic) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
248074
3455
105
5
+ Addedaxios-retry@3.1.9
+ Addedaxios-retry@3.1.9(transitive)
+ Addedis-retry-allowed@1.2.0(transitive)