Skip to content
markpaper

src/testing/fixtures.ts

v0.1.0 · 1.9 KB

Download file
import type { QfexFill, QfexOrderEvent } from '../frames/index.js';
// All values and identities in this module are synthetic, not account observations.
export const FIXTURE_ACCOUNT = '10000000-0000-4000-8000-000000000001';
export const FIXTURE_KEYS = { publicKey: 'fixture-public', secret: 'fixture-secret' };
export const fixtureRefdata = (symbol = 'BTC-USD') => ({
  symbol,
  base_asset: symbol.split('-')[0],
  quote_asset: 'USD',
  status: 'ACTIVE',
  tick_size: '0.25',
  lot_size: '0.02',
  min_quantity: '0.06',
  max_quantity: '900',
  default_max_leverage: 8,
  margin_asset: 'USDC',
  min_price: '40',
  max_price: '240',
  market_hours: {},
  product_category: 'SYNTHETIC',
});
export const fixtureOrder = (changes: Partial<QfexOrderEvent> = {}): QfexOrderEvent => ({
  orderId: '20000000-0000-4000-8000-000000000001',
  symbol: 'BTC-USD',
  status: 'ACK',
  side: 'BUY',
  type: 'LIMIT',
  tif: 'GTC',
  qty: '0.38',
  price: '120.25',
  remaining: '0.38',
  cloid: 'ab'.repeat(16),
  updateTimeMs: null,
  tradeId: null,
  userId: null,
  ...changes,
});
export const fixtureFill = (changes: Partial<QfexFill> = {}): QfexFill => ({
  tradeId: '9007199254741009',
  orderId: fixtureOrder().orderId,
  cloid: fixtureOrder().cloid,
  symbol: 'BTC-USD',
  side: 'BUY',
  price: '120.25',
  qty: '0.38',
  remaining: '0',
  fee: '0',
  execType: 'TRADE',
  tsMs: null,
  aggressorSide: null,
  orderType: 'LIMIT',
  tif: 'IOC',
  orderPrice: '120.25',
  realisedPnl: null,
  userId: null,
  ...changes,
});
export function wireOrder(row: QfexOrderEvent) {
  return {
    order_id: row.orderId,
    symbol: row.symbol,
    status: row.status,
    side: row.side,
    type: row.type,
    time_in_force: row.tif,
    quantity: row.qty,
    price: row.price,
    quantity_remaining: row.remaining,
    client_order_id: row.cloid,
    reduce_only: row.reduceOnly ?? false,
    order_origin: 'PORT',
  };
}
All files