Skip to content

Commit

Permalink
docs: add code samples (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
franck34 authored May 9, 2024
1 parent 4fdb71e commit af0db98
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,38 @@ const client = new APIClient(APIClient.URL_LIVE, {
});
```

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));
```

Show available resolutions
```
import { APIClient, Resolution } from 'ig-trading-api';
console.log(Resolution)
```
## Resources

- [IG REST Trading API Reference](https://labs.ig.com/rest-trading-api-reference)
Expand Down

0 comments on commit af0db98

Please sign in to comment.