Skip to content

Commit

Permalink
add some samples
Browse files Browse the repository at this point in the history
  • Loading branch information
franck34 committed May 4, 2024
1 parent 756e7a8 commit f5b8c8e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
51 changes: 51 additions & 0 deletions HOWTO.md
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)
```
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Unofficial [IG Trading API](https://labs.ig.com/rest-trading-api-guide) for Node
- **Tested.** Code coverage is 100%. No surprises when using [ig-trading-api][1].
- **Maintained.** Automated security updates. No threats from outdated dependencies.
- **Documented.** Get started with the [generated documentation][2].
- **Samples.** Get started with [some "HowTos"][3].

## Installation

Expand Down Expand Up @@ -107,5 +108,6 @@ This project is [MIT](./LICENSE) licensed.

[1]: https://www.npmjs.com/package/ig-trading-api
[2]: https://bennycode.com/ig-trading-api
[3]: https://github.com/bennycode/ig-trading-api/blob/main/HOWTO.md
[stack_exchange_bennyn_badge]: https://stackexchange.com/users/flair/203782.png?theme=default
[stack_exchange_bennyn_url]: https://stackexchange.com/users/203782/benny-neugebauer?tab=accounts

0 comments on commit f5b8c8e

Please sign in to comment.