1.0.0 • Published 2 years ago

3commas-client-node v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

3commas Client Node:

This is a typescript client for 3commas for node.js. It supports also websockets.
The client definition is automatically generated from OpenAPI specs using OpenAPI Typescript Codegen

Quickstart

import dotenv from 'dotenv'
import { ThreeCommasClient, ThreeCommasClientConfig, WSEventType, AccountEntity } from '3commas-client-node'

dotenv.config({ path: '.env' })

const THREECOMMAS_API_KEY: string = process.env.THREECOMMAS_API_KEY!
const THREECOMMAS_API_SECRET: string = process.env.THREECOMMAS_API_SECRET!

async function main () {
  const config: ThreeCommasClientConfig = { apiKey: THREECOMMAS_API_KEY, apiSecret: THREECOMMAS_API_SECRET }
  const threeCommasClient = new ThreeCommasClient(config)

  const accounts = await threeCommasClient.RESTClient.accounts.getVer1Accounts()
  const account: AccountEntity = accounts[0]
  console.log(account.id)

  // Websocket support
  await threeCommasClient.waitForWsReady()
  const waitForSub = () => new Promise<void>((resolve) => {
    threeCommasClient.subscribe(WSEventType.ConfirmSubscription, function () {
      resolve()
    })
    threeCommasClient.subscribe(WSEventType.SmartTrades, function () { })
  })

  await waitForSub()
  threeCommasClient.wsClient.close()
}

main()