-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmarket-data.ts
More file actions
161 lines (139 loc) · 4.28 KB
/
Copy pathmarket-data.ts
File metadata and controls
161 lines (139 loc) · 4.28 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
160
161
import { z } from 'zod';
import {
ClobAssetIdSchema,
ConditionIdSchema,
type DecimalString,
DecimalStringSchema,
type OrderSide,
OrderSideSchema,
type PositionId,
type TickSizeValue,
TickSizeValueSchema,
type TokenId,
} from '../shared';
export const MidpointSchema = z.object({
mid: DecimalStringSchema,
});
export type Midpoint = z.infer<typeof MidpointSchema>;
export const MidpointsSchema = z.record(ClobAssetIdSchema, DecimalStringSchema);
export type Midpoints = z.infer<typeof MidpointsSchema>;
export const PriceSchema = z.object({
price: DecimalStringSchema,
});
export type Price = z.infer<typeof PriceSchema>;
const PricesBySideSchema = z.partialRecord(
OrderSideSchema,
DecimalStringSchema,
);
export type PricesBySide = z.infer<typeof PricesBySideSchema>;
export const PricesSchema = z.record(ClobAssetIdSchema, PricesBySideSchema);
export type Prices = z.infer<typeof PricesSchema>;
export const SpreadSchema = z.object({
spread: DecimalStringSchema,
});
export type Spread = z.infer<typeof SpreadSchema>;
export const SpreadsSchema = z.record(ClobAssetIdSchema, DecimalStringSchema);
export type Spreads = z.infer<typeof SpreadsSchema>;
const LastTradePriceValueSchema = z.object({
price: DecimalStringSchema,
side: OrderSideSchema,
});
export type LastTradePrice = z.infer<typeof LastTradePriceValueSchema>;
export const LastTradePriceSchema = LastTradePriceValueSchema.extend({
side: z.union([OrderSideSchema, z.literal('')]),
}).transform((lastTrade): LastTradePrice | null =>
lastTrade.side === ''
? null
: { price: lastTrade.price, side: lastTrade.side },
);
const LastTradePriceForTokenResponseSchema = z
.object({
price: DecimalStringSchema,
side: OrderSideSchema,
token_id: ClobAssetIdSchema,
})
.transform(({ token_id, price, side }) => ({
assetId: token_id,
tokenId: token_id,
price,
side,
})) satisfies z.ZodType<LastTradePriceForAssetResponse>;
export type LastTradePriceForAssetResponse = {
assetId: TokenId | PositionId;
/** @deprecated Use `assetId`. */
tokenId: TokenId | PositionId;
price: DecimalString;
side: OrderSide;
};
/** @deprecated Use `LastTradePriceForAssetResponse`. */
export type LastTradePriceForTokenResponse = LastTradePriceForAssetResponse;
export type LastTradePriceForAsset = {
assetId: TokenId | PositionId;
/** @deprecated Use `assetId`. */
tokenId: TokenId | PositionId;
price: DecimalString;
side: OrderSide;
};
/** @deprecated Use `LastTradePriceForAsset`. */
export type LastTradePriceForToken = LastTradePriceForAsset;
export const LastTradePricesSchema = z.array(
LastTradePriceForTokenResponseSchema,
);
export type LastTradePrices = z.infer<typeof LastTradePricesSchema>;
export const ConditionByTokenSchema = z
.object({
condition_id: ConditionIdSchema,
})
.transform(({ condition_id }) => condition_id);
export const ResolveConditionByTokenResponseSchema = ConditionByTokenSchema;
export type ConditionByToken = z.infer<typeof ConditionByTokenSchema>;
export type ResolveConditionByTokenResponse = z.infer<
typeof ResolveConditionByTokenResponseSchema
>;
export const MarketFeeInfoSchema = z
.object({
r: z.number().default(0),
e: z.number().default(0),
})
.transform(({ r, e }) => ({
rate: r,
exponent: e,
}));
export const MarketTokenSchema = z
.object({
t: ClobAssetIdSchema,
o: z.string(),
})
.transform(({ t, o }) => ({
assetId: t,
tokenId: t,
outcome: o,
})) satisfies z.ZodType<MarketToken>;
export const MarketInfoSchema = z
.object({
fd: MarketFeeInfoSchema.nullish(),
mts: TickSizeValueSchema,
nr: z.boolean().optional(),
t: z.array(MarketTokenSchema),
})
.transform(({ fd, mts, nr, t }) => ({
feeInfo: fd ?? { rate: 0, exponent: 0 },
negRisk: nr ?? false,
tickSize: mts,
tokens: t,
})) satisfies z.ZodType<MarketInfo>;
export const FetchMarketInfoResponseSchema = MarketInfoSchema;
export type MarketFeeInfo = z.infer<typeof MarketFeeInfoSchema>;
export type MarketToken = {
assetId: TokenId | PositionId;
/** @deprecated Use `assetId`. */
tokenId: TokenId | PositionId;
outcome: string;
};
export type MarketInfo = {
feeInfo: MarketFeeInfo;
negRisk: boolean;
tickSize: TickSizeValue;
tokens: MarketToken[];
};
export type FetchMarketInfoResponse = MarketInfo;