iqoptionapi-node 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +219 -0
- package/dist/auth/CredentialAbstraction.d.ts +25 -0
- package/dist/auth/CredentialAbstraction.d.ts.map +1 -0
- package/dist/auth/CredentialAbstraction.js +46 -0
- package/dist/auth/CredentialAbstraction.js.map +1 -0
- package/dist/auth/EmailPasswordAuth.d.ts +11 -0
- package/dist/auth/EmailPasswordAuth.d.ts.map +1 -0
- package/dist/auth/EmailPasswordAuth.js +36 -0
- package/dist/auth/EmailPasswordAuth.js.map +1 -0
- package/dist/auth/SessionManager.d.ts +14 -0
- package/dist/auth/SessionManager.d.ts.map +1 -0
- package/dist/auth/SessionManager.js +51 -0
- package/dist/auth/SessionManager.js.map +1 -0
- package/dist/auth/SsidAuth.d.ts +10 -0
- package/dist/auth/SsidAuth.d.ts.map +1 -0
- package/dist/auth/SsidAuth.js +26 -0
- package/dist/auth/SsidAuth.js.map +1 -0
- package/dist/client/IQOptionClient.d.ts +58 -0
- package/dist/client/IQOptionClient.d.ts.map +1 -0
- package/dist/client/IQOptionClient.js +125 -0
- package/dist/client/IQOptionClient.js.map +1 -0
- package/dist/errors/index.d.ts +22 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +53 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/index.d.ts +6 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +33 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/market-data/AssetCatalog.d.ts +16 -0
- package/dist/market-data/AssetCatalog.d.ts.map +1 -0
- package/dist/market-data/AssetCatalog.js +45 -0
- package/dist/market-data/AssetCatalog.js.map +1 -0
- package/dist/market-data/CandleBuffer.d.ts +12 -0
- package/dist/market-data/CandleBuffer.d.ts.map +1 -0
- package/dist/market-data/CandleBuffer.js +44 -0
- package/dist/market-data/CandleBuffer.js.map +1 -0
- package/dist/market-data/CandleStream.d.ts +19 -0
- package/dist/market-data/CandleStream.d.ts.map +1 -0
- package/dist/market-data/CandleStream.js +73 -0
- package/dist/market-data/CandleStream.js.map +1 -0
- package/dist/market-data/HistoricalCandles.d.ts +11 -0
- package/dist/market-data/HistoricalCandles.d.ts.map +1 -0
- package/dist/market-data/HistoricalCandles.js +32 -0
- package/dist/market-data/HistoricalCandles.js.map +1 -0
- package/dist/market-data/TickAggregator.d.ts +13 -0
- package/dist/market-data/TickAggregator.d.ts.map +1 -0
- package/dist/market-data/TickAggregator.js +40 -0
- package/dist/market-data/TickAggregator.js.map +1 -0
- package/dist/market-data/TickStream.d.ts +18 -0
- package/dist/market-data/TickStream.d.ts.map +1 -0
- package/dist/market-data/TickStream.js +68 -0
- package/dist/market-data/TickStream.js.map +1 -0
- package/dist/protocol/V1Adapter.d.ts +20 -0
- package/dist/protocol/V1Adapter.d.ts.map +1 -0
- package/dist/protocol/V1Adapter.js +21 -0
- package/dist/protocol/V1Adapter.js.map +1 -0
- package/dist/trading/BinaryOptions.d.ts +31 -0
- package/dist/trading/BinaryOptions.d.ts.map +1 -0
- package/dist/trading/BinaryOptions.js +107 -0
- package/dist/trading/BinaryOptions.js.map +1 -0
- package/dist/trading/DigitalOptions.d.ts +31 -0
- package/dist/trading/DigitalOptions.d.ts.map +1 -0
- package/dist/trading/DigitalOptions.js +107 -0
- package/dist/trading/DigitalOptions.js.map +1 -0
- package/dist/trading/OrderCache.d.ts +17 -0
- package/dist/trading/OrderCache.d.ts.map +1 -0
- package/dist/trading/OrderCache.js +39 -0
- package/dist/trading/OrderCache.js.map +1 -0
- package/dist/trading/OrderHistory.d.ts +9 -0
- package/dist/trading/OrderHistory.d.ts.map +1 -0
- package/dist/trading/OrderHistory.js +17 -0
- package/dist/trading/OrderHistory.js.map +1 -0
- package/dist/transformers/entities.d.ts +8 -0
- package/dist/transformers/entities.d.ts.map +1 -0
- package/dist/transformers/entities.js +51 -0
- package/dist/transformers/entities.js.map +1 -0
- package/dist/transformers/toCamelCase.d.ts +2 -0
- package/dist/transformers/toCamelCase.d.ts.map +1 -0
- package/dist/transformers/toCamelCase.js +18 -0
- package/dist/transformers/toCamelCase.js.map +1 -0
- package/dist/transport/MessageRouter.d.ts +17 -0
- package/dist/transport/MessageRouter.d.ts.map +1 -0
- package/dist/transport/MessageRouter.js +87 -0
- package/dist/transport/MessageRouter.js.map +1 -0
- package/dist/transport/ReconnectionManager.d.ts +25 -0
- package/dist/transport/ReconnectionManager.d.ts.map +1 -0
- package/dist/transport/ReconnectionManager.js +63 -0
- package/dist/transport/ReconnectionManager.js.map +1 -0
- package/dist/transport/WebSocketTransport.d.ts +21 -0
- package/dist/transport/WebSocketTransport.d.ts.map +1 -0
- package/dist/transport/WebSocketTransport.js +68 -0
- package/dist/transport/WebSocketTransport.js.map +1 -0
- package/dist/types/logger.d.ts +7 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/logger.js +3 -0
- package/dist/types/logger.js.map +1 -0
- package/dist/types/market-data.d.ts +38 -0
- package/dist/types/market-data.d.ts.map +1 -0
- package/dist/types/market-data.js +3 -0
- package/dist/types/market-data.js.map +1 -0
- package/dist/types/messages.d.ts +8 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/dist/types/messages.js +3 -0
- package/dist/types/messages.js.map +1 -0
- package/dist/types/primitives.d.ts +29 -0
- package/dist/types/primitives.d.ts.map +1 -0
- package/dist/types/primitives.js +29 -0
- package/dist/types/primitives.js.map +1 -0
- package/dist/types/profile.d.ts +24 -0
- package/dist/types/profile.d.ts.map +1 -0
- package/dist/types/profile.js +3 -0
- package/dist/types/profile.js.map +1 -0
- package/dist/types/raw/asset.d.ts +20 -0
- package/dist/types/raw/asset.d.ts.map +1 -0
- package/dist/types/raw/asset.js +3 -0
- package/dist/types/raw/asset.js.map +1 -0
- package/dist/types/raw/candle.d.ts +15 -0
- package/dist/types/raw/candle.d.ts.map +1 -0
- package/dist/types/raw/candle.js +3 -0
- package/dist/types/raw/candle.js.map +1 -0
- package/dist/types/raw/order.d.ts +31 -0
- package/dist/types/raw/order.d.ts.map +1 -0
- package/dist/types/raw/order.js +3 -0
- package/dist/types/raw/order.js.map +1 -0
- package/dist/types/raw/tick.d.ts +9 -0
- package/dist/types/raw/tick.d.ts.map +1 -0
- package/dist/types/raw/tick.js +3 -0
- package/dist/types/raw/tick.js.map +1 -0
- package/dist/types/trading.d.ts +38 -0
- package/dist/types/trading.d.ts.map +1 -0
- package/dist/types/trading.js +3 -0
- package/dist/types/trading.js.map +1 -0
- package/dist/validators/malformedMessage.d.ts +16 -0
- package/dist/validators/malformedMessage.d.ts.map +1 -0
- package/dist/validators/malformedMessage.js +15 -0
- package/dist/validators/malformedMessage.js.map +1 -0
- package/dist/validators/messageSchema.d.ts +7 -0
- package/dist/validators/messageSchema.d.ts.map +1 -0
- package/dist/validators/messageSchema.js +25 -0
- package/dist/validators/messageSchema.js.map +1 -0
- package/package.json +81 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# 1.0.0 (2026-05-17)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- add publishConfig public and soften attw check ([24dfc7b](https://github.com/TupythonDev/iqoptionapi-node/commit/24dfc7b136ab6327513c332c6ea76963546cf756))
|
|
6
|
+
- ignore-scripts on npm pack and relax body-max-line-length for semantic-release ([aa3bf9e](https://github.com/TupythonDev/iqoptionapi-node/commit/aa3bf9e170dffe85a6d078a19b011ab2659316d5))
|
|
7
|
+
- switch to npm classic automation token ([c0f67a6](https://github.com/TupythonDev/iqoptionapi-node/commit/c0f67a63ab4b6ee2d0f72bb4e4d4f4c76c1bcc98))
|
|
8
|
+
- update npm token with 2fa bypass ([f0eecc0](https://github.com/TupythonDev/iqoptionapi-node/commit/f0eecc0d5ccb4c56cdbf49ae730b71aaa9081848))
|
|
9
|
+
- use Node 24 for release, test matrix 20/22/24 ([2004f5b](https://github.com/TupythonDev/iqoptionapi-node/commit/2004f5bc0ddda3e69d24ecc860da1e55b9577ae2))
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
- initial release ([02cb496](https://github.com/TupythonDev/iqoptionapi-node/commit/02cb49674e1c222ddddcfd0e70c90a9698463d09))
|
|
14
|
+
|
|
15
|
+
# 1.0.0 (2026-05-17)
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
- add publishConfig public and soften attw check ([24dfc7b](https://github.com/TupythonDev/iqoptionapi-node/commit/24dfc7b136ab6327513c332c6ea76963546cf756))
|
|
20
|
+
- ignore-scripts on npm pack and relax body-max-line-length for semantic-release ([aa3bf9e](https://github.com/TupythonDev/iqoptionapi-node/commit/aa3bf9e170dffe85a6d078a19b011ab2659316d5))
|
|
21
|
+
- use Node 24 for release, test matrix 20/22/24 ([2004f5b](https://github.com/TupythonDev/iqoptionapi-node/commit/2004f5bc0ddda3e69d24ecc860da1e55b9577ae2))
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
- initial release ([02cb496](https://github.com/TupythonDev/iqoptionapi-node/commit/02cb49674e1c222ddddcfd0e70c90a9698463d09))
|
|
26
|
+
|
|
27
|
+
# 1.0.0 (2026-05-17)
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
- ignore-scripts on npm pack and relax body-max-line-length for semantic-release ([aa3bf9e](https://github.com/TupythonDev/iqoptionapi-node/commit/aa3bf9e170dffe85a6d078a19b011ab2659316d5))
|
|
32
|
+
- use Node 24 for release, test matrix 20/22/24 ([2004f5b](https://github.com/TupythonDev/iqoptionapi-node/commit/2004f5bc0ddda3e69d24ecc860da1e55b9577ae2))
|
|
33
|
+
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
- initial release ([02cb496](https://github.com/TupythonDev/iqoptionapi-node/commit/02cb49674e1c222ddddcfd0e70c90a9698463d09))
|
package/README.md
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# iqoptionapi-node
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the IQOption WebSocket API — unofficial, reverse-engineered.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/TupythonDev/iqoptionapi-node/actions/workflows/ci.yml)
|
|
6
|
+
[](https://www.npmjs.com/package/iqoptionapi-node)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
> **Warning:** This is an unofficial SDK that reverse-engineers a proprietary protocol. It may break without notice when IQOption updates their API.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- Typed, promise-based API (TypeScript strict mode)
|
|
14
|
+
- Authentication via email/password or SSID session restore
|
|
15
|
+
- Real-time candle and tick streaming with auto-reconnect
|
|
16
|
+
- Historical candles
|
|
17
|
+
- Binary and digital options trading
|
|
18
|
+
- Circuit breaker on trading (suspends after 5 consecutive failures)
|
|
19
|
+
- PRACTICE account by default — REAL requires explicit opt-in
|
|
20
|
+
- WSS enforced — no insecure connections
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install iqoptionapi-node
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Requires **Node.js ≥ 18**.
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { IQOptionClient, Direction, TimeFrame } from 'iqoptionapi-node';
|
|
34
|
+
|
|
35
|
+
const client = new IQOptionClient();
|
|
36
|
+
await client.connect();
|
|
37
|
+
|
|
38
|
+
const profile = await client.login({ email: 'you@example.com', password: 'secret' });
|
|
39
|
+
console.log(`Balance: ${profile.balance} ${profile.currency}`);
|
|
40
|
+
|
|
41
|
+
// Fetch candles
|
|
42
|
+
const candles = await client.getCandles('EURUSD', TimeFrame.M1, 10);
|
|
43
|
+
|
|
44
|
+
// Place a binary option (PRACTICE account)
|
|
45
|
+
const { orderId } = await client.buyBinaryOption({
|
|
46
|
+
symbol: 'EURUSD',
|
|
47
|
+
direction: Direction.Call,
|
|
48
|
+
amount: 1,
|
|
49
|
+
durationSeconds: 60,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const result = await client.checkBinaryOptionResult(orderId, 70_000);
|
|
53
|
+
console.log(result.win, result.profitAmount);
|
|
54
|
+
|
|
55
|
+
await client.disconnect();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## API
|
|
59
|
+
|
|
60
|
+
### `new IQOptionClient(options?)`
|
|
61
|
+
|
|
62
|
+
| Option | Type | Default | Description |
|
|
63
|
+
| --------------------- | --------- | ---------------- | ------------------------- |
|
|
64
|
+
| `url` | `string` | IQOption WSS URL | Custom WebSocket endpoint |
|
|
65
|
+
| `logger` | `ILogger` | console logger | Injectable logger |
|
|
66
|
+
| `silent` | `boolean` | `false` | Suppress all log output |
|
|
67
|
+
| `requestTimeoutMs` | `number` | `10000` | Request timeout in ms |
|
|
68
|
+
| `maxReconnectRetries` | `number` | `5` | Max reconnection attempts |
|
|
69
|
+
|
|
70
|
+
### Connection
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
await client.connect();
|
|
74
|
+
await client.disconnect();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Authentication
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const profile = await client.login({ email, password });
|
|
81
|
+
const profile = await client.restoreSession(ssid);
|
|
82
|
+
const profile = client.getProfile();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Assets
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
client.getAllAssets(); // IQAsset[]
|
|
89
|
+
client.getOpenAssets(); // IQAsset[] — currently tradeable
|
|
90
|
+
client.getOtcAssets(); // IQAsset[] — OTC only
|
|
91
|
+
client.getNonOtcAssets(); // IQAsset[] — non-OTC only
|
|
92
|
+
client.getAsset('EURUSD'); // IQAsset | undefined
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Market Data
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
// Historical candles
|
|
99
|
+
const candles = await client.getCandles('EURUSD', TimeFrame.M1, 100)
|
|
100
|
+
const candles = await client.getCandles('EURUSD', TimeFrame.M5, 50, Date.now())
|
|
101
|
+
|
|
102
|
+
// Real-time candle stream
|
|
103
|
+
client.subscribeCandles('EURUSD', TimeFrame.M1, (candle) => { ... })
|
|
104
|
+
client.unsubscribeCandles('EURUSD', TimeFrame.M1)
|
|
105
|
+
|
|
106
|
+
// Tick quotes
|
|
107
|
+
client.subscribeQuotes('EURUSD', (tick) => { ... })
|
|
108
|
+
client.unsubscribeQuotes('EURUSD')
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Trading
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
// Binary options
|
|
115
|
+
const { orderId } = await client.buyBinaryOption({
|
|
116
|
+
symbol: 'EURUSD',
|
|
117
|
+
direction: Direction.Call, // or Direction.Put
|
|
118
|
+
amount: 10,
|
|
119
|
+
durationSeconds: 60,
|
|
120
|
+
})
|
|
121
|
+
const result = await client.checkBinaryOptionResult(orderId, 70_000)
|
|
122
|
+
// result: { orderId, win: 'win' | 'loss' | 'equal', profitAmount: number | null }
|
|
123
|
+
|
|
124
|
+
// Digital options
|
|
125
|
+
const { orderId } = await client.buyDigitalOption({ ... })
|
|
126
|
+
const result = await client.checkDigitalOptionResult(orderId, 70_000)
|
|
127
|
+
|
|
128
|
+
// Positions
|
|
129
|
+
const open = client.getOpenPositions()
|
|
130
|
+
const closed = client.getClosedPositions(10) // last 10
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### TimeFrame enum
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { TimeFrame } from 'iqoptionapi-node';
|
|
137
|
+
|
|
138
|
+
TimeFrame.S1; // 1 second
|
|
139
|
+
TimeFrame.M1; // 1 minute
|
|
140
|
+
TimeFrame.M5; // 5 minutes
|
|
141
|
+
TimeFrame.M15; // 15 minutes
|
|
142
|
+
TimeFrame.M30; // 30 minutes
|
|
143
|
+
TimeFrame.H1; // 1 hour
|
|
144
|
+
TimeFrame.H4; // 4 hours
|
|
145
|
+
TimeFrame.D1; // 1 day
|
|
146
|
+
TimeFrame.W1; // 1 week
|
|
147
|
+
TimeFrame.MN1; // 1 month
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Environment Variables
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
IQ_EMAIL=you@example.com
|
|
154
|
+
IQ_PASSWORD=secret
|
|
155
|
+
IQ_SSID=optional-session-token # restore an existing session
|
|
156
|
+
IQ_ACCOUNT_TYPE=PRACTICE # PRACTICE (default) | REAL
|
|
157
|
+
IQ_LOG_LEVEL=info # debug | info | warn | error
|
|
158
|
+
IQ_REQUEST_TIMEOUT_MS=10000
|
|
159
|
+
IQ_MAX_RECONNECT_RETRIES=5
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Examples
|
|
163
|
+
|
|
164
|
+
See the [`examples/`](./examples) directory:
|
|
165
|
+
|
|
166
|
+
| File | Description |
|
|
167
|
+
| ----------------------------------------------------------- | -------------------------------------- |
|
|
168
|
+
| [01-connect-auth.ts](./examples/01-connect-auth.ts) | Connect and authenticate |
|
|
169
|
+
| [02-fetch-candles.ts](./examples/02-fetch-candles.ts) | Fetch historical candles |
|
|
170
|
+
| [03-subscribe-stream.ts](./examples/03-subscribe-stream.ts) | Real-time candle + tick stream |
|
|
171
|
+
| [04-buy-option.ts](./examples/04-buy-option.ts) | Place a binary option and check result |
|
|
172
|
+
| [05-get-balance.ts](./examples/05-get-balance.ts) | Restore session, inspect positions |
|
|
173
|
+
|
|
174
|
+
Run any example with:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
IQ_EMAIL=you@example.com IQ_PASSWORD=secret npx ts-node examples/01-connect-auth.ts
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Error Hierarchy
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
IQOptionError
|
|
184
|
+
├── AuthenticationError — login / session failures
|
|
185
|
+
├── ConnectionError — WebSocket connect / send failures
|
|
186
|
+
├── ProtocolError — unexpected server messages
|
|
187
|
+
├── TradingError — order placement / circuit breaker
|
|
188
|
+
├── TimeoutError — request or result timeout
|
|
189
|
+
└── ValidationError — bad input (unknown symbol, insecure URL)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Circuit Breaker
|
|
193
|
+
|
|
194
|
+
The trading modules (`BinaryOptions`, `DigitalOptions`) automatically suspend after **5 consecutive failures** and emit a `tradingCircuitOpen` event. No further orders can be placed until the circuit is reset.
|
|
195
|
+
|
|
196
|
+
This protects against rapid-fire losses during connectivity issues or server-side errors.
|
|
197
|
+
|
|
198
|
+
## Security Notes
|
|
199
|
+
|
|
200
|
+
- Credentials are never logged. The sanitizer strips SSID, email, and password from all log output.
|
|
201
|
+
- `ws://` connections are rejected with `ValidationError` — WSS only.
|
|
202
|
+
- `rejectUnauthorized: true` is hardcoded with no override.
|
|
203
|
+
|
|
204
|
+
## Publishing / CI
|
|
205
|
+
|
|
206
|
+
This project uses:
|
|
207
|
+
|
|
208
|
+
- **GitHub Actions** — runs tests on Node 18 + 20 for every PR
|
|
209
|
+
- **semantic-release** — automated versioning and npm publish on merge to `main`
|
|
210
|
+
- **Conventional Commits** — `feat:` bumps minor, `fix:` bumps patch, `BREAKING CHANGE` bumps major
|
|
211
|
+
|
|
212
|
+
To publish, set these secrets in your GitHub repository:
|
|
213
|
+
|
|
214
|
+
- `NPM_TOKEN` — npm automation token
|
|
215
|
+
- `GITHUB_TOKEN` — provided automatically by GitHub Actions
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
|
|
219
|
+
MIT
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface CredentialProvider {
|
|
2
|
+
provide(): {
|
|
3
|
+
identifier: string;
|
|
4
|
+
password: string;
|
|
5
|
+
};
|
|
6
|
+
zero(): void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Replaces every occurrence of each sensitive value with [REDACTED].
|
|
10
|
+
* Safe to call with empty strings — they are skipped.
|
|
11
|
+
*/
|
|
12
|
+
export declare function sanitizeLog(message: string, ...sensitiveValues: string[]): string;
|
|
13
|
+
export declare class EmailPasswordCredentials implements CredentialProvider {
|
|
14
|
+
private _identifier;
|
|
15
|
+
private _password;
|
|
16
|
+
constructor(email: string, password: string);
|
|
17
|
+
provide(): {
|
|
18
|
+
identifier: string;
|
|
19
|
+
password: string;
|
|
20
|
+
};
|
|
21
|
+
/** Overwrite references so credentials are not retained in memory. */
|
|
22
|
+
zero(): void;
|
|
23
|
+
}
|
|
24
|
+
export declare function loadCredentialsFromEnv(): EmailPasswordCredentials;
|
|
25
|
+
//# sourceMappingURL=CredentialAbstraction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CredentialAbstraction.d.ts","sourceRoot":"","sources":["../../src/auth/CredentialAbstraction.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,kBAAkB;IACjC,OAAO,IAAI;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACpD,IAAI,IAAI,IAAI,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,eAAe,EAAE,MAAM,EAAE,GAAG,MAAM,CAQjF;AAED,qBAAa,wBAAyB,YAAW,kBAAkB;IACjE,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;gBAEd,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAK3C,OAAO,IAAI;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE;IAInD,sEAAsE;IACtE,IAAI,IAAI,IAAI;CAIb;AAED,wBAAgB,sBAAsB,IAAI,wBAAwB,CAMjE"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmailPasswordCredentials = void 0;
|
|
4
|
+
exports.sanitizeLog = sanitizeLog;
|
|
5
|
+
exports.loadCredentialsFromEnv = loadCredentialsFromEnv;
|
|
6
|
+
const errors_1 = require("../errors");
|
|
7
|
+
/**
|
|
8
|
+
* Replaces every occurrence of each sensitive value with [REDACTED].
|
|
9
|
+
* Safe to call with empty strings — they are skipped.
|
|
10
|
+
*/
|
|
11
|
+
function sanitizeLog(message, ...sensitiveValues) {
|
|
12
|
+
let result = message;
|
|
13
|
+
for (const value of sensitiveValues) {
|
|
14
|
+
if (value.length > 0) {
|
|
15
|
+
result = result.split(value).join('[REDACTED]');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
class EmailPasswordCredentials {
|
|
21
|
+
_identifier;
|
|
22
|
+
_password;
|
|
23
|
+
constructor(email, password) {
|
|
24
|
+
this._identifier = email;
|
|
25
|
+
this._password = password;
|
|
26
|
+
}
|
|
27
|
+
provide() {
|
|
28
|
+
return { identifier: this._identifier, password: this._password };
|
|
29
|
+
}
|
|
30
|
+
/** Overwrite references so credentials are not retained in memory. */
|
|
31
|
+
zero() {
|
|
32
|
+
this._identifier = '';
|
|
33
|
+
this._password = '';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.EmailPasswordCredentials = EmailPasswordCredentials;
|
|
37
|
+
function loadCredentialsFromEnv() {
|
|
38
|
+
const email = process.env['IQ_EMAIL'];
|
|
39
|
+
const password = process.env['IQ_PASSWORD'];
|
|
40
|
+
if (!email)
|
|
41
|
+
throw new errors_1.ValidationError('IQ_EMAIL environment variable is required');
|
|
42
|
+
if (!password)
|
|
43
|
+
throw new errors_1.ValidationError('IQ_PASSWORD environment variable is required');
|
|
44
|
+
return new EmailPasswordCredentials(email, password);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=CredentialAbstraction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CredentialAbstraction.js","sourceRoot":"","sources":["../../src/auth/CredentialAbstraction.ts"],"names":[],"mappings":";;;AAWA,kCAQC;AAsBD,wDAMC;AA/CD,sCAA4C;AAO5C;;;GAGG;AACH,SAAgB,WAAW,CAAC,OAAe,EAAE,GAAG,eAAyB;IACvE,IAAI,MAAM,GAAG,OAAO,CAAC;IACrB,KAAK,MAAM,KAAK,IAAI,eAAe,EAAE,CAAC;QACpC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAa,wBAAwB;IAC3B,WAAW,CAAS;IACpB,SAAS,CAAS;IAE1B,YAAY,KAAa,EAAE,QAAgB;QACzC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED,OAAO;QACL,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;IACpE,CAAC;IAED,sEAAsE;IACtE,IAAI;QACF,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,CAAC;CACF;AAlBD,4DAkBC;AAED,SAAgB,sBAAsB;IACpC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC5C,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,wBAAe,CAAC,2CAA2C,CAAC,CAAC;IACnF,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,wBAAe,CAAC,8CAA8C,CAAC,CAAC;IACzF,OAAO,IAAI,wBAAwB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MessageRouter } from '../transport/MessageRouter';
|
|
2
|
+
import type { CredentialProvider } from './CredentialAbstraction';
|
|
3
|
+
import type { SessionManager } from './SessionManager';
|
|
4
|
+
import type { IQProfile } from '../types/profile';
|
|
5
|
+
export declare class EmailPasswordAuth {
|
|
6
|
+
private readonly router;
|
|
7
|
+
private readonly session;
|
|
8
|
+
constructor(router: MessageRouter, session: SessionManager);
|
|
9
|
+
login(credentials: CredentialProvider): Promise<IQProfile>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=EmailPasswordAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmailPasswordAuth.d.ts","sourceRoot":"","sources":["../../src/auth/EmailPasswordAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,kBAAkB,CAAC;AAUhE,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;gBAE7B,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc;IAKpD,KAAK,CAAC,WAAW,EAAE,kBAAkB,GAAG,OAAO,CAAC,SAAS,CAAC;CAyBjE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmailPasswordAuth = void 0;
|
|
4
|
+
const CredentialAbstraction_1 = require("./CredentialAbstraction");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const V1Adapter_1 = require("../protocol/V1Adapter");
|
|
7
|
+
class EmailPasswordAuth {
|
|
8
|
+
router;
|
|
9
|
+
session;
|
|
10
|
+
constructor(router, session) {
|
|
11
|
+
this.router = router;
|
|
12
|
+
this.session = session;
|
|
13
|
+
}
|
|
14
|
+
async login(credentials) {
|
|
15
|
+
const { identifier, password } = credentials.provide();
|
|
16
|
+
try {
|
|
17
|
+
const response = await this.router.sendRequest(V1Adapter_1.V1Adapter.authorization, { identifier, password });
|
|
18
|
+
// The server either responds with a profile directly (success)
|
|
19
|
+
// or with an authorization result containing isSuccessful: false (failure).
|
|
20
|
+
const msg = response.msg;
|
|
21
|
+
if ('isSuccessful' in msg && msg['isSuccessful'] === false) {
|
|
22
|
+
const detail = typeof msg['message'] === 'string' ? msg['message'] : 'Invalid credentials';
|
|
23
|
+
throw new errors_1.AuthenticationError((0, CredentialAbstraction_1.sanitizeLog)(detail, password, identifier));
|
|
24
|
+
}
|
|
25
|
+
if (!('ssid' in msg) || typeof msg['ssid'] !== 'string') {
|
|
26
|
+
throw new errors_1.AuthenticationError('Unexpected authorization response from server');
|
|
27
|
+
}
|
|
28
|
+
return this.session.store(response.msg);
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
credentials.zero();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.EmailPasswordAuth = EmailPasswordAuth;
|
|
36
|
+
//# sourceMappingURL=EmailPasswordAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmailPasswordAuth.js","sourceRoot":"","sources":["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D,CAAC;gBAAS,CAAC;YACT,WAAW,CAAC,IAAI,EAAE,CAAC;QACrB,CAAC;IACH,CAAC;CACF;AAlCD,8CAkCC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AccountType } from '../types/primitives';
|
|
2
|
+
import type { ILogger } from '../types/logger';
|
|
3
|
+
import type { IQRawProfile, IQProfile } from '../types/profile';
|
|
4
|
+
export declare class SessionManager {
|
|
5
|
+
private profile;
|
|
6
|
+
private readonly logger;
|
|
7
|
+
constructor(logger: ILogger);
|
|
8
|
+
store(raw: IQRawProfile): IQProfile;
|
|
9
|
+
getProfile(): IQProfile;
|
|
10
|
+
switchAccount(type: AccountType): void;
|
|
11
|
+
clear(): void;
|
|
12
|
+
get isAuthenticated(): boolean;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=SessionManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionManager.d.ts","sourceRoot":"","sources":["../../src/auth/SessionManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAgBhE,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;gBAErB,MAAM,EAAE,OAAO;IAI3B,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,SAAS;IAOnC,UAAU,IAAI,SAAS;IAKvB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI;IAWtC,KAAK,IAAI,IAAI;IAIb,IAAI,eAAe,IAAI,OAAO,CAE7B;CACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SessionManager = void 0;
|
|
4
|
+
const primitives_1 = require("../types/primitives");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
function toProfile(raw, accountType) {
|
|
7
|
+
return {
|
|
8
|
+
ssid: raw.ssid,
|
|
9
|
+
userId: raw.user_id,
|
|
10
|
+
email: raw.email,
|
|
11
|
+
firstName: raw.first_name,
|
|
12
|
+
lastName: raw.last_name,
|
|
13
|
+
balance: raw.balance,
|
|
14
|
+
currency: raw.currency,
|
|
15
|
+
accountType,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
class SessionManager {
|
|
19
|
+
profile = null;
|
|
20
|
+
logger;
|
|
21
|
+
constructor(logger) {
|
|
22
|
+
this.logger = logger;
|
|
23
|
+
}
|
|
24
|
+
store(raw) {
|
|
25
|
+
const existing = this.profile;
|
|
26
|
+
const accountType = existing?.accountType ?? primitives_1.AccountType.Practice;
|
|
27
|
+
this.profile = toProfile(raw, accountType);
|
|
28
|
+
return this.profile;
|
|
29
|
+
}
|
|
30
|
+
getProfile() {
|
|
31
|
+
if (!this.profile)
|
|
32
|
+
throw new errors_1.AuthenticationError('Not authenticated');
|
|
33
|
+
return this.profile;
|
|
34
|
+
}
|
|
35
|
+
switchAccount(type) {
|
|
36
|
+
if (type === primitives_1.AccountType.Real) {
|
|
37
|
+
this.logger.warn('[IQOption SDK] WARNING: Switching to REAL account. All subsequent trades will use REAL MONEY.');
|
|
38
|
+
}
|
|
39
|
+
if (this.profile) {
|
|
40
|
+
this.profile = { ...this.profile, accountType: type };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
clear() {
|
|
44
|
+
this.profile = null;
|
|
45
|
+
}
|
|
46
|
+
get isAuthenticated() {
|
|
47
|
+
return this.profile !== null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.SessionManager = SessionManager;
|
|
51
|
+
//# sourceMappingURL=SessionManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sess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G,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;QACxD,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC;IAC/B,CAAC;CACF;AAtCD,wCAsCC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MessageRouter } from '../transport/MessageRouter';
|
|
2
|
+
import type { SessionManager } from './SessionManager';
|
|
3
|
+
import type { IQProfile } from '../types/profile';
|
|
4
|
+
export declare class SsidAuth {
|
|
5
|
+
private readonly router;
|
|
6
|
+
private readonly session;
|
|
7
|
+
constructor(router: MessageRouter, session: SessionManager);
|
|
8
|
+
restore(ssid: string): Promise<IQProfile>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=SsidAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SsidAuth.d.ts","sourceRoot":"","sources":["../../src/auth/SsidAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,kBAAkB,CAAC;AAShE,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;gBAE7B,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc;IAKpD,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;CAkBhD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SsidAuth = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const V1Adapter_1 = require("../protocol/V1Adapter");
|
|
6
|
+
class SsidAuth {
|
|
7
|
+
router;
|
|
8
|
+
session;
|
|
9
|
+
constructor(router, session) {
|
|
10
|
+
this.router = router;
|
|
11
|
+
this.session = session;
|
|
12
|
+
}
|
|
13
|
+
async restore(ssid) {
|
|
14
|
+
const response = await this.router.sendRequest(V1Adapter_1.V1Adapter.ssid, ssid);
|
|
15
|
+
const msg = response.msg;
|
|
16
|
+
if ('isSuccessful' in msg && msg['isSuccessful'] === false) {
|
|
17
|
+
throw new errors_1.AuthenticationError('SESSION_EXPIRED');
|
|
18
|
+
}
|
|
19
|
+
if (!('ssid' in msg) || typeof msg['ssid'] !== 'string') {
|
|
20
|
+
throw new errors_1.AuthenticationError('SESSION_EXPIRED');
|
|
21
|
+
}
|
|
22
|
+
return this.session.store(response.msg);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.SsidAuth = SsidAuth;
|
|
26
|
+
//# sourceMappingURL=SsidAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SsidAuth.js","sourceRoot":"","sources":["../../src/auth/SsidAuth.ts"],"names":[],"mappings":";;;AAGA,sCAAgD;AAChD,qDAAkD;AAOlD,MAAa,QAAQ;IACF,MAAM,CAAgB;IACtB,OAAO,CAAiB;IAEzC,YAAY,MAAqB,EAAE,OAAuB;QACxD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAY;QACxB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAC5C,qBAAS,CAAC,IAAI,EACd,IAAI,CACL,CAAC;QAEF,MAAM,GAAG,GAAG,QAAQ,CAAC,GAA8B,CAAC;QAEpD,IAAI,cAAc,IAAI,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,KAAK,KAAK,EAAE,CAAC;YAC3D,MAAM,IAAI,4BAAmB,CAAC,iBAAiB,CAAC,CAAC;QACnD,CAAC;QAED,IAAI,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,QAAQ,EAAE,CAAC;YACxD,MAAM,IAAI,4BAAmB,CAAC,iBAAiB,CAAC,CAAC;QACnD,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAmB,CAAC,CAAC;IAC1D,CAAC;CACF;AA3BD,4BA2BC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ILogger } from '../types/logger';
|
|
2
|
+
import type { IQProfile } from '../types/profile';
|
|
3
|
+
import type { IQAsset, IQCandle, IQTick } from '../types/market-data';
|
|
4
|
+
import type { IQPosition, BuyBinaryOptionParams, BuyDigitalOptionParams, BinaryOptionResult, DigitalOptionResult } from '../types/trading';
|
|
5
|
+
import type { TimeFrame } from '../types/primitives';
|
|
6
|
+
export interface IQOptionClientOptions {
|
|
7
|
+
url?: string;
|
|
8
|
+
logger?: ILogger;
|
|
9
|
+
silent?: boolean;
|
|
10
|
+
requestTimeoutMs?: number;
|
|
11
|
+
maxReconnectRetries?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare class IQOptionClient {
|
|
14
|
+
private readonly transport;
|
|
15
|
+
private readonly router;
|
|
16
|
+
private readonly reconnection;
|
|
17
|
+
private readonly session;
|
|
18
|
+
private readonly emailAuth;
|
|
19
|
+
private readonly ssidAuth;
|
|
20
|
+
private readonly catalog;
|
|
21
|
+
private readonly historical;
|
|
22
|
+
private readonly candleStream;
|
|
23
|
+
private readonly tickStream;
|
|
24
|
+
private readonly orderCache;
|
|
25
|
+
private readonly binaryOptions;
|
|
26
|
+
private readonly digitalOptions;
|
|
27
|
+
private readonly orderHistory;
|
|
28
|
+
constructor(options?: IQOptionClientOptions);
|
|
29
|
+
connect(): Promise<void>;
|
|
30
|
+
disconnect(): void;
|
|
31
|
+
login(credentials: {
|
|
32
|
+
email: string;
|
|
33
|
+
password: string;
|
|
34
|
+
}): Promise<IQProfile>;
|
|
35
|
+
restoreSession(ssid: string): Promise<IQProfile>;
|
|
36
|
+
getProfile(): IQProfile;
|
|
37
|
+
getAllAssets(): IQAsset[];
|
|
38
|
+
getOpenAssets(): IQAsset[];
|
|
39
|
+
getOtcAssets(): IQAsset[];
|
|
40
|
+
getNonOtcAssets(): IQAsset[];
|
|
41
|
+
getAsset(symbol: string): IQAsset | undefined;
|
|
42
|
+
getCandles(symbol: string, timeframe: TimeFrame, count: number, endTime?: number): Promise<IQCandle[]>;
|
|
43
|
+
subscribeCandles(symbol: string, timeframe: TimeFrame, callback: (c: IQCandle) => void): void;
|
|
44
|
+
unsubscribeCandles(symbol: string, timeframe: TimeFrame): void;
|
|
45
|
+
subscribeQuotes(symbol: string, callback: (t: IQTick) => void): void;
|
|
46
|
+
unsubscribeQuotes(symbol: string): void;
|
|
47
|
+
buyBinaryOption(params: BuyBinaryOptionParams): Promise<{
|
|
48
|
+
orderId: string;
|
|
49
|
+
}>;
|
|
50
|
+
checkBinaryOptionResult(orderId: string, timeoutMs?: number): Promise<BinaryOptionResult>;
|
|
51
|
+
buyDigitalOption(params: BuyDigitalOptionParams): Promise<{
|
|
52
|
+
orderId: string;
|
|
53
|
+
}>;
|
|
54
|
+
checkDigitalOptionResult(orderId: string, timeoutMs?: number): Promise<DigitalOptionResult>;
|
|
55
|
+
getOpenPositions(): IQPosition[];
|
|
56
|
+
getClosedPositions(limit?: number): IQPosition[];
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=IQOptionClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IQOptionClient.d.ts","sourceRoot":"","sources":["../../src/client/IQOptionClient.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,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