From f8c75ef291941f1940355f814bebe1dd7e53080d Mon Sep 17 00:00:00 2001 From: franck34 Date: Wed, 8 May 2024 14:00:55 +0200 Subject: [PATCH] add code sample un README file --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index 5a71f0a6..2d997f92 100644 --- a/README.md +++ b/README.md @@ -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)