Coder Social home page Coder Social logo

cedelabs / sdk-examples Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 711 KB

Examples of how to use the Cede SDK: Connect to multiple centralized exchanges using a single SDK

Home Page: https://sdk.cede.store/

TypeScript 100.00%
algorithmic-trading algotrading altcoin api arbitrage bitcoin bot btc cefi cex crypto cryptocurrency eth ethereum exchange invest library market-data strategy trading

sdk-examples's Introduction

Cede Playground SDK

CEDE

Cede SDK is a centralized exchange (CEX) connectivity solution that unifies access to multiple CEX APIs. At present, we support connections to over 10 CEXs using both API keys and OAuth. This SDK enables B2B stakeholders to effortlessly incorporate features like account balances, withdrawals, transaction histories, trades, and public data.

This repository demonstrates the API of this SDK in sandbox mode (exchange API keys are not required). Below, you will find numerous available features.

Installation

git clone https://github.com/cedelabs/sdk-examples
cd sdk-examples
yarn

You can specify the exchange you want to use in config.ts.

In the public version of the SDK, exchanges are mocked. You don't need to provide API keys to test or start the integration.

Once you're ready to integrate with real exchanges, you'll need to do the following:

  1. We'll provide you with the clientId to include in config.ts.
  2. You'll need to copy and paste the exchanges.example.ts file to exchanges.ts with your API keys.
  3. Install the private @cedelabs-private/sdk package and replace the "@cedelabs/demo-sdk" imports with "@cedelabs-private/sdk".

Commands

Each command file is located inside the corresponding use case folder: authentication, balances, deposit, exchange, prices, trade, withdraw.

You can use the yarn execute commande to execute any command:

yarn execute ./deposit/getDepositableTokens

// [
//   { tokenSymbol: 'ETH', networks: [ [Object] ] },
//   { tokenSymbol: 'MATIC', networks: [ [Object] ] }
// ]

Features

You will find supported features in the tables below. For more detailed documentation, please visit https://sdk.cede.store/documentation/general-info.

Authentication

To authenticate your requests, you need to register an exchange instance and provide credentials for future requests. You can register it using either an API key pair (apiKey and secretKey) or an OAuth key pair (accessToken and refreshToken). If you're in "MOCK" mode, providing keys is not necessary.

Feature Command Description
register an exchange yarn execute ./exchange/registerExchangeInstance Creates an exchange instance with the provided credentials (API keys or OAuth tokens).
remove an exchange yarn execute ./exchange/removeExchangeInstance Removes an exchange instance, deleting API keys from memory, revoking OAuth tokens, etc.
exchange registered yarn execute ./exchange/isRegistered Checks if the exchange instance is already registered.
OAuth URL yarn execute ./exchange/getOAuthUrl Provides the URL of the exchange to initiate the OAuth flow. After redirection, you will be able to retrieve the authorization code.
Get OAuth tokens yarn execute ./exchange/getOAuthTokens After obtaining the authorization code, call this method to retrieve the access and refresh tokens.

Balances and other data

Feature Command Description
balances yarn execute ./balances/getBalances Provides balances by wallet type (spot, futures, margin, etc.). You can find the supported wallet types in getSupportedExchanges.
prices yarn execute ./prices/getPrices Provides prices in USD for all tokens supported by the SDK.
supported exchanges yarn execute ./exchange/getSupportedExchanges Lists all supported exchanges along with their metadata.

Withdrawal use case

Feature Command Description
withdrawal networks yarn execute ./withdraw/getWithdrawableNetworks Provides a list of networks available for withdrawing a specific token on a given exchange.
withdrawable tokens yarn execute ./withdraw/getWithdrawableBalances Provides balances of tokens available for withdrawal from one or more wallet types.
prepare a withdrawal yarn execute ./withdraw/prepareWithdrawal Prepares a withdrawal. More info: https://sdk.cede.store/documentation/api-reference/withdraw#prepare-withdrawal
create a withdrawal yarn execute ./withdraw/createWithdrawal Sends a withdrawal request to the exchange. If more than one wallet type is used, the SDK executes an internal transfer to have enough funds for the withdrawal.
retrieve a withdrawal yarn execute ./withdraw/getWithdrawalById Retrieves a withdrawal.

Deposit use case

Feature Command Description
deposit networks yarn execute ./deposit/getNetworks Provides a list of networks available for depositing a specific token on a given exchange.
depositable tokens yarn execute ./deposit/getDepositableTokens Provides a list of tokens available for deposit on a given exchange.
deposit address yarn execute ./deposit/getDepositAddress Retrieves the deposit address for a specific token and network on a given exchange.

Trade use case

Feature Command Description
market pairs yarn execute ./trade/getMarketPairs Provides a list of existing market pairs.
market rate yarn execute ./trade/getMarketRate Provides the best buy and sell prices from the order book, useful for estimating amountOut.
minimum trade amounts yarn execute ./trade/getMinAmounts Provides minimum trade amounts.
prepare an order yarn execute ./trade/prepareOrder Estimates the exchange fee and the amount to be received. Provides the object to pass to the createOrder function.
create an order yarn execute ./trade/createOrder Send an order to the exchange.
update an order yarn execute ./trade/updateOrder Updates the open order (type, side, amount, price).
open orders yarn execute ./trade/getOpenOrders Lists all open orders.
retrieve an order yarn execute ./trade/getOrder Retrieves an order.

Tests

The tests actually rely on the mocked coinbase CEX using the demo package and can fail in case you change the CEX or the content of the executeMethod function.

Usage with a real CEX

First, install the private package @cedelabs-private/sdk. To obtain access, please contact the Cede Labs team:

If you want to add a CEX, copy paste the exchanges.example.ts file to the exchanges.ts file and fill in the CEX credentials.

And then change the SELECTED_CEX entry inside the .env file so every commands will run using the CEX you need.

Then link the local sdk package with to this project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.