Skip to content

Commit

Permalink
feat(iqoption): Add cors bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
andredezzy committed Aug 14, 2021
1 parent c2664f6 commit 6d4cbec
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
],
"rules": {
"prettier/prettier": "error",
"curly": ["error", "all"],
"newline-before-return": "error",
"camelcase": "off",
"no-useless-constructor": "off",
"no-async-promise-executor": "off",
Expand Down
8 changes: 4 additions & 4 deletions examples/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# yarn lockfile v1


"@hemes/core@../packages/core", "@hemes/core@0.0.1-next.2":
version "0.0.1-next.2"
"@hemes/core@../packages/core", "@hemes/core@0.0.1-next.3":
version "0.0.1-next.3"

"@hemes/iqoption@../packages/iqoption":
version "0.0.1-next.2"
version "0.0.1-next.3"
dependencies:
"@hemes/core" "0.0.1-next.2"
"@hemes/core" "0.0.1-next.3"
axios "^0.21.1"
date-fns "^2.21.1"
date-fns-timezone "^0.1.4"
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"coveralls": "cat ./coverage/lcov.info | coveralls",
"tsc": "tsc --skipLibCheck",
"prepublishOnly": "npm run test && npm run build",
"publish:local": "npm run prepublishOnly && yalc publish packages/core && yalc publish packages/iqoption",
"publish:canary": "lerna version prerelease --no-changelog --preid next",
"publish:stable": "lerna version --no-changelog",
"postinstall": "husky install && shx rm -rf .git/hooks && shx ln -s ../.husky .git/hooks"
Expand Down Expand Up @@ -67,6 +68,7 @@
"rollup-plugin-url": "3.0.1",
"shx": "^0.3.3",
"ts-jest": "26.4.4",
"typescript": "4.1.3"
"typescript": "4.1.3",
"yalc": "^1.0.0-pre.53"
}
}
13 changes: 13 additions & 0 deletions packages/iqoption/lib/IQOptionProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios, { AxiosInstance } from 'axios'

import { cors } from '@base-sdk/core'
import { sleep } from '@hemes/core'

