Skip to content

Commit 7cf25f6

Browse files
authored
docs: Add template for environment variables used in demo scripts (#208)
1 parent c9f863d commit 7cf25f6

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

.env.defaults

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Instructions:
2+
# 1) Copy this file to the root of this repository and name it ".env"
3+
# 2) Enter your API keys in the ".env" file
4+
# 3) Now your API keys can be used by "init-client.ts" from the "src/demo" directory
5+
# 4) You can test it by running: npx ts-node ./src/demo/dump-candles.ts
6+
# 5) Alternatively, you can run: yarn demo:candles
7+
8+
# Set to "false" if you want to use your production API key
9+
USE_SANDBOX="true"
10+
11+
# Your sandbox API key from: https://public.sandbox.pro.coinbase.com/profile/api
12+
COINBASE_PRO_SANDBOX_API_KEY=""
13+
COINBASE_PRO_SANDBOX_API_SECRET=""
14+
COINBASE_PRO_SANDBOX_PASSPHRASE=""
15+
16+
# Your production API key from: https://pro.coinbase.com/profile/api
17+
COINBASE_PRO_API_KEY=""
18+
COINBASE_PRO_API_SECRET=""
19+
COINBASE_PRO_PASSPHRASE=""

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ If you want to listen to WebSocket messages, have a look at these demo scripts:
8787

8888
### Demos
8989

90-
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).
90+
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/tree/v8.2.0#usage) used in [init-client.ts](https://github.com/bennyn/coinbase-pro-node/blob/master/src/demo/init-client.ts).
9191

9292
```bash
9393
npx ts-node ./src/demo/dump-candles.ts
9494
```
9595

96+
**Tip:** There is a [.env.defaults](https://github.com/bennyn/coinbase-pro-node/blob/master/.env.defaults) file which serves as a template. Just remove its `.defaults` extension and enter your credentials to get started. Do not commit this file (or your credentials) to any repository!
97+
9698
### Real-world examples
9799

98100
Checkout [GitHub's dependency graph][6] to see who uses "coinbase-pro-node" in production. There are also [npm packages][7] depending on "coinbase-pro-node".

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@typescript-eslint/eslint-plugin": "3.6.0",
2020
"@typescript-eslint/parser": "3.6.0",
2121
"cross-env": "7.0.2",
22-
"dotenv": "8.2.0",
22+
"dotenv-defaults": "2.0.0",
2323
"eslint": "7.4.0",
2424
"eslint-config-prettier": "6.11.0",
2525
"eslint-plugin-prettier": "3.1.4",
@@ -77,6 +77,7 @@
7777
"changelog:commit": "git add CHANGELOG.md && git commit -m \"docs: Updated changelog\"",
7878
"clean": "rimraf .nyc_output coverage dist",
7979
"demo": "cross-env NODE_DEBUG=coinbase-pro-node* ts-node src/demo/rest-get-candles.ts",
80+
"demo:candles": "cross-env NODE_DEBUG=coinbase-pro-node* ts-node src/demo/dump-candles.ts",
8081
"demo:ws": "cross-env NODE_DEBUG=coinbase-pro-node* ts-node src/demo/websocket-ticker.ts",
8182
"docs": "yarn docs:build && yarn docs:start",
8283
"docs:build": "yarn typedoc",

src/demo/init-client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {CoinbasePro} from '..';
22

3-
require('dotenv').config();
3+
import 'dotenv-defaults/config';
44

55
export function initClient(): CoinbasePro {
66
if (process.env.USE_SANDBOX === 'true') {

yarn.lock

+8-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,14 @@ doctrine@^3.0.0:
700700
dependencies:
701701
esutils "^2.0.2"
702702

703-
dotenv@8.2.0:
703+
dotenv-defaults@2.0.0:
704+
version "2.0.0"
705+
resolved "https://registry.npmjs.org/dotenv-defaults/-/dotenv-defaults-2.0.0.tgz#f48577d885c7755d2a4ce1f7f3706552c0cb367e"
706+
integrity sha512-8X8gQoM+BH0L/v+GwgpeNwrthbG2uTDVr3vkbedQPLrIalZE0vxB9LbuD+7echbiP7fAY3tE+pZI11R1DtlUNg==
707+
dependencies:
708+
dotenv "^8.2.0"
709+
710+
dotenv@^8.2.0:
704711
version "8.2.0"
705712
resolved "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
706713
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==

0 commit comments

Comments
 (0)