Coinbase Logo

Language and region

Introducing the Coinbase Advanced TypeScript SDK

TL;DR: The Advanced Trade TypeScript SDK is a flexible sample application that allows customers to automate their crypto trading strategies on Coinbase Advanced. The SDK is built on top of Coinbase Advanced REST APIs and simplifies the development process, enabling traders and developers to integrate advanced crypto trading functionalities with ease.

By Lisa Mohanty, David Mkrtchyan

, September 17, 2024

unnamed (24).png

Coinbase Advanced empowers traders with a range of tools and features that deliver substantial advantages, including integrated TradingView charts, real-time order books, enhanced order reporting, and reduced volume-based fees. The Advanced Trade API extends these functionalities, enabling traders and developers to create custom crypto trading solutions tailored to their specific needs. However, integrating these robust APIs into custom applications can often be a time-consuming process. By popular demand, our first official Python SDK was launched to simplify and expedite the integration process for Python developers.

Today, we are excited to announce the launch of our community-based Advanced Trade TypeScript SDK. In this blog post, we will explore its design and usage, highlighting how this sample application aims to simplify the integration process. Similar to the Python SDK, the Typescript SDK will enhance the overall developer experience by providing a clear framework and reducing the complexity of building on top of the Advanced Trade API.

Functionality

The Advanced Trade TypeScript SDK streamlines integration with the Advanced Trade API, making it easier to use Coinbase Advanced features. The SDK supports a wide range of functionalities, including:

  • Market Data Access: Retrieve real-time market data, historical data, and order book details 

  • Order Management: Place, modify, and cancel orders programmatically for automated trading 

  • Account Management: Access account information, including balances, order history, and positions

  • Portfolio Management: Manage multiple portfolios, including the ability to create, update, and delete portfolios

  • International Exchange (INTX) support: Access exclusive instruments for retail users onboarded to Coinbase International Exchange

Built with strong typing, the SDK provides custom request and response objects for each API endpoint, simplifying API interactions and error handling. Comprehensive documentation and consistent methods make it easy to learn and accelerate development.

High-level Architecture

The application features a streamlined architecture with a clear design. Each API endpoint maps to a specific SDK method responsible for crafting requests, sending them, and processing responses.

Key components include:

  • HTTP Communication: Manages interactions with the Advanced Trade API, including GET, POST, PUT, DELETE requests, JWT token authentication, and session handling

  • Client Initialization: Sets up and configures the client for API requests, establishing the necessary connection

  • Endpoint Handlers: Each endpoint has a handler that integrates request and response structures, defining parameters and capturing returned data

  • Model: Provides typed request and response structures for trading entities like assets and orders, offering a type-safe interface

  • Utilities: Includes helper functions for common tasks such as pagination

The Advanced Trade TypeScript SDK is designed for flexibility and easy extension, allowing developers to add new endpoints and features with minimal effort.

Making Your First Trade

To use the Advanced Trade Typescript SDK, first start by creating API keys. Once finished, import the RESTClient and then initialize it by passing in your API keys. Here is this would look:

import { RESTClient } from './rest';
const client = new RESTClient("INSERT_API_KEY", "INSERT_API_SECRET");

Once the client is initialized, you are ready to make your first call. In the provided example, we place a 10 USD Market Buy order on BTC-USD. To do so, we will make a request to the Create Order endpoint. Request and response objects are defined for all endpoints, so developers should have an easier time making requests and interacting with responses that get returned from them.

This endpoints uses the CreateOrderRequest object, in which there are 4 required fields:

  • clientOrderId: Provide a unique ID for this order

  • productId: The product you want to place the order for. In this case, it’s BTC-USD

  • side: Indicate whether you want to BUY or SELL this product. Import the OrderSide enum type and set it to either OrderSide.BUY or OrderSide.SELL

  • orderConfiguration: The details of the order. In this case, we are placing a Market order, so it only requires the size of the quote currency (USD)

