Skip to content

Commit

Permalink
feat: IQ Option package implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
andredezzy committed Apr 9, 2021
2 parents f58ea72 + 63b3881 commit d65eae1
Show file tree
Hide file tree
Showing 44 changed files with 1,207 additions and 278 deletions.
14 changes: 13 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,28 @@
"prettier",
"import-helpers"
],
"overrides": [
{
"files": ["**/types.ts"],
"rules": {
"no-use-before-define": "off"
}
}
],
"rules": {
"prettier/prettier": "error",
"camelcase": "off",
"no-useless-constructor": "off",
"no-async-promise-executor": "off",
"import-helpers/order-imports": [
"warn",
{
"newlinesBetween": "always",
"groups": [
["module", "absolute"],
"/^@/",
["parent", "sibling", "index"]
["parent", "index"],
"sibling"
],
"alphabetize": { "order": "asc", "ignoreCase": true }
}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
name: Test code
runs-on: ubuntu-latest

environment: Test

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -26,6 +28,9 @@ jobs:

- name: Run Jest
run: yarn test --coverage
env:
TEST_IQOPTION_ACCOUNT_EMAIL: ${{ secrets.TEST_IQOPTION_ACCOUNT_EMAIL }}
TEST_IQOPTION_ACCOUNT_PASSWORD: ${{ secrets.TEST_IQOPTION_ACCOUNT_PASSWORD }}

- name: Coveralls
uses: coverallsapp/github-action@master
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ typings/
*.tgz

# dotenv environment variable files
.env*
.env*.local

# Library
dist/
Expand Down
4 changes: 2 additions & 2 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"src/**/*.{js,ts,tsx}": [
"eslint --ext js,ts,tsx --fix"
"packages/**/*.{js,ts}": [
"eslint --ext js,ts --fix"
]
}
2 changes: 2 additions & 0 deletions examples/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TEST_IQOPTION_ACCOUNT_EMAIL=
TEST_IQOPTION_ACCOUNT_PASSWORD=
7 changes: 4 additions & 3 deletions examples/iqoption/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ This folder contains Hemes for IQ Option examples for different types of actions
them were tested and may work properly. You can also customize them for your
needs.

| Name | Link |
| ------- | ----------------------------------------------------------------- |
| Sign In | [JavaScript](./signIn.js) - [TypeScript](./typescript/signIn.tsx) |
| Name | Link |
| ----------- | ------------------------------------------------------------------------- |
| Log in | [JavaScript](./logIn.js) - [TypeScript](./typescript/logIn.tsx) |
| Get profile | [JavaScript](./getProfile.js) - [TypeScript](./typescript/getProfile.tsx) |

## Add an example

Expand Down
21 changes: 21 additions & 0 deletions examples/iqoption/getProfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import '../../loadEnv'

import { Hemes, sleep } from '@hemes/core'
import { IQOptionProvider } from '@hemes/iqoption'

async function run() {
const hemes = new Hemes(IQOptionProvider).getProvider()

const account = await hemes.logIn({
email: String(process.env.TEST_IQOPTION_ACCOUNT_EMAIL),
password: String(process.env.TEST_IQOPTION_ACCOUNT_PASSWORD),
})

await sleep(5000)

const profile = await account.getProfile()

console.log('Has received profile ->', !!profile)
}

run()
15 changes: 15 additions & 0 deletions examples/iqoption/logIn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import '../../loadEnv'

import { Hemes } from '@hemes/core'
import { IQOptionProvider } from '@hemes/iqoption'

async function run() {
const hemes = new Hemes(IQOptionProvider).getProvider()

await hemes.logIn({
email: String(process.env.TEST_IQOPTION_ACCOUNT_EMAIL),
password: String(process.env.TEST_IQOPTION_ACCOUNT_PASSWORD),
})
}

run()
Empty file removed examples/iqoption/signIn.js
Empty file.
21 changes: 21 additions & 0 deletions examples/iqoption/typescript/getProfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import '../../loadEnv'

import { Hemes, sleep } from '@hemes/core'
import { IQOptionProvider, BaseIQOptionProvider } from '@hemes/iqoption'

async function run() {
const hemes = new Hemes(IQOptionProvider).getProvider<BaseIQOptionProvider>()

const account = await hemes.logIn({
email: String(process.env.TEST_IQOPTION_ACCOUNT_EMAIL),
password: String(process.env.TEST_IQOPTION_ACCOUNT_PASSWORD),
})

await sleep(5000)

const profile = await account.getProfile()

console.log('Has received profile ->', !!profile)
}

run()
15 changes: 15 additions & 0 deletions examples/iqoption/typescript/logIn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import '../../loadEnv'

import { Hemes } from '@hemes/core'
import { BaseIQOptionProvider, IQOptionProvider } from '@hemes/iqoption'

async function run() {
const hemes = new Hemes(IQOptionProvider).getProvider<BaseIQOptionProvider>()

await hemes.logIn({
email: String(process.env.TEST_IQOPTION_ACCOUNT_EMAIL),
password: String(process.env.TEST_IQOPTION_ACCOUNT_PASSWORD),
})
}

run()
Empty file.
8 changes: 8 additions & 0 deletions examples/loadEnv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const dotenv = require('dotenv')
const path = require('path')

const envFileName = '.env.local'

dotenv.config({
path: path.resolve(__dirname, envFileName),
})
19 changes: 19 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@hemes/example",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"update": "cd .. && yarn --force && yarn build && cd examples && yarn --force",
"prestart": "yarn update",
"start": "yarn ts-node"
},
"dependencies": {
"@hemes/core": "../packages/core",
"@hemes/iqoption": "../packages/iqoption",
"dotenv": "^8.2.0"
},
"devDependencies": {
"ts-node": "^9.1.1",
"typescript": "^4.2.3"
}
}
10 changes: 10 additions & 0 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
114 changes: 114 additions & 0 deletions examples/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


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

