Skip to content

Commit

Permalink
Merge branch 'develop' into feature/iqoption-candles
Browse files Browse the repository at this point in the history
  • Loading branch information
andredezzy committed Jul 3, 2021
2 parents 2de31f0 + 458ece4 commit 8bdff91
Show file tree
Hide file tree
Showing 10 changed files with 1,298 additions and 1,132 deletions.
28 changes: 28 additions & 0 deletions examples/iqoption/typescript/getCandles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Hemes } from '@hemes/core'
import {
BaseIQOptionProvider,
CandleInterval,
IQOptionProvider,
} from '@hemes/iqoption'
import '../../loadEnv'

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),
})

const candles = await hemes.getCandles(
6,
CandleInterval['1S'],
10,
Date.now()
)

console.log('Account', !!account)
console.log('\n', 'Candles', candles, '\n')
}

run()
3 changes: 2 additions & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"dependencies": {
"@hemes/core": "../packages/core",
"@hemes/iqoption": "../packages/iqoption",
"dotenv": "^8.2.0"
"dotenv": "^8.2.0",
"fs": "^0.0.1-security"
},
"devDependencies": {
"ts-node": "^9.1.1",
Expand Down
47 changes: 26 additions & 21 deletions examples/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
# yarn lockfile v1


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

"@hemes/iqoption@../packages/iqoption":
version "0.0.1-next.0"
version "0.0.1-next.2"
dependencies:
"@hemes/core" "0.0.1-next.0"
"@hemes/core" "0.0.1-next.2"
axios "^0.21.1"
date-fns "^2.21.1"
date-fns-timezone "^0.1.4"
md5 "2.3.0"

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

axios@^0.21.1:
Expand All @@ -28,7 +28,7 @@ axios@^0.21.1:

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

charenc@0.0.2:
Expand All @@ -43,7 +43,7 @@ commander@2.19.0:

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

crypt@0.0.2:
Expand All @@ -65,24 +65,29 @@ date-fns@^1.29.0:
integrity sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==

date-fns@^2.21.1:
version "2.21.1"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.21.1.tgz#679a4ccaa584c0706ea70b3fa92262ac3009d2b0"
integrity sha512-m1WR0xGiC6j6jNFAyW4Nvh4WxAi4JF4w9jRJwSI8nBmNcyZXPcP9VUQG+6gHQXAmqaGEKDKhOqAtENDC941UkA==
version "2.22.1"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.22.1.tgz#1e5af959831ebb1d82992bf67b765052d8f0efc4"
integrity sha512-yUFPQjrxEmIsMqlHhAhmxkuH769baF21Kk+nZwZGyrMoyLA+LugaQtC0+Tqf9CBUUULWwUJt6Q5ySI3LJDDCGg==

diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
resolved "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz"
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"
resolved "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz"
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==
version "1.14.1"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.1.tgz#d9114ded0a1cfdd334e164e6662ad02bfd91ff43"
integrity sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg==

fs@^0.0.1-security:
version "0.0.1-security"
resolved "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz"
integrity sha1-invTcYa23d84E/I4WLV+yq9eQdQ=

is-buffer@~1.1.6:
version "1.1.6"
Expand All @@ -91,7 +96,7 @@ is-buffer@~1.1.6:

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

md5@2.3.0:
Expand All @@ -105,15 +110,15 @@ md5@2.3.0:

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"
resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz"
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"
resolved "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==

timezone-support@^1.5.5:
Expand All @@ -125,7 +130,7 @@ timezone-support@^1.5.5:

ts-node@^9.1.1:
version "9.1.1"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.1.1.tgz#51a9a450a3e959401bda5f004a72d54b936d376d"
resolved "https://registry.npmjs.org/ts-node/-/ts-node-9.1.1.tgz"
integrity sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==
dependencies:
arg "^4.1.0"
Expand All @@ -137,10 +142,10 @@ ts-node@^9.1.1:

typescript@^4.2.3:
version "4.2.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
resolved "https://registry.npmjs.org/typescript/-/typescript-4.2.4.tgz"
integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==

yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
resolved "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"release/*"
],
"conventionalCommits": true,
"message": "chore: Publish release",
"message": "chore: Publish",
"registry": "https://registry.npmjs.org/"
}
},
Expand Down
2 changes: 0 additions & 2 deletions packages/iqoption/.env.test

This file was deleted.

33 changes: 33 additions & 0 deletions packages/iqoption/lib/IQOptionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import { IQOptionAccount } from './IQOptionAccount'
import {
BaseIQOptionAccount,
BaseIQOptionProvider,
Candle,
LogInCredentials,
} from './types'
import { GetCandlesRequest } from './websocket/events/requests/GetCandles'
import { SsidRequest } from './websocket/events/requests/SSID'
import {
CandleResponseData,
GetCandlesResponse,
} from './websocket/events/responses/GetCandles'
import { WebSocketClient } from './websocket/WebSocketClient'

interface LoginResponse {
Expand Down Expand Up @@ -59,4 +65,31 @@ export class IQOptionProvider implements BaseIQOptionProvider {

return account
}

public async getCandles(
active: number,
interval: string | number,
amount: number,
endtime: number
): Promise<Candle[]> {
const getCandlesRequest = await this.webSocket.send(GetCandlesRequest, {
active_id: active,
interval,
endtime,
amount,
})

const getCandlesResponse = await this.webSocket.waitFor<CandleResponseData>(
GetCandlesResponse,
{
requestId: getCandlesRequest.request_id,
}
)

if (!getCandlesResponse) {
throw new Error('Candles not found')
}

return getCandlesResponse.msg.candles
}
}
46 changes: 46 additions & 0 deletions packages/iqoption/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export interface LogInCredentials {

export interface BaseIQOptionProvider {
logIn(credentials: LogInCredentials): Promise<BaseIQOptionAccount>
getCandles(
active: number,
interval: string | number,
amount: number,
endtime: number
): Promise<Candle[]>
}

export interface PlaceDigitalOption {
Expand Down Expand Up @@ -269,6 +275,46 @@ export const allInstrumentTypes: InstrumentType[] = [
'crypto',
]

export interface CandleData {
open_at: number
close_at: number
direction: 'equal' | 'up' | 'down'
}

export interface Candle {
close: number
from: number
id: number
max: number
min: number
open: number
to: number
volume: number
}

export const CandleInterval = {
'1S': 1,
'5S': 5,
'10S': 10,
'15S': 15,
'30S': 30,
'1M': 60,
'2M': 120,
'5M': 300,
'10M': 600,
'15M': 900,
'30M': 1800,
'1H': 3600,
'2H': 7200,
'4H': 14400,
'8H': 28800,
'12H': 43200,
'1D': 86400,
'1W': 604800,
'1MO': 2592000,
ALL: 'all',
}

export type DigitalOptionExpirationPeriod = 'm1' | 'm5' | 'm15'

export type ExpirationPeriod = 'm1' | 'm5' | 'm15' | 'm30' | 'h1'
Expand Down
42 changes: 42 additions & 0 deletions packages/iqoption/lib/websocket/events/requests/GetCandles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Request } from '../Request'

interface GetCandlesMessage {
name: 'get-candles'
version: '2.0'
body: {}
}

interface GetCandlesRequestArgs {
active_id: number
interval: number | string
endtime: number
amount: number
}

export class GetCandlesRequest extends Request<
GetCandlesMessage,
GetCandlesRequestArgs
> {
public get name(): string {
return 'sendMessage'
}

public async build({
active_id,
interval,
endtime,
amount,
}: GetCandlesRequestArgs): Promise<GetCandlesMessage> {
return {
name: 'get-candles',
version: '2.0',
body: {
active_id: active_id,
size: interval,
to: endtime,
count: amount,
'': active_id,
},
}
}
}
13 changes: 13 additions & 0 deletions packages/iqoption/lib/websocket/events/responses/GetCandles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Candle } from 'packages/iqoption/lib/types'

import { Response } from '../Response'

export interface CandleResponseData {
candles: Candle[]
}

export class GetCandlesResponse extends Response<CandleResponseData> {
public get name(): string {
return 'candles'
}
}
Loading

0 comments on commit 8bdff91

Please sign in to comment.