Skip to main content

Installation

You can install the SDK using npm from the GitHub repository:
npm i github:bison-markets/sdk-ts

Basic Usage

To avoid ambiguity, we denote the smallest possible multiple of USDC (0.000001 USDC) as one uusdc, which stands for µUSDC (micro-USDC), and denote the smallest possible multiple of a contract (0.01 contract) as one ccontract (centicontract).User-facing USDC balances are specified as fixed-point strings (e.g. "1.2625" for USDC). Contract quantities in the API and SDK are specified as integer ccontracts strings (e.g. "1050" for 10.50 contracts at precision 2).
example.ts
import { createBisonClient, usdcToUusdc, uusdcToUsdc } from '@bison-markets/sdk-ts';
import { createWalletClient, createPublicClient, http, custom } from 'viem';
import { base } from 'viem/chains';

// Create a client instance
const client = createBisonClient({ 
  baseUrl: 'https://api.bison.markets' 
});

// Create a wallet client for signing transactions
const walletClient = createWalletClient({
  chain: base,
  transport: custom(window.ethereum!),
});

// Create a public client for reading blockchain state
const publicClient = createPublicClient({
  chain: base,
  transport: http(),
});

// Deposit 100 USDC
const txHash = await client.executeDepositFlow({
  walletClient,
  publicClient,
  userAddress: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  chain: 'base',
  amountUusdc: usdcToUusdc(100).toString(), // Convert 100 USDC to µUSDC
});

console.log('Deposited! Transaction:', txHash);

// Start listening for account events
const disconnect = client.listen(
  '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  (event) => {
    if (event.type === 'usdc_deposited') {
      console.log('USDC deposit confirmed:', uusdcToUsdc(event.uusdcAmount), 'USDC');
    } else if (event.type === 'order_filled') {
      console.log('Order filled:', event.orderId);
    }
  }
);

// Clean up when done
// disconnect();

Configuration

The SDK requires only the base URL of the Bison API:
const client = createBisonClient({ 
  baseUrl: 'https://api.bison.markets' 
});

Developer Accounts

If you have a developer account, you can set it at the client level to automatically apply it to all orders:
const client = createBisonClient({ 
  baseUrl: 'https://api.bison.markets',
  devAccountId: 'your-dev-account-id'
});
All orders placed through this client will be associated with your dev account, allowing you to earn a portion of trading fees. See the Developer Accounts guide for more information on how to get a dev account and configure fee structures.

Working with Amounts

The SDK provides utility functions for working with µUSDC amounts:
import { usdcToUusdc, uusdcToUsdc, parseBigInt } from '@bison-markets/sdk-ts';

// Convert USDC to µUSDC (returns bigint)
const amount = usdcToUusdc(100);      // 100000000n
const amount2 = usdcToUusdc("1.50");  // 1500000n

// Convert µUSDC to USDC display string
const display = uusdcToUsdc(1500000n); // "1.500000"
const display2 = uusdcToUsdc("1500000"); // "1.500000"

// Parse various formats to bigint
const parsed = parseBigInt("1000000");  // 1000000n
const parsed2 = parseBigInt(1000000);   // 1000000n
const parsed3 = parseBigInt(1000000n);  // 1000000n
You can find detailed usage information on the next few pages.