Skip to content

Fully functional websocket connection template built with PENDAX-SDK

Notifications You must be signed in to change notification settings

traderjoe155/Okx-Websocket-Template-PENDAX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OKX Websocket Template built with PENDAX-SDK

https://github.com/CompendiumFi/PENDAX-SDK

signup for an OKX account: https://www.okx.com/join/COMPENDIUM

install required packages with npm install

run with npm index.js

This application is a fully functional template for okx websockets utilizing PENDAX-SDK

Add your api key, secret, and passphrase in index.js under the socket config. adjust parameters as neccesary. If the endpoint you are trying to use is private, change isPrivate: true. For market data and other public endpoints, isPrivate: false.

This sample code is using a single okxSubscription, however to add more just declare a new variable and a new socket config. You can refrence more than one at a time inside the try block in startSocket function.

Screenshot 2022-11-03 at 4 13 41 AM

create a subscription inside the doSubscriptions function.

ex:

function doSubscriptions(socket) {
subscriptions.tickers = {
        name: 'tickers',
        args:
            [{ channel: 'tickers', instId: 'BTC-USDT-SWAP' }]
    }
    socket.subscribe(subscriptions.tickers)
    console.log('Attempting subscriptions')
}

Edit what you want to happen when a message comes in on this channel inside the handleMessage function:

case 'tickers':
            console.log(msg.data)
            break;

Result

Screenshot 2022-11-03 at 4 08 31 AM

All websocket functionality available from OKX at time of writing is present in this template

Releases

No releases published

Packages

No packages published