-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# HOWTO | ||
|
||
## Prerequisites | ||
|
||
Before using theses samples, you have to authenticate first. | ||
``` | ||
// Note that we import "Resolution" too | ||
import { APIClient, Resolution } from 'ig-trading-api'; | ||
// Create a client instance | ||
const client = new APIClient(APIClient.URL_LIVE, process.env.IG_API_KEY); | ||
// Let's log in | ||
const session = await client.rest.login.createSession(process.env.IG_IDENTIFIER, process.env.IG_PASSWORD); | ||
``` | ||
|
||
## Search for an IG epic code | ||
|
||
``` | ||
const response = await client.rest.market.searchMarkets('BITCOIN'); | ||
console.log(JSON.stringify(response, null, 4)); | ||
console.log(response.markets[0].epic); | ||
``` | ||
|
||
## Subscribe to realtime candles updates with IG epic codes | ||
|
||
``` | ||
const epics = [ | ||
'CS.D.BITCOIN.OPTCALL.IP' | ||
]; | ||
client.stream.subscribeCandles(epics, Resolution.SECOND, (epic, candle) => { | ||
console.log(epic); | ||
console.log(candle) | ||
}); | ||
``` | ||
|
||
|
||
## Retrieve historical data of an IG epic code | ||
|
||
``` | ||
const prices = await client.rest.market.price.getPrices('CS.D.BITCOIN.OPTCALL.IP', Resolution.DAY, 5); | ||
console.log(JSON.stringify(prices, null, 4)); | ||
``` | ||
|
||
|
||
## Available resolutions | ||
``` | ||
console.log(Resolution) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters