Skip to content
markpaper

src/testing/fixtures.ts

v0.2.1 · 6 KB

Download file
// Test fixtures in the shape of instance responses documented in the knowledge base
// (instances-and-api.md §2, orders.md §6, account-and-leverage.md §1-2). Every number is invented;
// order ids are deliberately above 2^53 so that JSON.parse rounds `order_index`.
// Not part of the published build.

export function orderBookDetailsPayload(): Record<string, unknown> {
  return {
    code: 200,
    order_book_details: [
      {
        symbol: 'ETH',
        market_id: 32,
        market_type: 'perp',
        status: 'active',
        supported_size_decimals: 4,
        supported_price_decimals: 2,
        min_base_amount: '0.0100',
        min_quote_amount: '10.000000',
        mark_price: '1605.34',
        last_trade_price: '1606.10',
        min_initial_margin_fraction: '1000',
        default_initial_margin_fraction: '5000',
      },
      {
        symbol: 'ETH/USDG',
        market_id: 132,
        market_type: 'perp',
        status: 'active',
        supported_size_decimals: 4,
        supported_price_decimals: 2,
        min_base_amount: '0.0100',
        min_quote_amount: '10.000000',
        mark_price: '1605.20',
        last_trade_price: '1605.20',
        min_initial_margin_fraction: '1000',
        default_initial_margin_fraction: '5000',
      },
      {
        symbol: 'LIT',
        market_id: 57,
        market_type: 'perp',
        status: 'active',
        supported_size_decimals: 0,
        supported_price_decimals: 4,
        min_base_amount: '5',
        min_quote_amount: '10.000000',
        mark_price: '0.9120',
        last_trade_price: '0.9100',
        min_initial_margin_fraction: '2000',
        default_initial_margin_fraction: '5000',
      },
      {
        symbol: 'CRWV',
        market_id: 41,
        market_type: 'perp',
        status: 'active',
        supported_size_decimals: 2,
        supported_price_decimals: 2,
        min_base_amount: '0.04',
        min_quote_amount: '10.000000',
        mark_price: '90.15',
        last_trade_price: '90.00',
        min_initial_margin_fraction: '2000',
        default_initial_margin_fraction: '5000',
      },
      {
        symbol: 'PURR',
        market_id: 9001,
        market_type: 'spot',
        status: 'active',
        supported_size_decimals: 2,
        supported_price_decimals: 4,
        min_base_amount: '1',
        min_quote_amount: '10.000000',
        mark_price: '0.2000',
        last_trade_price: '0.2000',
        min_initial_margin_fraction: '10000',
        default_initial_margin_fraction: '10000',
      },
    ],
  };
}

export function orderBooksPayload(): Record<string, unknown> {
  return {
    code: 200,
    order_books: [
      { symbol: 'ETH', market_id: 32, status: 'active', market_type: 'perp', taker_fee: '0.0000', maker_fee: '0.0000' },
      { symbol: 'ETH/USDG', market_id: 132, status: 'active', market_type: 'perp' },
      { symbol: 'LIT', market_id: 57, status: 'active', market_type: 'perp' },
      { symbol: 'CRWV', market_id: 41, status: 'active', market_type: 'perp' },
    ],
  };
}

/** Zero address: a placeholder, not a wallet. */
export const FIXTURE_L1_ADDRESS = '0x0000000000000000000000000000000000000000';

export function accountPayload(): Record<string, unknown> {
  return {
    code: 200,
    accounts: [
      {
        index: 12345,
        l1_address: FIXTURE_L1_ADDRESS,
        total_asset_value: '3000.000000',
        collateral: '2950.000000',
        available_balance: '1920.000000',
        cross_initial_margin_requirement: '1080.000000',
        total_order_count: 3,
        positions: [
          {
            market_id: 32,
            symbol: 'ETH',
            sign: 1,
            position: '0.6230',
            avg_entry_price: '1600.00',
            position_value: '1000.00',
            unrealized_pnl: '3.32',
            initial_margin_fraction: '50.00',
            margin_mode: '0',
          },
          {
            market_id: 41,
            symbol: 'CRWV',
            sign: -1,
            position: '27.73',
            avg_entry_price: '90.10',
            position_value: '2500.00',
            unrealized_pnl: '-1.40',
            initial_margin_fraction: '20.00',
            margin_mode: '0',
          },
          {
            market_id: 57,
            symbol: 'LIT',
            sign: 1,
            position: '877',
            avg_entry_price: '0.9100',
            position_value: '800.00',
            unrealized_pnl: '1.75',
            initial_margin_fraction: '10.00',
            margin_mode: '0',
          },
          {
            market_id: 999,
            symbol: 'FLAT',
            sign: 1,
            position: '0',
            avg_entry_price: '0',
            position_value: '0',
            unrealized_pnl: '0',
            initial_margin_fraction: '50.00',
            margin_mode: '0',
          },
        ],
      },
    ],
  };
}

/** Two synthetic ids above 2^53 that JSON.parse rounds to the SAME double (…564), plus one that survives (2^53 - 1). */
export const ORDER_ID_A = '12345678901234565';
export const ORDER_ID_B = '12345678901234563';
export const ORDER_ID_ROUNDED = 12345678901234564;
export const ORDER_ID_SAFE = '9007199254740991';

/** Raw text of an `accountActiveOrders` response with ids above 2^53 as bare integers. */
export function activeOrdersText(): string {
  return `{"code":200,"orders":[
    {"order_id":"${ORDER_ID_A}","order_index":${ORDER_ID_A},"client_order_index":1712345678,"market_index":32,
     "is_ask":true,"price":"1650.00","remaining_base_amount":"0.0100","initial_base_amount":"0.0100","reduce_only":false,"status":"open"},
    {"order_id":"${ORDER_ID_B}","order_index":${ORDER_ID_B},"client_order_index":1712345679,"market_index":32,
     "is_ask":false,"price":"1550.00","remaining_base_amount":"0.0200","initial_base_amount":"0.0300","reduce_only":true,"status":"open"},
    {"order_id":"${ORDER_ID_SAFE}","order_index":${ORDER_ID_SAFE},"client_order_index":1712345680,"market_index":41,
     "is_ask":false,"price":"88.00","remaining_base_amount":"0","initial_base_amount":"0.50","reduce_only":false,"status":"filled"}
  ]}`;
}
All files