iqoption
Real-time forex data using IQ Option WebSocket API.

npm i iqoption
Disclaimer: do not use real money with this library.
https://iqoption.com/en/register
Usage
const Broker = require('iqoption')
const broker = new Broker({
email: 'example@gmail.com',
password: 'secret123'
})
await broker.login()
console.log('ssid', broker.ssid)
await broker.connect()
console.log('user_id', broker.profile.user_id)
console.log('balance_id', broker.profile.balance_id)
console.log('balances', broker.balances)
console.log('balance IDs', broker.balances.map(b => b.id))
await broker.subscribe('candle-generated', { active_id: 76, size: 1 })
broker.on('candle-generated', function (tick) {
console.log(tick)
})
Note: All the names, returned values, etc are originally from the WebSocket.
broker.balances
is automatically updated on background.
broker.trading.profits
is also updated on background and used internally.
SSID
Connect without login.
const broker = new Broker({
ssid: 'abcd1234b4c0d1dc9d60e824b3cb71c0'
})
await broker.connect()
BigInt
There is a bigInt
option available when creating a new Broker
instance.
For example, the tick.at
is losing precision at the last two digits.
bigInt: false
: parse big integers as normal numbers losing precision (default).
bigInt: 'string'
: parse big integers as string (this is a good option too).
const broker = new Broker({
...,
bigInt: 'string'
})
broker.on('candle-generated', function (tick) {
console.log(tick)
})
Open trades
I recommend reading test.js
where there is multiple examples.
const practiceBalance = broker.balances.find(b => b.type === 4)
const option = await broker.send('binary-options.open-option', {
user_balance_id: practiceBalance.id,
active_id: 76,
option_type_id: 3,
direction: 'call',
expired: 1,
price: 5,
returnMessage: true
})
if (option.message) {
throw new Error(option.message)
}
console.log(option)
Note: broker.trading.expiration
is used to calculate expired
for turbo-option
so you only set a range of 1-5.
Sell the option:
const sold = await broker.send('sell-options', { options_ids: [option.id], returnMessage: true })
if (sold.error) {
throw new Error(sold.error)
}
console.log(sold)
You can also let it close by itself.
Get traders mood
const mood = await broker.send('get-traders-mood', { instrument: 'turbo-option', asset_id: 1, returnMessage: true })
send()
Every time you send a message, there is normally two responses back:
- A success confirmation
- The actual data response
Let's say you found a command but not need to wait for the response:
returnResult
in true
will track and wait for the confirmation based on the automatic request_id
.
returnMessage
in true
will track and wait for a response based on the automatic request_id
.
Otherwise you would have to track all the messages from the WebSocket, etc.
The default is false
for both.
const result = await broker.send('my-magic-command', { returnResult: true })
I think there is no subscription that have a message response.
So don't use returnMessage
in true with subscriptions.
Assets
At the moment assets are fetch from an outdated file.
const Broker = require('iqoption')
const assets = Broker.assets()
console.log(assets[1].name)
const asset1 = Broker.assets('EUR/USD (OTC)')
console.log(asset1.active_id)
const asset2 = Broker.assets(76)
console.log(asset2.name)
Handle semi-raw messages or subscriptions
You can inspect the WebSocket from the traderoom of IQ Option.
Maybe you're interested in sending a message not supported by the library.
Normally when sending a message, the data looks like this:
{
name: 'sendMessage',
request_id: '15',
local_time: 123,
msg: {
...
}
}
The library tries to automatically handle common operations like this:
await broker.send('sell-options', { options_ids: [option.id] })
The "raw" equivalent would be:
const option = await broker.send({
name: 'sell-options',
version: '3.0',
body: {
options_ids: [option.id]
}
})
The sell-options
message might not be that complicated.
But the library still autocompleting the request_id
, local_time
, etc.
There is too many commands, three different versions, too many data structures, etc.
Be aware that the IQ Option WebSocket is not documented and doesn't have guarantees.
The same applies for subscribe()
and unsubscribe()
.
Also, if you want to listen to all the messages from the WebSocket:
broker.on('all', function (data) {
console.log(data)
})
I recommend reading the first tests of test.js
for more events.
Send raw messages or subscriptions
broker.ws.json({
name: 'the-command-name',
request_id: broker.newRequestId(false),
local_time: broker.localTime(),
msg: { ... }
})
License
MIT