"@hemes/iqoption@../packages/iqoption":
version "0.0.1-next.0"
dependencies:
"@hemes/core" "0.0.1-next.0"
axios "^0.21.1"
md5 "2.3.0"

arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==

axios@^0.21.1:
version "0.21.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
dependencies:
follow-redirects "^1.10.0"

buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==

charenc@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"
integrity sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc=

create-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==

crypt@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b"
integrity sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs=

diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==

dotenv@^8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==

follow-redirects@^1.10.0:
version "1.13.3"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.3.tgz#e5598ad50174c1bc4e872301e82ac2cd97f90267"
integrity sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA==

is-buffer@~1.1.6:
version "1.1.6"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==

make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==

md5@2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/md5/-/md5-2.3.0.tgz#c3da9a6aae3a30b46b7b0c349b87b110dc3bda4f"
integrity sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==
dependencies:
charenc "0.0.2"
crypt "0.0.2"
is-buffer "~1.1.6"

source-map-support@^0.5.17:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==

ts-node@^9.1.1:
version "9.1.1"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.1.1.tgz#51a9a450a3e959401bda5f004a72d54b936d376d"
integrity sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==
dependencies:
arg "^4.1.0"
create-require "^1.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"

typescript@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.3.tgz#39062d8019912d43726298f09493d598048c1ce3"
integrity sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==

yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@
"@commitlint/config-conventional": "12.0.1",
"@commitlint/travis-cli": "12.0.1",
"@rocketseat/commitlint-config": "^0.0.3",
"@rollup/plugin-json": "^4.1.0",
"@types/dot-object": "2.1.2",
"@types/dotenv": "^8.2.0",
"@types/jest": "26.0.20",
"@typescript-eslint/eslint-plugin": "4.14.1",
"@typescript-eslint/parser": "4.14.1",
"coveralls": "3.1.0",
"dotenv": "^8.2.0",
"eslint": "7.18.0",
"eslint-config-prettier": "8.1.0",
"eslint-config-standard": "16.0.2",
Expand All @@ -64,4 +67,4 @@
"ts-jest": "26.4.4",
"typescript": "4.1.3"
}
}
}
6 changes: 4 additions & 2 deletions packages/core/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const { join } = require('path')
const path = require('path')

const baseConfig = require('../../jest.config')
const pkg = require('./package.json')

delete baseConfig.projects

const testsPath = path.join(__dirname, '__tests__')

module.exports = {
...baseConfig,
displayName: pkg.name,
testMatch: [join(__dirname, '__tests__/**/*.spec.{ts,tsx}')],
testMatch: [path.join(testsPath, '**/*.spec.{ts,tsx}')],
}
14 changes: 7 additions & 7 deletions packages/core/lib/Hemes.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ProviderConstructor, BaseHemes, Provider } from './types'
import { BaseHemes, ClassPrototype, ProviderConstructor } from './types'

export class Hemes<PC extends ProviderConstructor> implements BaseHemes {
private HemesProvider: PC
export class Hemes<T extends ClassPrototype> implements BaseHemes<T> {
private provider: any

constructor(provider: PC) {
this.HemesProvider = provider
constructor(HemesProvider: T & ProviderConstructor<T>) {
this.provider = new HemesProvider(this)
}

getProvider(): Provider {
return new this.HemesProvider(this)
public getProvider<P = T['prototype']>(): P {
return this.provider
}
}
5 changes: 5 additions & 0 deletions packages/core/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
export * from './Hemes'

/**
* Utils
*/
export * from './utils/sleep'

/**
* Types
*/
Expand Down
Loading

0 comments on commit d65eae1

Please sign in to comment.