Skip to content

Commit

Permalink
docs: Explain demo scripts (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode authored May 4, 2020
1 parent ea0f8cc commit 86fe9a6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Motivation

The purpose of "coinbase-pro-node" is to continue an active **Coinbase Pro API** after Coinbase deprecated the official Node.js library on [January, 16 2020](https://github.com/coinbase/coinbase-node/issues/140#issuecomment-574990136). The official predecessor got deprecated on [July, 19th 2016](https://github.com/coinbase/coinbase-exchange-node/commit/b8347efdb4e2589367c1395b646d283c9c391681).
The purpose of [coinbase-pro-node][5] is to continue an active **Coinbase Pro API** after Coinbase deprecated the official Node.js library on [January, 16 2020](https://github.com/coinbase/coinbase-node/issues/140#issuecomment-574990136). Its predecessor got deprecated on [July, 19th 2016](https://github.com/coinbase/coinbase-exchange-node/commit/b8347efdb4e2589367c1395b646d283c9c391681).

## Features

Expand Down Expand Up @@ -53,7 +53,7 @@ const client = new CoinbasePro();

The [demo section][3] provides many examples on how to use "coinbase-pro-node". There is also an automatically generated [API documentation][4]. For a quick start, here is a simple example for a REST request:

**REST Example**
### REST example

```typescript
import {CoinbasePro} from 'coinbase-pro-node';
Expand All @@ -78,35 +78,38 @@ client.rest.account.listAccounts().then(accounts => {
});
```

**WebSocket Examples**
### WebSocket example

If you want to listen to WebSocket messages, have a look at these demo scripts:

- [Subscribe to "ticker" channel (real-time price updates)](https://github.com/bennyn/coinbase-pro-node/blob/master/src/demo/websocket-ticker.ts)
- [Subscribe to authenticated "user" channel](https://github.com/bennyn/coinbase-pro-node/blob/master/src/demo/websocket-user.ts)

**Real World Examples**
### Demos

You can checkout [GitHub's dependency graph][6] to see who is using "coinbase-pro-node".
All [demo scripts][3] are executable from the root directory. If you want to use specific credentials with a demo script, simply add a `.env` file to the root of this package to [modify environment variables](https://github.com/motdotla/dotenv#usage) used in [init-client.ts](https://github.com/bennyn/coinbase-pro-node/blob/master/src/demo/init-client.ts).

## Resources
```bash
npx ts-node ./src/demo/dump-candles.ts
```

- [Coinbase Pro API Reference][2]
- [coinbase-pro-node API docs][4]
- [coinbase-pro-node npm page][5]
- [coinbase-pro-node users][6]
### Real-world examples

Checkout [GitHub's dependency graph][6] to see who uses "coinbase-pro-node" in production.

## Contributing

Contributions, issues and feature requests are welcome!

Feel free to check [issues page](https://github.com/bennyn/coinbase-pro-node/issues).
Feel free to check the [issues page](https://github.com/bennyn/coinbase-pro-node/issues).

The following commits will help you getting started quickly with the code base:

- [Add REST API endpoint](https://github.com/bennyn/coinbase-pro-node/commit/9920c2f4343985c349b68e2a47d7fe2c42e23e34)
- [Add REST API endpoint (with fixtures)](https://github.com/bennyn/coinbase-pro-node/commit/8a150fecb7d32b7b7cd39a8109985f665aaee26e)

All resources can be found in the [Coinbase Pro API reference][2].

## Maintainers

[![Benny Neugebauer on Stack Exchange][stack_exchange_bennyn_badge]][stack_exchange_bennyn_url]
Expand Down
29 changes: 29 additions & 0 deletions src/demo/dump-candles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {initClient} from './init-client';
import {CandleGranularity} from '..';
import fs from 'fs';
import path from 'path';

async function main(): Promise<void> {
const client = initClient();

const productId = 'BTC-USD';
const begin = '2020-04-11T00:00:00.000Z';
const end = '2020-04-11T10:00:00.000Z';
const granularity = CandleGranularity.ONE_HOUR;
const directory = __dirname;

const candles = await client.rest.product.getCandles(productId, {
end,
granularity,
start: begin,
});

const start = candles[0].openTimeInMillis;
const file = path.join(directory, `${productId}-${start}-${granularity}.json`);

fs.writeFileSync(file, JSON.stringify(candles, null, 2));

console.info(`Dumped "${candles.length}" candles in file "${file}".`);
}

main().catch(console.error);

0 comments on commit 86fe9a6

Please sign in to comment.