https://github.com/coinbase-samples/exchange-sdk-ts
TypeScript SDK for the Coinbase Exchange REST APIs
https://github.com/coinbase-samples/exchange-sdk-ts
coinbase exchange javascript typescript
Last synced: 5 months ago
JSON representation
TypeScript SDK for the Coinbase Exchange REST APIs
- Host: GitHub
- URL: https://github.com/coinbase-samples/exchange-sdk-ts
- Owner: coinbase-samples
- License: other
- Created: 2025-05-14T22:47:10.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-30T23:06:17.000Z (8 months ago)
- Last Synced: 2025-10-08T08:37:19.167Z (8 months ago)
- Topics: coinbase, exchange, javascript, typescript
- Language: TypeScript
- Homepage: https://docs.cdp.coinbase.com/exchange/reference/introduction
- Size: 189 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Coinbase Exchange API TypeScript SDK
## Overview
Welcome to the Coinbase Exchange API TypeScript SDK. This TypeScript project was created to allow developers to easily plug into the [Coinbase Exchange API](https://docs.cdp.coinbase.com/exchange/docs/welcome).
---
## Installation
```bash
npm install @coinbase-sample/exchange-sdk-ts
```
## License
The _Exchange Typescript SDK_ sample library is free and open source and released under the [Apache License, Version 2.0](LICENSE).
The application and code are only available for demonstration purposes.
## Usage
Here are a few examples requests:
**Configure Credentials**
```
const creds = JSON.parse(process.env.EXCHANGE_CREDENTIALS);
const credentials = new CoinbaseExchangeCredentials(
creds.AccessKey,
creds.SecretKey,
creds.Passphrase
);
const client = new CoinbaseExchangeClient(credentials);
```
**[List Orders]https://docs.cdp.coinbase.com/exchange/reference/exchangerestapi_getorders)**
```
const service = new OrdersService(client);
service
.listOrders()
.then((orders) => {
console.log(orders);
})
.catch(console.error);
```
**[Get Trading Pairs](https://docs.cdp.coinbase.com/exchange/reference/exchangerestapi_getproducts)**
```
const service = new ProductsService(client);
service
.listTradingPairs({entityId: "somePortfolioId"})
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error.message);
});
```
**[Create Order](https://docs.cdp.coinbase.com/exchange/reference/exchangerestapi_postorders)**
_$10 Market Buy on BTC-USD_
```
client
.createOrder({
portfolioId: "somePortfolioId",
productId: "BTC-USD",
side: OrderSide.BUY,
type: OrderType.Market,
baseQuantity: "0.0001"
})
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error.message);
});
```
## Development Installation
```bash
npm install
```
---
## Build and Use
To build the project, run the following command:
```bash
npm run build
```
_Note: To avoid potential issues, do not forget to build your project again after making any changes to it._
After building the project, each `.ts` file will have its `.js` counterpart generated.
To run a file, use the following command:
```
node dist/{INSERT-FILENAME}.js
```
For example, a `main.ts` file would be run like:
```bash
node dist/main.js
```
---