@pear-protocol/types 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/entities.d.ts +9 -0
- package/dist/auth/entities.js +8 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/index.js +3 -0
- package/dist/auth/payloads.d.ts +50 -0
- package/dist/auth/payloads.js +39 -0
- package/dist/auth/response.d.ts +55 -0
- package/dist/auth/response.js +21 -0
- package/dist/bundle.d.ts +17 -0
- package/dist/bundle.js +17 -0
- package/dist/common/array.d.ts +10 -0
- package/dist/common/array.js +10 -0
- package/dist/common/index.d.ts +3 -0
- package/dist/common/index.js +3 -0
- package/dist/common/refinement.d.ts +20 -0
- package/dist/common/refinement.js +60 -0
- package/dist/common/request.d.ts +11 -0
- package/dist/common/request.js +24 -0
- package/dist/common/response.d.ts +12 -0
- package/dist/common/response.js +28 -0
- package/dist/common/schema.d.ts +8 -0
- package/dist/common/schema.js +10 -0
- package/dist/common/trade-legs.d.ts +34 -0
- package/dist/common/trade-legs.js +30 -0
- package/dist/connector/index.d.ts +8 -0
- package/dist/connector/index.js +5 -0
- package/dist/execution/entities.d.ts +741 -0
- package/dist/execution/entities.js +125 -0
- package/dist/execution/index.d.ts +3 -0
- package/dist/execution/index.js +3 -0
- package/dist/execution/queries.d.ts +20 -0
- package/dist/execution/queries.js +14 -0
- package/dist/execution/responses.d.ts +218 -0
- package/dist/execution/responses.js +9 -0
- package/dist/fill/entities.d.ts +25 -0
- package/dist/fill/entities.js +61 -0
- package/dist/fill/index.d.ts +3 -0
- package/dist/fill/index.js +3 -0
- package/dist/fill/queries.d.ts +13 -0
- package/dist/fill/queries.js +11 -0
- package/dist/fill/responses.d.ts +55 -0
- package/dist/fill/responses.js +12 -0
- package/dist/funding/entities.d.ts +11 -0
- package/dist/funding/entities.js +16 -0
- package/dist/funding/index.d.ts +3 -0
- package/dist/funding/index.js +3 -0
- package/dist/funding/queries.d.ts +10 -0
- package/dist/funding/queries.js +8 -0
- package/dist/funding/responses.d.ts +8 -0
- package/dist/funding/responses.js +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/instrument/entities.d.ts +43 -0
- package/dist/instrument/entities.js +48 -0
- package/dist/instrument/index.d.ts +3 -0
- package/dist/instrument/index.js +3 -0
- package/dist/instrument/queries.d.ts +10 -0
- package/dist/instrument/queries.js +8 -0
- package/dist/instrument/responses.d.ts +37 -0
- package/dist/instrument/responses.js +11 -0
- package/dist/instrument-precision/index.d.ts +18 -0
- package/dist/instrument-precision/index.js +51 -0
- package/dist/misc/index.d.ts +3 -0
- package/dist/misc/index.js +1 -0
- package/dist/order/entities.d.ts +73 -0
- package/dist/order/entities.js +73 -0
- package/dist/order/index.d.ts +1 -0
- package/dist/order/index.js +1 -0
- package/dist/position/entities.d.ts +53 -0
- package/dist/position/entities.js +55 -0
- package/dist/position/index.d.ts +3 -0
- package/dist/position/index.js +3 -0
- package/dist/position/queries.d.ts +16 -0
- package/dist/position/queries.js +28 -0
- package/dist/position/responses.d.ts +28 -0
- package/dist/position/responses.js +8 -0
- package/dist/price/entities.d.ts +8 -0
- package/dist/price/entities.js +7 -0
- package/dist/price/index.d.ts +3 -0
- package/dist/price/index.js +3 -0
- package/dist/price/queries.d.ts +10 -0
- package/dist/price/queries.js +8 -0
- package/dist/price/responses.d.ts +6 -0
- package/dist/price/responses.js +15 -0
- package/dist/schedule/entities.d.ts +380 -0
- package/dist/schedule/entities.js +159 -0
- package/dist/schedule/index.d.ts +4 -0
- package/dist/schedule/index.js +4 -0
- package/dist/schedule/payloads.d.ts +72 -0
- package/dist/schedule/payloads.js +102 -0
- package/dist/schedule/queries.d.ts +18 -0
- package/dist/schedule/queries.js +12 -0
- package/dist/schedule/responses.d.ts +279 -0
- package/dist/schedule/responses.js +10 -0
- package/dist/trade/index.d.ts +2 -0
- package/dist/trade/index.js +2 -0
- package/dist/trade/payloads.d.ts +217 -0
- package/dist/trade/payloads.js +35 -0
- package/dist/trade/responses.d.ts +861 -0
- package/dist/trade/responses.js +9 -0
- package/dist/trade-accounts/entities.d.ts +50 -0
- package/dist/trade-accounts/entities.js +18 -0
- package/dist/trade-accounts/index.d.ts +3 -0
- package/dist/trade-accounts/index.js +3 -0
- package/dist/trade-accounts/payloads.d.ts +137 -0
- package/dist/trade-accounts/payloads.js +84 -0
- package/dist/trade-accounts/response.d.ts +65 -0
- package/dist/trade-accounts/response.js +41 -0
- package/dist/trigger/entities/conditions.d.ts +407 -0
- package/dist/trigger/entities/conditions.js +239 -0
- package/dist/trigger/entities/index.d.ts +1549 -0
- package/dist/trigger/entities/index.js +123 -0
- package/dist/trigger/index.d.ts +6 -0
- package/dist/trigger/index.js +6 -0
- package/dist/trigger/payloads/conditions.d.ts +340 -0
- package/dist/trigger/payloads/conditions.js +109 -0
- package/dist/trigger/payloads/index.d.ts +470 -0
- package/dist/trigger/payloads/index.js +47 -0
- package/dist/trigger/queries.d.ts +18 -0
- package/dist/trigger/queries.js +12 -0
- package/dist/trigger/responses.d.ts +1001 -0
- package/dist/trigger/responses.js +10 -0
- package/dist/users/entities.d.ts +16 -0
- package/dist/users/entities.js +14 -0
- package/dist/users/index.d.ts +3 -0
- package/dist/users/index.js +3 -0
- package/dist/users/payloads.d.ts +5 -0
- package/dist/users/payloads.js +7 -0
- package/dist/users/response.d.ts +23 -0
- package/dist/users/response.js +12 -0
- package/package.json +35 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const RequestNonceRequest: z.ZodObject<{
|
|
3
|
+
address: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
4
|
+
}, z.core.$strip>;
|
|
5
|
+
export declare const EmailRegisterRequest: z.ZodObject<{
|
|
6
|
+
email: z.ZodPipe<z.ZodEmail, z.ZodTransform<string, string>>;
|
|
7
|
+
password: z.ZodString;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
export declare const LinkEmailRequest: z.ZodObject<{
|
|
10
|
+
email: z.ZodPipe<z.ZodEmail, z.ZodTransform<string, string>>;
|
|
11
|
+
password: z.ZodString;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
export declare const LinkWalletRequest: z.ZodObject<{
|
|
14
|
+
address: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
15
|
+
signature: z.ZodString;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export declare const WalletLoginRequest: z.ZodObject<{
|
|
18
|
+
method: z.ZodLiteral<"wallet">;
|
|
19
|
+
address: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
20
|
+
signature: z.ZodString;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
export declare const EmailLoginRequest: z.ZodObject<{
|
|
23
|
+
method: z.ZodLiteral<"email">;
|
|
24
|
+
email: z.ZodPipe<z.ZodEmail, z.ZodTransform<string, string>>;
|
|
25
|
+
password: z.ZodString;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
export declare const LoginRequest: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
28
|
+
method: z.ZodLiteral<"wallet">;
|
|
29
|
+
address: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
30
|
+
signature: z.ZodString;
|
|
31
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
32
|
+
method: z.ZodLiteral<"email">;
|
|
33
|
+
email: z.ZodPipe<z.ZodEmail, z.ZodTransform<string, string>>;
|
|
34
|
+
password: z.ZodString;
|
|
35
|
+
}, z.core.$strip>], "method">;
|
|
36
|
+
export declare const RefreshTokenRequest: z.ZodObject<{
|
|
37
|
+
refreshToken: z.ZodString;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
export declare const LogoutRequest: z.ZodObject<{
|
|
40
|
+
refreshToken: z.ZodString;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
export type RequestNonceRequest = z.infer<typeof RequestNonceRequest>;
|
|
43
|
+
export type WalletLoginRequest = z.infer<typeof WalletLoginRequest>;
|
|
44
|
+
export type EmailRegisterRequest = z.infer<typeof EmailRegisterRequest>;
|
|
45
|
+
export type LinkEmailRequest = z.infer<typeof LinkEmailRequest>;
|
|
46
|
+
export type LinkWalletRequest = z.infer<typeof LinkWalletRequest>;
|
|
47
|
+
export type EmailLoginRequest = z.infer<typeof EmailLoginRequest>;
|
|
48
|
+
export type LoginRequest = z.infer<typeof LoginRequest>;
|
|
49
|
+
export type RefreshTokenRequest = z.infer<typeof RefreshTokenRequest>;
|
|
50
|
+
export type LogoutRequest = z.infer<typeof LogoutRequest>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const EthereumAddress = z.string().regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address").transform((val) => val.toLowerCase()).describe("Ethereum wallet address (0x-prefixed, 40 hex chars, lowercase)");
|
|
4
|
+
const Email = z.email("Invalid email address").transform((val) => val.toLowerCase()).describe("Email address (lowercase)");
|
|
5
|
+
const Password = z.string().min(8, "Password must be at least 8 characters").max(128, "Password must be at most 128 characters").describe("Password for authentication");
|
|
6
|
+
const RequestNonceRequest = z.object({
|
|
7
|
+
address: EthereumAddress
|
|
8
|
+
}).describe("Request a nonce for wallet authentication");
|
|
9
|
+
const EmailRegisterRequest = z.object({
|
|
10
|
+
email: Email,
|
|
11
|
+
password: Password
|
|
12
|
+
}).describe("Email registration request");
|
|
13
|
+
const LinkEmailRequest = z.object({
|
|
14
|
+
email: Email,
|
|
15
|
+
password: Password
|
|
16
|
+
}).describe("Link email/password credentials to the authenticated account");
|
|
17
|
+
const LinkWalletRequest = z.object({
|
|
18
|
+
address: EthereumAddress,
|
|
19
|
+
signature: z.string().min(1, "Signature is required").describe("Signature of the nonce message")
|
|
20
|
+
}).describe("Link wallet credentials to the authenticated account");
|
|
21
|
+
const WalletLoginRequest = z.object({
|
|
22
|
+
method: z.literal("wallet").describe('Must be "wallet" for wallet authentication'),
|
|
23
|
+
address: EthereumAddress,
|
|
24
|
+
signature: z.string().min(1, "Signature is required").describe("Signature of the nonce message")
|
|
25
|
+
}).describe("Wallet-based authentication using nonce signature");
|
|
26
|
+
const EmailLoginRequest = z.object({
|
|
27
|
+
method: z.literal("email").describe('Must be "email" for email authentication'),
|
|
28
|
+
email: Email,
|
|
29
|
+
password: Password
|
|
30
|
+
}).describe("Email-based authentication using email and password");
|
|
31
|
+
const LoginRequest = z.discriminatedUnion("method", [WalletLoginRequest, EmailLoginRequest]);
|
|
32
|
+
const RefreshTokenRequest = z.object({
|
|
33
|
+
refreshToken: z.string().min(1, "Refresh token is required").describe("Refresh token")
|
|
34
|
+
}).describe("Refresh token request");
|
|
35
|
+
const LogoutRequest = z.object({
|
|
36
|
+
refreshToken: z.string().min(1, "Refresh token is required").describe("Refresh token to revoke")
|
|
37
|
+
}).describe("Logout and revoke refresh token");
|
|
38
|
+
|
|
39
|
+
export { EmailLoginRequest, EmailRegisterRequest, LinkEmailRequest, LinkWalletRequest, LoginRequest, LogoutRequest, RefreshTokenRequest, RequestNonceRequest, WalletLoginRequest };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const LoginResponse: z.ZodObject<{
|
|
3
|
+
user: z.ZodObject<{
|
|
4
|
+
id: z.ZodUUID;
|
|
5
|
+
role: z.ZodEnum<{
|
|
6
|
+
basic: "basic";
|
|
7
|
+
pro: "pro";
|
|
8
|
+
}>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export declare const RefreshTokenResponse: z.ZodObject<{
|
|
12
|
+
accessToken: z.ZodString;
|
|
13
|
+
refreshToken: z.ZodString;
|
|
14
|
+
tokenType: z.ZodLiteral<"Bearer">;
|
|
15
|
+
expiresIn: z.ZodNumber;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export declare const RefreshSessionResponse: z.ZodObject<{}, z.core.$strip>;
|
|
18
|
+
export declare const LogoutResponse: z.ZodObject<{}, z.core.$strip>;
|
|
19
|
+
export declare const RegisterResponse: z.ZodObject<{
|
|
20
|
+
user: z.ZodObject<{
|
|
21
|
+
id: z.ZodUUID;
|
|
22
|
+
role: z.ZodEnum<{
|
|
23
|
+
basic: "basic";
|
|
24
|
+
pro: "pro";
|
|
25
|
+
}>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
export declare const LinkResponse: z.ZodObject<{
|
|
29
|
+
user: z.ZodObject<{
|
|
30
|
+
id: z.ZodUUID;
|
|
31
|
+
role: z.ZodEnum<{
|
|
32
|
+
basic: "basic";
|
|
33
|
+
pro: "pro";
|
|
34
|
+
}>;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
export declare const RequestNonceResponse: z.ZodObject<{
|
|
38
|
+
nonce: z.ZodString;
|
|
39
|
+
expiresAt: z.ZodNumber;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
export declare const MeResponse: z.ZodObject<{
|
|
42
|
+
id: z.ZodUUID;
|
|
43
|
+
role: z.ZodEnum<{
|
|
44
|
+
basic: "basic";
|
|
45
|
+
pro: "pro";
|
|
46
|
+
}>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
export type RequestNonceResponse = z.infer<typeof RequestNonceResponse>;
|
|
49
|
+
export type LoginResponse = z.infer<typeof LoginResponse>;
|
|
50
|
+
export type RefreshSessionResponse = z.infer<typeof RefreshSessionResponse>;
|
|
51
|
+
export type RefreshTokenResponse = z.infer<typeof RefreshTokenResponse>;
|
|
52
|
+
export type LogoutResponse = z.infer<typeof LogoutResponse>;
|
|
53
|
+
export type RegisterResponse = z.infer<typeof RegisterResponse>;
|
|
54
|
+
export type LinkResponse = z.infer<typeof LinkResponse>;
|
|
55
|
+
export type MeResponse = z.infer<typeof MeResponse>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { AuthenticatedUser } from './entities';
|
|
3
|
+
|
|
4
|
+
const LoginResponse = z.object({ user: AuthenticatedUser }).describe("Successful login response");
|
|
5
|
+
const RefreshTokenResponse = z.object({
|
|
6
|
+
accessToken: z.string().describe("New JWT access token"),
|
|
7
|
+
refreshToken: z.string().describe("New JWT refresh token"),
|
|
8
|
+
tokenType: z.literal("Bearer").describe('Token type (always "Bearer")'),
|
|
9
|
+
expiresIn: z.number().int().positive().describe("Access token expiry time in seconds")
|
|
10
|
+
}).describe("Successful token refresh response");
|
|
11
|
+
const RefreshSessionResponse = z.object({}).describe("Successful session refresh response");
|
|
12
|
+
const LogoutResponse = z.object({}).describe("Successful logout response");
|
|
13
|
+
const RegisterResponse = LoginResponse.describe("Successful registration response");
|
|
14
|
+
const LinkResponse = LoginResponse.describe("Successful link response");
|
|
15
|
+
const RequestNonceResponse = z.object({
|
|
16
|
+
nonce: z.string().describe("Nonce to sign with wallet"),
|
|
17
|
+
expiresAt: z.number().int().positive().describe("Unix timestamp when nonce expires")
|
|
18
|
+
}).describe("Nonce response for wallet authentication");
|
|
19
|
+
const MeResponse = AuthenticatedUser.describe("Current authenticated user info");
|
|
20
|
+
|
|
21
|
+
export { LinkResponse, LoginResponse, LogoutResponse, MeResponse, RefreshSessionResponse, RefreshTokenResponse, RegisterResponse, RequestNonceResponse };
|
package/dist/bundle.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './auth';
|
|
2
|
+
export * from './common/trade-legs';
|
|
3
|
+
export * from './connector';
|
|
4
|
+
export * from './execution';
|
|
5
|
+
export * from './fill';
|
|
6
|
+
export * from './funding';
|
|
7
|
+
export * from './instrument';
|
|
8
|
+
export * from './instrument-precision';
|
|
9
|
+
export * from './misc';
|
|
10
|
+
export * from './order';
|
|
11
|
+
export * from './position';
|
|
12
|
+
export * from './price';
|
|
13
|
+
export * from './schedule';
|
|
14
|
+
export * from './trade';
|
|
15
|
+
export * from './trade-accounts';
|
|
16
|
+
export * from './trigger';
|
|
17
|
+
export * from './users';
|
package/dist/bundle.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './auth';
|
|
2
|
+
export * from './common/trade-legs';
|
|
3
|
+
export * from './connector';
|
|
4
|
+
export * from './execution';
|
|
5
|
+
export * from './fill';
|
|
6
|
+
export * from './funding';
|
|
7
|
+
export * from './instrument';
|
|
8
|
+
export * from './instrument-precision';
|
|
9
|
+
export * from './misc';
|
|
10
|
+
export * from './order';
|
|
11
|
+
export * from './position';
|
|
12
|
+
export * from './price';
|
|
13
|
+
export * from './schedule';
|
|
14
|
+
export * from './trade';
|
|
15
|
+
export * from './trade-accounts';
|
|
16
|
+
export * from './trigger';
|
|
17
|
+
export * from './users';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize an array of values to a string array.
|
|
3
|
+
* Using the zod preprocess function this allows us
|
|
4
|
+
* to correctly type the input instead of getting
|
|
5
|
+
* the 'unknown' type.
|
|
6
|
+
*
|
|
7
|
+
* @param val - The value to normalize.
|
|
8
|
+
* @returns The normalized value.
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeArray<TInput>(val: TInput): (TInput & any[]) | string[] | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function normalizeArray(val) {
|
|
2
|
+
if (!val) return void 0;
|
|
3
|
+
if (Array.isArray(val)) return val;
|
|
4
|
+
if (typeof val === "string") {
|
|
5
|
+
return val.includes(",") ? val.split(",").map((s) => s.trim()) : [val];
|
|
6
|
+
}
|
|
7
|
+
return [String(val)];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { normalizeArray };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
export declare const RefineMinimumOneSymbol: <T extends {
|
|
3
|
+
symbol: string;
|
|
4
|
+
}[]>(basket: T, ctx: z.RefinementCtx) => void;
|
|
5
|
+
export declare const RefineMinimumTwoSymbols: <T extends {
|
|
6
|
+
symbol: string;
|
|
7
|
+
}[]>(basket: T, ctx: z.RefinementCtx) => void;
|
|
8
|
+
export declare const RefineTwoUniqueSymbols: <T extends {
|
|
9
|
+
symbol_a: string;
|
|
10
|
+
symbol_b: string;
|
|
11
|
+
}>(pair: T, ctx: z.RefinementCtx) => void;
|
|
12
|
+
export declare const RefineUniqueSymbols: <T extends {
|
|
13
|
+
symbol: string;
|
|
14
|
+
}[]>(basket: T, ctx: z.RefinementCtx) => void;
|
|
15
|
+
export declare const RefineWeightingSum: <T extends {
|
|
16
|
+
weight: number;
|
|
17
|
+
}[]>(basket: T, ctx: z.RefinementCtx) => void;
|
|
18
|
+
export declare const RefineMinimumOneBuyOneSell: <T extends {
|
|
19
|
+
side: "BUY" | "SELL";
|
|
20
|
+
}[]>(basket: T, ctx: z.RefinementCtx) => void;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import 'zod';
|
|
2
|
+
|
|
3
|
+
const RefineMinimumOneSymbol = (basket, ctx) => {
|
|
4
|
+
if (basket.length < 1) {
|
|
5
|
+
ctx.addIssue({
|
|
6
|
+
code: "custom",
|
|
7
|
+
message: "At least one symbol is required."
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
const RefineMinimumTwoSymbols = (basket, ctx) => {
|
|
12
|
+
if (basket.length < 2) {
|
|
13
|
+
ctx.addIssue({
|
|
14
|
+
code: "custom",
|
|
15
|
+
message: "At least two symbols are required."
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const RefineTwoUniqueSymbols = (pair, ctx) => {
|
|
20
|
+
if (pair.symbol_a === pair.symbol_b) {
|
|
21
|
+
ctx.addIssue({
|
|
22
|
+
code: "custom",
|
|
23
|
+
message: "Symbols cannot be the same."
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const RefineUniqueSymbols = (basket, ctx) => {
|
|
28
|
+
const symbols = basket.map((item) => item.symbol);
|
|
29
|
+
const uniqueSymbols = new Set(symbols);
|
|
30
|
+
if (symbols.length !== uniqueSymbols.size) {
|
|
31
|
+
const duplicates = symbols.filter((symbol, index) => symbols.indexOf(symbol) !== index);
|
|
32
|
+
ctx.addIssue({
|
|
33
|
+
code: "custom",
|
|
34
|
+
message: `Duplicate symbols found: ${[...new Set(duplicates)].join(", ")}`,
|
|
35
|
+
path: ["basket"]
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const RefineWeightingSum = (basket, ctx) => {
|
|
40
|
+
const totalWeight = basket.reduce((acc, curr) => acc + curr.weight, 0);
|
|
41
|
+
if (totalWeight !== 1) {
|
|
42
|
+
ctx.addIssue({
|
|
43
|
+
code: "custom",
|
|
44
|
+
message: `The sum of weights must be exactly 1, but got ${totalWeight}`,
|
|
45
|
+
path: ["basket"]
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const RefineMinimumOneBuyOneSell = (basket, ctx) => {
|
|
50
|
+
const buyCount = basket.filter((item) => item.side === "BUY").length;
|
|
51
|
+
const sellCount = basket.filter((item) => item.side === "SELL").length;
|
|
52
|
+
if (buyCount < 1 || sellCount < 1) {
|
|
53
|
+
ctx.addIssue({
|
|
54
|
+
code: "custom",
|
|
55
|
+
message: "At least one BUY and one SELL are required."
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export { RefineMinimumOneBuyOneSell, RefineMinimumOneSymbol, RefineMinimumTwoSymbols, RefineTwoUniqueSymbols, RefineUniqueSymbols, RefineWeightingSum };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const CursorFindParams: z.ZodObject<{
|
|
3
|
+
limit: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<number>>>;
|
|
4
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
5
|
+
}, z.core.$strip>;
|
|
6
|
+
export declare const PaginationFindParams: z.ZodObject<{
|
|
7
|
+
limit: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<number>>>;
|
|
8
|
+
offset: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<number>>>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
export type CursorFindParams = z.output<typeof CursorFindParams>;
|
|
11
|
+
export type PaginationFindParams = z.output<typeof PaginationFindParams>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const CursorFindParams = z.object({
|
|
4
|
+
/**
|
|
5
|
+
* The maximum number of items to retrieve.
|
|
6
|
+
*/
|
|
7
|
+
limit: z.coerce.number().int().positive().max(100).optional().default(20),
|
|
8
|
+
/**
|
|
9
|
+
* Opaque pagination cursor returned by the API.
|
|
10
|
+
*/
|
|
11
|
+
cursor: z.string().optional()
|
|
12
|
+
});
|
|
13
|
+
const PaginationFindParams = z.object({
|
|
14
|
+
/**
|
|
15
|
+
* The maximum number of items to retrieve.
|
|
16
|
+
*/
|
|
17
|
+
limit: z.coerce.number().int().positive().max(100).optional().default(20),
|
|
18
|
+
/**
|
|
19
|
+
* The number of items to skip before retrieving the returned items.
|
|
20
|
+
*/
|
|
21
|
+
offset: z.coerce.number().int().min(0).optional().default(0)
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export { CursorFindParams, PaginationFindParams };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const PaginatedResponse: z.ZodObject<{
|
|
3
|
+
limit: z.ZodNumber;
|
|
4
|
+
offset: z.ZodNumber;
|
|
5
|
+
count: z.ZodNumber;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
export type PaginatedResponse = z.output<typeof PaginatedResponse>;
|
|
8
|
+
export declare const CursorResponse: z.ZodObject<{
|
|
9
|
+
limit: z.ZodNumber;
|
|
10
|
+
nextCursor: z.ZodUnion<[z.ZodString, z.ZodUndefined]>;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
export type CursorResponse = z.output<typeof CursorResponse>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const PaginatedResponse = z.object({
|
|
4
|
+
/**
|
|
5
|
+
* The maximum number of items retrieved.
|
|
6
|
+
*/
|
|
7
|
+
limit: z.number(),
|
|
8
|
+
/**
|
|
9
|
+
* The number of items to skip before retrieving the returned items.
|
|
10
|
+
*/
|
|
11
|
+
offset: z.number(),
|
|
12
|
+
/**
|
|
13
|
+
* The total number of items.
|
|
14
|
+
*/
|
|
15
|
+
count: z.number()
|
|
16
|
+
});
|
|
17
|
+
const CursorResponse = z.object({
|
|
18
|
+
/**
|
|
19
|
+
* The maximum number of items retrieved.
|
|
20
|
+
*/
|
|
21
|
+
limit: z.number(),
|
|
22
|
+
/**
|
|
23
|
+
* The cursor to use for pagination.
|
|
24
|
+
*/
|
|
25
|
+
nextCursor: z.string().or(z.undefined())
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export { CursorResponse, PaginatedResponse };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
|
|
3
|
+
const UnsignedDecimalString = z.string().regex(/^\d+(\.\d+)?$/, "Must be a valid decimal string");
|
|
4
|
+
const SignedDecimalString = z.string().regex(/^-?\d+(\.\d+)?$/, "Must be a valid decimal string");
|
|
5
|
+
const Leverage = z.int({ message: "Leverage must be an integer" }).positive({ message: "Leverage must be greater than 0" }).max(100, { message: "Leverage must be less than 100" });
|
|
6
|
+
const Side = z.enum(["BUY", "SELL"], {
|
|
7
|
+
message: "Side must be either BUY or SELL"
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export { Leverage, Side, SignedDecimalString, UnsignedDecimalString };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
declare const TradeLegMode: z.ZodEnum<{
|
|
3
|
+
QUANTITY: "QUANTITY";
|
|
4
|
+
USD: "USD";
|
|
5
|
+
}>;
|
|
6
|
+
export type TradeLegMode = z.infer<typeof TradeLegMode>;
|
|
7
|
+
export declare const TradeLeg: z.ZodObject<{
|
|
8
|
+
symbol: z.ZodString;
|
|
9
|
+
side: z.ZodEnum<{
|
|
10
|
+
BUY: "BUY";
|
|
11
|
+
SELL: "SELL";
|
|
12
|
+
}>;
|
|
13
|
+
mode: z.ZodEnum<{
|
|
14
|
+
QUANTITY: "QUANTITY";
|
|
15
|
+
USD: "USD";
|
|
16
|
+
}>;
|
|
17
|
+
amount: z.ZodString;
|
|
18
|
+
reduceOnly: z.ZodBoolean;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
export declare const TradeLegPostOnly: z.ZodObject<{
|
|
21
|
+
symbol: z.ZodString;
|
|
22
|
+
side: z.ZodEnum<{
|
|
23
|
+
BUY: "BUY";
|
|
24
|
+
SELL: "SELL";
|
|
25
|
+
}>;
|
|
26
|
+
mode: z.ZodEnum<{
|
|
27
|
+
QUANTITY: "QUANTITY";
|
|
28
|
+
USD: "USD";
|
|
29
|
+
}>;
|
|
30
|
+
amount: z.ZodString;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
export type TradeLeg = z.infer<typeof TradeLeg>;
|
|
33
|
+
export type TradeLegPostOnly = z.infer<typeof TradeLegPostOnly>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { InstrumentId } from '../instrument';
|
|
3
|
+
import { UnsignedDecimalString, Side } from './schema';
|
|
4
|
+
|
|
5
|
+
const TradeLegMode = z.enum(["QUANTITY", "USD"]);
|
|
6
|
+
const TradeLeg = z.object({
|
|
7
|
+
/**
|
|
8
|
+
* Instrument ID
|
|
9
|
+
*/
|
|
10
|
+
symbol: InstrumentId,
|
|
11
|
+
/**
|
|
12
|
+
* Side
|
|
13
|
+
*/
|
|
14
|
+
side: Side,
|
|
15
|
+
/**
|
|
16
|
+
* Mode to interpret the amount
|
|
17
|
+
*/
|
|
18
|
+
mode: TradeLegMode,
|
|
19
|
+
/**
|
|
20
|
+
* Quantity or USD amount
|
|
21
|
+
*/
|
|
22
|
+
amount: UnsignedDecimalString,
|
|
23
|
+
/**
|
|
24
|
+
* Reduce only flag
|
|
25
|
+
*/
|
|
26
|
+
reduceOnly: z.boolean()
|
|
27
|
+
});
|
|
28
|
+
const TradeLegPostOnly = TradeLeg.omit({ reduceOnly: true });
|
|
29
|
+
|
|
30
|
+
export { TradeLeg, TradeLegPostOnly };
|