import { IQOptionAccount } from './IQOptionAccount'
Expand All @@ -20,6 +21,8 @@ export class IQOptionProvider implements BaseIQOptionProvider {
private api: AxiosInstance
private webSocket: WebSocketClient

private isCorsBypassEnabled: boolean

constructor() {
this.api = axios.create({
baseURL: 'https://iqoption.com/api',
Expand All @@ -28,6 +31,12 @@ export class IQOptionProvider implements BaseIQOptionProvider {
this.webSocket = new WebSocketClient()
}

public async enableCorsBypass(): Promise<void> {
this.isCorsBypassEnabled = true

cors.useAxiosCors(this.api)
}

public async logIn({
email,
password,
Expand All @@ -38,6 +47,10 @@ export class IQOptionProvider implements BaseIQOptionProvider {
baseURL: 'https://auth.iqoption.com/api/v2',
})

if (this.isCorsBypassEnabled) {
cors.useAxiosCors(authApi)
}

const response = await authApi.post<LoginResponse>('/login', {
identifier: email,
password,
Expand Down
12 changes: 2 additions & 10 deletions packages/iqoption/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface LogInCredentials {
}

export interface BaseIQOptionProvider {
enableCorsBypass(): Promise<void>
logIn(credentials: LogInCredentials): Promise<BaseIQOptionAccount>
}

Expand Down Expand Up @@ -258,21 +259,12 @@ export type BalanceMode = 'real' | 'practice'

export type UnderlyingType = 'digital-option'

export type InstrumentType =
| 'binary-option'
| 'turbo-option'
| 'digital-option'
| 'cfd'
| 'forex'
| 'crypto'
export type InstrumentType = 'binary-option' | 'turbo-option' | 'digital-option'

export const allInstrumentTypes: InstrumentType[] = [
'binary-option',
'turbo-option',
'digital-option',
'cfd',
'forex',
'crypto',
]

export interface CandleData {
Expand Down
1 change: 1 addition & 0 deletions packages/iqoption/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"access": "public"
},
"dependencies": {
"@base-sdk/core": "^0.1.0-1",
"@hemes/core": "0.0.1-next.3",
"axios": "^0.21.1",
"date-fns": "^2.21.1",
Expand Down
52 changes: 47 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@
lodash "^4.17.19"
to-fast-properties "^2.0.0"

"@base-sdk/core@^0.1.0-1":
version "0.1.0-1"
resolved "https://registry.yarnpkg.com/@base-sdk/core/-/core-0.1.0-1.tgz#0cc7102a658caa2e783586f7fb705574711f0072"
integrity sha512-FRI5tUq4fr3TU5b077O9gGXrZgAll71wtc+mBPN644xVsntnluMvrbLoCRJd8z5Zp98avkbxkulX8QVoiYFn4g==
dependencies:
"@reflect-ui/core" "0.0.2-rc.7"
axios "^0.21.0"

"@bcoe/v8-coverage@^0.2.3":
version "0.2.3"
resolved "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz"
Expand Down Expand Up @@ -1541,6 +1549,11 @@
dependencies:
"@octokit/openapi-types" "^6.0.0"

"@reflect-ui/core@0.0.2-rc.7":
version "0.0.2-rc.7"
resolved "https://registry.yarnpkg.com/@reflect-ui/core/-/core-0.0.2-rc.7.tgz#9d531f5a0b9caab31e7563020044b753700e2bbc"
integrity sha512-EqF4SRU57bfa5DOPET1rv5lROFyMVHLv1xTEIlN6N2gDpXt71QceImWfQp3z3Khqnb4R/p9OhNK6DXGUpozWKw==

"@rollup/plugin-json@^4.1.0":
version "4.1.0"
resolved "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-4.1.0.tgz"
Expand Down Expand Up @@ -2134,7 +2147,7 @@ aws4@^1.8.0:
resolved "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz"
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==

axios@^0.21.1:
axios@^0.21.0, axios@^0.21.1:
version "0.21.1"
resolved "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz"
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
Expand Down Expand Up @@ -3733,7 +3746,7 @@ fragment-cache@^0.2.1:
dependencies:
map-cache "^0.2.2"

fs-extra@8.1.0:
fs-extra@8.1.0, fs-extra@^8.0.1:
version "8.1.0"
resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz"
integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==
Expand Down Expand Up @@ -4203,7 +4216,7 @@ ignore@^4.0.6:
resolved "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz"
integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==

ignore@^5.1.1, ignore@^5.1.4:
ignore@^5.0.4, ignore@^5.1.1, ignore@^5.1.4:
version "5.1.8"
resolved "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz"
integrity sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==
Expand Down Expand Up @@ -4264,6 +4277,11 @@ ini@^1.3.2, ini@^1.3.4:
resolved "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==

ini@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ini/-/ini-2.0.0.tgz#e5fd556ecdd5726be978fa1001862eacb0a94bc5"
integrity sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==

init-package-json@^2.0.2:
version "2.0.2"
resolved "https://registry.npmjs.org/init-package-json/-/init-package-json-2.0.2.tgz"
Expand Down Expand Up @@ -6040,6 +6058,16 @@ npm-packlist@^2.1.4:
npm-bundled "^1.1.1"
npm-normalize-package-bin "^1.0.1"

npm-packlist@^2.1.5:
version "2.2.2"
resolved "https://registry.yarnpkg.com/npm-packlist/-/npm-packlist-2.2.2.tgz#076b97293fa620f632833186a7a8f65aaa6148c8"
integrity sha512-Jt01acDvJRhJGthnUJVF/w6gumWOZxO7IkpY/lsX9//zqQgnF7OJaxgQXcerd4uQOLu7W5bkb4mChL9mdfm+Zg==
dependencies:
glob "^7.1.6"
ignore-walk "^3.0.3"
npm-bundled "^1.1.1"
npm-normalize-package-bin "^1.0.1"

npm-pick-manifest@^6.0.0:
version "6.1.1"
resolved "https://registry.npmjs.org/npm-pick-manifest/-/npm-pick-manifest-6.1.1.tgz"
Expand Down Expand Up @@ -7060,7 +7088,7 @@ rimraf@^2.6.3:

rollup-plugin-babel@^4.4.0:
version "4.4.0"
resolved "https://registry.npmjs.org/rollup-plugin-babel/-/rollup-plugin-babel-4.4.0.tgz"
resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-4.4.0.tgz#d15bd259466a9d1accbdb2fe2fff17c52d030acb"
integrity sha512-Lek/TYp1+7g7I+uMfJnnSJ7YWoD58ajo6Oarhlex7lvUce+RCKRuGRSgztDO3/MF/PuGKmUL5iTHKf208UNszw==
dependencies:
"@babel/helper-module-imports" "^7.0.0"
Expand Down Expand Up @@ -8439,6 +8467,20 @@ y18n@^5.0.5:
resolved "https://registry.npmjs.org/y18n/-/y18n-5.0.5.tgz"
integrity sha512-hsRUr4FFrvhhRH12wOdfs38Gy7k2FFzB9qgN9v3aLykRq0dRcdcpz5C9FxdS2NuhOrI/628b/KSTJ3rwHysYSg==

yalc@^1.0.0-pre.53:
version "1.0.0-pre.53"
resolved "https://registry.yarnpkg.com/yalc/-/yalc-1.0.0-pre.53.tgz#c51db2bb924a6908f4cb7e82af78f7e5606810bc"
integrity sha512-tpNqBCpTXplnduzw5XC+FF8zNJ9L/UXmvQyyQj7NKrDNavbJtHvzmZplL5ES/RCnjX7JR7W9wz5GVDXVP3dHUQ==
dependencies:
chalk "^4.1.0"
detect-indent "^6.0.0"
fs-extra "^8.0.1"
glob "^7.1.4"
ignore "^5.0.4"
ini "^2.0.0"
npm-packlist "^2.1.5"
yargs "^16.1.1"

yallist@^3.0.0, yallist@^3.0.3:
version "3.1.1"
resolved "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz"
Expand Down Expand Up @@ -8489,7 +8531,7 @@ yargs@^15.4.1:
y18n "^4.0.0"
yargs-parser "^18.1.2"

yargs@^16.2.0:
yargs@^16.1.1, yargs@^16.2.0:
version "16.2.0"
resolved "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz"
integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==
Expand Down

0 comments on commit 6d4cbec

Please sign in to comment.