Coinbase TypeScript SDK example: cbapp-public-rest-all.ts
Coinbase Coinbase App Public cbapp public REST all example for the Siebly Coinbase SDK, with TypeScript source for exchange REST API and WebSocket integration, setup, and production SDK docs.
What This Example Covers
- Coinbase exchange API example in TypeScript.
- Uses the Siebly Coinbase SDK package
coinbase-apiinstead of hand-written HTTP request plumbing. - Source path:
Coinbase/CoinbaseApp/Public/cbapp-public-rest-all.ts. - Example category: Coinbase App Public.
- Imports SDK symbols including
CBAppClient. - Calls SDK methods such as
getFiatCurrencies(),getCryptocurrencies(),getExchangeRates(),getBuyPrice(),getSellPrice(),getSpotPrice(),getCurrentTime().
How To Use This Example
- Start here for the specific request or stream pattern, then check the matching SDK guide for install, credentials, and operational notes.
- Open the repository source when you need the latest committed version: GitHub source file.
Example Path
Coinbase/CoinbaseApp/Public/cbapp-public-rest-all.ts
Source Link
Repository source: https://github.com/sieblyio/crypto-api-examples/blob/master/examples/Coinbase/CoinbaseApp/Public/cbapp-public-rest-all.ts
Related SDK Docs
Example Source
import { CBAppClient } from 'coinbase-api';
// Initialize the client, you can pass in api keys here if you have them but they are not required for public endpoints
const client = new CBAppClient();
async function publicCalls() {
try {
// Get fiat currencies
const fiatCurrencies = await client.getFiatCurrencies();
console.log('Fiat Currencies: ', fiatCurrencies);
// Get cryptocurrencies
const cryptocurrencies = await client.getCryptocurrencies();
console.log('Cryptocurrencies: ', cryptocurrencies);
// Get exchange rates
const exchangeRates = await client.getExchangeRates({ currency: 'USD' });
console.log('Exchange Rates: ', exchangeRates);
// Get buy price
const buyPrice = await client.getBuyPrice({ currencyPair: 'BTC-USD' });
console.log('Buy Price: ', buyPrice);
// Get sell price
const sellPrice = await client.getSellPrice({ currencyPair: 'BTC-USD' });
console.log('Sell Price: ', sellPrice);
// Get spot price
const spotPrice = await client.getSpotPrice({ currencyPair: 'BTC-USD' });
console.log('Spot Price: ', spotPrice);
// Get current time
const currentTime = await client.getCurrentTime();
console.log('Current Time: ', currentTime);
} catch (e) {
console.error('Error: ', e);
}
}
publicCalls();