After we provide the necessary fields, we send the request. If successful, it will return a CreateOrderResponse object and print it; otherwise, we print the error message that is returned instead.

import { RESTClient } from './rest';
import { OrderSide } from './rest/types/common-types';
import {
CreateOrderRequest,
CreateOrderResponse,
} from './rest/types/orders-types';
const client = new RESTClient('INSERT_API_KEY', 'INSERT_API_SECRET');
client
.createOrder({
clientOrderId: '00000001',
productId: '
BTC
-USD',
side: OrderSide.BUY,
orderConfiguration: {
market_market_ioc: {
quote_size: '10',
},
},
} as CreateOrderRequest)
.then((result) => {
console.log(result as CreateOrderResponse);
})
.catch((error) => {
console.error(error.message);
});

Refer to the API Reference for information about other endpoints.

The Advanced Trade TypeScript SDK simplifies integrating advanced trading features into applications by abstracting the Advanced Trade API's complexities. It offers a clear, consistent interface that speeds up development and time to market, making it ideal for building trading bots, portfolio management systems, or custom trading platforms.

Help us build better for you.

Advanced Trade Typescript SDK is made possible through the continued collaboration and feedback from our developers. Please take a moment to tell us how we can better help you by providing feedback via our discord channel. You can also continue learning about Advanced Trade API in our technical documentation.

Please come find us and other developers on the Advanced Trade channel on Discord or on X ( @shubhashriM), if you need assistance.

- -

Disclaimer: this application should never be used in any production environment, and any real funds used in this application may be lost. Additionally, this information is provided for informational purposes only and is not investment advice. This is not a recommendation to buy or sell digital assets or to employ a particular investment strategy, codes, or APIs. Coinbase makes no representation on the accuracy, suitability, or validity of any information provided herein.

This material is for informational purposes only and is not (i) an offer, or solicitation of an offer, to invest in, or to buy or sell, any interests or shares, or to participate in any investment or trading strategy, or (ii) intended to provide accounting, legal, or tax advice, or investment recommendations. No representation or warranty is made, expressed or implied, with respect to the accuracy or completeness of the information or to the future performance of any digital asset, financial instrument or other market or economic measure. The information is believed to be current as of the date indicated and may not be updated or otherwise revised to reflect information that subsequently became available or a change in circumstances after the date of publication. Investing in cryptocurrency comes with risk. Prior results do not guarantee future performance. Readers should consult their advisors before making any investment decision. Any references to third parties do not imply Coinbase's endorsement, or approval of any third-party websites or their content. This material is the property of Coinbase, Inc. Any use, review, retransmission, distribution, or reproduction of these materials, in whole or in part, is strictly prohibited in any form without the express written approval of Coinbase. Coinbase, Inc. is licensed to engage in virtual currency business activity by the New York State Department of Financial Services. © 2024 Coinbase, Inc. All Rights Reserved. COINBASE, the C Logo, and the Wallet Logo are all trademarks of Coinbase, Inc.

Coinbase logo
Lisa Mohanty
David Mkrtchyan

About Lisa Mohanty and David Mkrtchyan

Lisa Mohanty is a Senior Product Manager at Coinbase Advanced, focusing on improving core features and developer experience for Advanced Traders worldwide. Before joining Coinbase, Lisa worked as a Product leader at Amazon Alexa helping launch consumer products like Echo Show and Alexa Gadgets. She holds Masters in Business Administration from University of Illinios Urbana-Champaign, and a Bachelors of Computer Science from Amrita University, India.

If you have questions and feedback on Coinbase Advanced, we would love to hear from you – Lisa’s DMs are open!

David Mkrtchyan is a Software Engineer on the Advanced API team at Coinbase. He graduated with a B.S. in Computer Science from California State University, Northridge in 2021. David found his passion for crypto when he made his first purchase on Coinbase over 5+ years ago, and has remained deeply involved with the space ever since.