πŸš€ How to Build a WebSocket Tracker using Coinbase Prime API with Node.js + React

Anuj varshneyAnuj varshney
3 min read

πŸ‘‹ Introduction

In the world of crypto trading, real-time updates are crucial β€” price movements, order books, and trade confirmations must be instant. That's where WebSockets shine.

In this tutorial, we’ll build a full-stack Coinbase Prime WebSocket Tracker using Node.js (TypeScript) for the backend and React for the frontend. This project is perfect if you're exploring real-time applications, authenticated WebSocket feeds, and crypto APIs.

πŸ“‹ Table of Contents

  1. Why Use Coinbase Prime WebSocket Feed?

  2. Project Overview

  3. Backend Setup (Node.js + TypeScript)

  4. Coinbase Prime Authentication (HMAC SHA256)

  5. Frontend Setup (React + WebSocket Client)

  6. Displaying Real-time Data

  7. Final Thoughts

πŸ”— 1. Why Use Coinbase Prime WebSocket Feed?

Coinbase Prime offers an authenticated WebSocket API that gives you access to channels like:

  • heartbeat – Keepalive signal

  • status – Product and system status

  • level2 – Real-time order book

  • user – Personal order updates (authenticated)

  • matches – Trade executions

Unlike Coinbase Pro, this feed is intended for institutional-grade apps. So if you're building anything real-time and crypto-focused, this is gold.

πŸ—οΈ 2. Project Overview

We’ll build:

  • A backend server to authenticate and subscribe to WebSocket channels from Coinbase Prime

  • A React frontend that connects to our backend via WebSocket to show real-time updates

Tech stack:

  • Backend: Node.js, TypeScript, ws, crypto

  • Frontend: React, WebSocket API

πŸ› οΈ 3. Backend Setup (Node.js + TypeScript)

πŸ‘‰ Install Dependencies

npm init -y
npm install ws dotenv crypto axios
npm install -D typescript ts-node @types/node

πŸ‘‰ Basic WebSocket Client

// src/websocketClient.ts
import WebSocket from 'ws';
import crypto from 'crypto';
import dotenv from 'dotenv';

dotenv.config();

const ws = new WebSocket('wss://advanced-trade-ws.coinbase.com');

const ACCESS_KEY = process.env.ACCESS_KEY!;
const SECRET_KEY = process.env.SECRET_KEY!;
const PASSPHRASE = process.env.PASSPHRASE!;
const ACCOUNT_ID = process.env.ACCOUNT_ID!;

ws.on('open', () => {
  console.log('WebSocket connected.');

  const timestamp = Math.floor(Date.now() / 1000).toString();
  const message = timestamp + 'GET' + '/users/self/verify';

  const signature = crypto
    .createHmac('sha256', SECRET_KEY)
    .update(message)
    .digest('base64');

  const subscribeMsg = {
    type: 'subscribe',
    channel: 'heartbeat',
    product_ids: ['BTC-USD'],
    api_key: ACCESS_KEY,
    timestamp,
    signature,
    passphrase: PASSPHRASE,
  };

  ws.send(JSON.stringify(subscribeMsg));
});

ws.on('message', (data) => {
  console.log('Message:', data.toString());
});

πŸ‘‰ Environment Variables (.env)

ACCESS_KEY=your_key
SECRET_KEY=your_secret
PASSPHRASE=your_passphrase
ACCOUNT_ID=your_account_id

πŸ’» 4. Frontend Setup (React + WebSocket)

πŸ‘‰ Basic Setup

npx create-react-app client
cd client
npm install

πŸ‘‰ WebSocket Component

import React, { useEffect, useState } from 'react';

export default function WebSocketFeed() {
  const [messages, setMessages] = useState([]);

  useEffect(() => {
    const socket = new WebSocket('ws://localhost:3000');

    socket.onmessage = (event) => {
      const msg = JSON.parse(event.data);
      setMessages((prev) => [...prev.slice(-50), msg]); // Keep latest 50
    };

    return () => socket.close();
  }, []);

  return (
    <div>
      <h2>πŸ”„ Real-Time Coinbase Feed</h2>
      <ul>
        {messages.map((msg, i) => (
          <li key={i}>{JSON.stringify(msg)}</li>
        ))}
      </ul>
    </div>
  );
}

🌐 5. Serve Data from Backend to Frontend

You can use ws or socket.io to create a WebSocket server in Node and broadcast the data received from Coinbase to the frontend.


πŸ“ˆ 6. Displaying Real-time Data

Once integrated, you’ll see:

  • Heartbeat signals every second

  • Real-time trade or order data

  • Dynamic UI changes as events happen

Add styling with Tailwind or Chakra UI, and you’ve got a clean, responsive dashboard!


βœ… 7. Final Thoughts

Building a real-time WebSocket tracker is a great way to:

  • Understand crypto APIs

  • Work with HMAC authentication

  • Handle real-time data pipelines

  • Enhance your portfolio with practical full-stack skills

If you're serious about becoming a Web3 or FinTech developer, this is a strong project to showcase.


πŸ™Œ Let’s Connect!

If you liked this, follow me on Hashnode and connect with me on LinkedIn. You can also check out more projects on my GitHub.

πŸ’¬ Want the full source code? Drop a comment and I’ll share it with you!

0
Subscribe to my newsletter

Read articles from Anuj varshney directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Anuj varshney
Anuj varshney

Hey, I am Anuj Varshney a software developer with over a year of experience at iQuinceSoft Pvt Ltd, specializing in web development using various programming languages and tools. He holds a Bachelor of Computer Application degree from Dr. BR Ambedkar University and is currently pursuing a Master of Computer Application from Chandigarh University via distance learning. Anuj has worked on a variety of projects, including the maintenance and updates of CaritasRevolution.com, iQuinceSoft.com, and OdontologiaVejarno.com. His skills include proficiency in programming languages such as JavaScript, C++, C, HTML, and CSS, as well as front-end development using React.js and Nuxt.js. He is also familiar with Node.js, Express.js, MongoDB, and various other tools such as WordPress REST API, Firebase, Redux, Stripe, and Material UI. Anuj is a quick learner with strong analytical skills, and attention to detail, and is committed to delivering high-quality work within tight deadlines.