|
| 1 | +# Coinbase Advanced API TypeScript SDK |
| 2 | + |
| 3 | +Welcome to the Coinbase Advanced API TypeScript SDK. This TypeScript project was created to allow developers to easily plug into the [Coinbase Advanced API](https://docs.cdp.coinbase.com/advanced-trade/docs/welcome). |
| 4 | + |
| 5 | +Coinbase Advanced Trade offers a comprehensive API for traders, providing access to real-time market data, order management, and execution. Elevate your trading strategies and develop sophisticated solutions using our powerful tools and features. |
| 6 | + |
| 7 | +For more information on all the available REST endpoints, see the [API Reference](https://docs.cdp.coinbase.com/advanced-trade/reference/). |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +```bash |
| 14 | +npm install |
| 15 | +``` |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Build and Use |
| 20 | + |
| 21 | +To build the project, run the following command: |
| 22 | + |
| 23 | +```bash |
| 24 | +npm run build |
| 25 | +``` |
| 26 | + |
| 27 | +_Note: To avoid potential issues, do not forget to build your project again after making any changes to it._ |
| 28 | + |
| 29 | +After building the project, each `.ts` file will have its `.js` counterpart generated. |
| 30 | + |
| 31 | +To run a file, use the following command: |
| 32 | + |
| 33 | +``` |
| 34 | +node dist/{INSERT-FILENAME}.js |
| 35 | +``` |
| 36 | + |
| 37 | +For example, a `main.ts` file would be run like: |
| 38 | + |
| 39 | +```bash |
| 40 | +node dist/main.js |
| 41 | +``` |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +## Coinbase Developer Platform (CDP) API Keys |
| 46 | + |
| 47 | +This SDK uses Cloud Developer Platform (CDP) API keys. To use this SDK, you will need to create a CDP API key and secret by following the instructions [here](https://docs.cdp.coinbase.com/advanced-trade/docs/getting-started). |
| 48 | +Make sure to save your API key and secret in a safe place. You will not be able to retrieve your secret again. |
| 49 | + |
| 50 | +--- |
| 51 | + |
| 52 | +## Importing the RESTClient |
| 53 | + |
| 54 | +All the REST endpoints are available directly from the client, therefore it's all you need to import. |
| 55 | + |
| 56 | +``` |
| 57 | +import { RESTClient } from './rest'; |
| 58 | +``` |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## Authentication |
| 63 | + |
| 64 | +Authentication of CDP API Keys is handled automatically by the SDK when making a REST request. |
| 65 | + |
| 66 | +After creating your CDP API keys, store them using your desired method and simply pass them into the client during initialization like: |
| 67 | + |
| 68 | +``` |
| 69 | +const client = new RESTClient(API_KEY, API_SECRET); |
| 70 | +``` |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## Making Requests |
| 75 | + |
| 76 | +Here are a few examples requests: |
| 77 | + |
| 78 | +**[List Accounts](https://docs.cdp.coinbase.com/advanced-trade/reference/retailbrokerageapi_getaccounts)** |
| 79 | + |
| 80 | +``` |
| 81 | +client |
| 82 | + .listAccounts({}) |
| 83 | + .then((result) => { |
| 84 | + console.log(result); |
| 85 | + }) |
| 86 | + .catch((error) => { |
| 87 | + console.error(error.message); |
| 88 | + }); |
| 89 | +``` |
| 90 | + |
| 91 | +**[Get Product](https://docs.cdp.coinbase.com/advanced-trade/reference/retailbrokerageapi_getproduct)** |
| 92 | + |
| 93 | +``` |
| 94 | +client |
| 95 | + .getProduct({productId: "BTC-USD"}) |
| 96 | + .then((result) => { |
| 97 | + console.log(result); |
| 98 | + }) |
| 99 | + .catch((error) => { |
| 100 | + console.error(error.message); |
| 101 | + }); |
| 102 | +``` |
| 103 | + |
| 104 | +**[Create Order](https://docs.cdp.coinbase.com/advanced-trade/reference/retailbrokerageapi_postorder)** |
| 105 | + |
| 106 | +_$10 Market Buy on BTC-USD_ |
| 107 | + |
| 108 | +``` |
| 109 | +client |
| 110 | + .createOrder({ |
| 111 | + clientOrderId: "00000001", |
| 112 | + productId: "BTC-USD", |
| 113 | + side: OrderSide.BUY, |
| 114 | + orderConfiguration:{ |
| 115 | + market_market_ioc: { |
| 116 | + quote_size: "10" |
| 117 | + } |
| 118 | + } |
| 119 | + }) |
| 120 | + .then((result) => { |
| 121 | + console.log(result); |
| 122 | + }) |
| 123 | + .catch((error) => { |
| 124 | + console.error(error.message); |
| 125 | + }); |
| 126 | +``` |
0 commit comments