This is an opinionated typescript client that wraps around carbon-js-sdk to proivde a simple way to programmatically trade on Carbon's Perpetuals markets.
Some data are steamed over websockets and cached in memory while the remaining are fetched asynchronously over gRPC or API methods.
- MAINNET support only
- Perpetuals trading only
# For NPM
npm install demex-client --legacy-peer-deps
# For Yarn
yarn add demex-client --legacy-peer-deps
This client is considered Alpha software and is under develpoment at the moment. Client may contain bugs and hence use at your own risk.
- Uses human friendly symbols instead of market ids (e.g. "ETH" -> "cmkt/117")
- Astracts all sats values & requirements to human readable values
- Dead man's switch for chain and indexer liveliness to prevent stale data
- Virtualization of user account state via websockets
- Virtualization of market data state via websockets
- Wraps position data with mark price and unrealized profit & loss
- Warps market stats with funding rates
- Expose websocket messages
- Wrapped deposit and withdrawal transfer functions
- Devnet & Testnet support
import { Client, OrderSide, OrderType, MAINNET_TOKENS } from 'demex-client'
async function run() {
const bot = new Client()
await bot.init({ mnemonic: "YOUR MNEMONIC"})
bot.subscribeMarketStats()
bot.subscribeOrderBooks(['BTC', 'ETH'])
bot.subscribeAccountData()
await bot.startWebsocket()
// MARKET DATA
const orderBook = bot.getOrderBook('ETH')
const recentTrades = await bot.getTrades('BTC')
const stats = await bot.getMarketStats()
// ACCOUNT DATA
const usdBalance = bot.getBalance(MAINNET_TOKENS.USD)
const positions = bot.getPositions()
const position = bot.getPosition('BTC')
const orders = bot.getOpenOrders('BTC')
const userTrades = await bot.getUserTrades('BTC')
const leverages = await bot.getMarketsLeverage()
// TRANSACTIONS
const order = await bot.submitOrder({
symbol: 'BTC',
side: OrderSide.Buy,
price: 40000.001,
quantity: 0.0011111,
type: OrderType.Limit,
})
const cancels = await bot.cancelAll('BTC')
cosnt cancel = await.bot.cancelOrder("ORDERID")
const leverage = await bot.updateLeverage('ETH', 1.3)
}
Submit an issue here.