-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmarket.test.ts
More file actions
159 lines (144 loc) · 4.14 KB
/
Copy pathmarket.test.ts
File metadata and controls
159 lines (144 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import { describe, expect, it } from 'vitest';
import {
GetServerTimeResponseSchema,
PerpsFeeScheduleEntrySchema,
PerpsFundingIntervalSchema,
PerpsInstrumentSchema,
PerpsPublicTradeSchema,
PerpsPublicTradeUpdateSchema,
} from './market';
const txHash = `0x${'1'.repeat(64)}`;
describe('GetServerTimeResponseSchema', () => {
it('parses an epoch-millisecond server time', () => {
expect(
GetServerTimeResponseSchema.parse({ time: 1_766_000_000_000 }),
).toEqual({ time: 1_766_000_000_000 });
});
it('rejects a non-integer server time', () => {
expect(() =>
GetServerTimeResponseSchema.parse({ time: 1_766_000_000_000.5 }),
).toThrow();
});
});
describe('PerpsFundingIntervalSchema', () => {
it('accepts positive whole-hour funding intervals', () => {
expect(PerpsFundingIntervalSchema.parse('1h')).toBe('1h');
expect(PerpsFundingIntervalSchema.parse('8h')).toBe('8h');
});
it('rejects unsupported funding interval formats', () => {
expect(() => PerpsFundingIntervalSchema.parse('0h')).toThrow();
expect(() => PerpsFundingIntervalSchema.parse('30m')).toThrow();
expect(() => PerpsFundingIntervalSchema.parse('1.5h')).toThrow();
});
});
describe('PerpsInstrumentSchema', () => {
it('normalizes instrument identifiers without exposing instrument type', () => {
const instrument = PerpsInstrumentSchema.parse({
base_asset: 'BTC',
category: 'crypto',
funding_interval: '1h',
instrument_id: 1,
instrument_type: 'perpetual',
isolated_only: true,
liquidation_fee: '0.01',
max_leverage: 10,
max_limit_notional: '1000000',
max_market_notional: '100000',
max_order_count: 200,
min_notional: '1',
price_bounds: '0.1',
price_decimals: 2,
quantity_decimals: 4,
quote_asset: 'USD',
risk_tiers: [{ lower_bound: '0', max_leverage: 10 }],
symbol: 'BTC-PERP',
});
expect(instrument).toMatchObject({
id: 1,
category: 'crypto',
symbol: 'BTC-PERP',
isolatedOnly: true,
});
expect(instrument).not.toHaveProperty('instrumentId');
expect(instrument).not.toHaveProperty('instrumentType');
});
});
describe('PerpsFeeScheduleEntrySchema', () => {
it('normalizes volume tiers including negative maker rates', () => {
const entry = PerpsFeeScheduleEntrySchema.parse({
instrument_type: 'perpetual',
category: 'crypto',
taker_fee_rate: '0.00045',
maker_fee_rate: '0.00015',
tiers: [
{
min_volume_30d: '0',
taker_fee_rate: '0.00045',
maker_fee_rate: '0.00015',
},
{
min_volume_30d: '5000000',
taker_fee_rate: '0.0002',
maker_fee_rate: '-0.00005',
},
],
});
expect(entry).toEqual({
category: 'crypto',
takerFeeRate: '0.00045',
makerFeeRate: '0.00015',
tiers: [
{
minVolume30d: '0',
takerFeeRate: '0.00045',
makerFeeRate: '0.00015',
},
{
minVolume30d: '5000000',
takerFeeRate: '0.0002',
makerFeeRate: '-0.00005',
},
],
});
});
});
describe('PerpsPublicTradeSchema', () => {
it('normalizes placeholder hashes to undefined', () => {
const trade = PerpsPublicTradeSchema.parse({
trade_id: 1,
instrument_id: 6,
side: 'long',
price: '1',
quantity: '2',
timestamp: 1_700_000_000_000,
hash: '0x',
});
expect(trade.hash).toBeUndefined();
});
it('preserves valid transaction hashes', () => {
const trade = PerpsPublicTradeSchema.parse({
trade_id: 1,
instrument_id: 6,
side: 'long',
price: '1',
quantity: '2',
timestamp: 1_700_000_000_000,
hash: txHash,
});
expect(trade.hash).toBe(txHash);
});
});
describe('PerpsPublicTradeUpdateSchema', () => {
it('normalizes compact placeholder hashes to undefined', () => {
const trade = PerpsPublicTradeUpdateSchema.parse({
tid: 1,
iid: 6,
side: 'long',
p: '1',
qty: '2',
ts: 1_700_000_000_000,
hash: '0x',
});
expect(trade.hash).toBeUndefined();
});
});