@andy-liquid-labs/lighter-ts-sdk 1.0.0
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/README.md +381 -0
- package/dist/index.d.mts +3686 -0
- package/dist/index.d.ts +3686 -0
- package/dist/index.js +6168 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5939 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +57 -0
- package/src/api/exchange/change-account-tier.ts +38 -0
- package/src/api/exchange/fastwithdraw.ts +38 -0
- package/src/api/exchange/index.ts +7 -0
- package/src/api/exchange/notification-ack.ts +36 -0
- package/src/api/exchange/send-tx-batch.ts +53 -0
- package/src/api/exchange/send-tx.ts +105 -0
- package/src/api/exchange/tokens-create.ts +50 -0
- package/src/api/exchange/tokens-revoke.ts +38 -0
- package/src/api/index.ts +3 -0
- package/src/api/info/account-by-l1-address.ts +23 -0
- package/src/api/info/account.ts +80 -0
- package/src/api/info/announcement.ts +24 -0
- package/src/api/info/api-keys.ts +32 -0
- package/src/api/info/asset-details.ts +42 -0
- package/src/api/info/candles.ts +31 -0
- package/src/api/info/exchange-stats.ts +16 -0
- package/src/api/info/fastbridge-info.ts +15 -0
- package/src/api/info/funding-rates.ts +22 -0
- package/src/api/info/fundings.ts +29 -0
- package/src/api/info/index.ts +20 -0
- package/src/api/info/next-nonce.ts +26 -0
- package/src/api/info/order-book-details.ts +125 -0
- package/src/api/info/order-books.ts +23 -0
- package/src/api/info/recent-trades.ts +24 -0
- package/src/api/info/root-info.ts +13 -0
- package/src/api/info/root-status.ts +13 -0
- package/src/api/info/tx-from-l1-hash.ts +20 -0
- package/src/api/info/tx.ts +45 -0
- package/src/api/info/txs.ts +19 -0
- package/src/api/info/withdrawal-delay.ts +13 -0
- package/src/api/info-private/account-active-orders.ts +31 -0
- package/src/api/info-private/account-inactive-orders.ts +83 -0
- package/src/api/info-private/account-limits.ts +35 -0
- package/src/api/info-private/account-metadata.ts +43 -0
- package/src/api/info-private/deposit-history.ts +49 -0
- package/src/api/info-private/export.ts +41 -0
- package/src/api/info-private/fastwithdraw-info.ts +35 -0
- package/src/api/info-private/index.ts +18 -0
- package/src/api/info-private/l1-metadata.ts +35 -0
- package/src/api/info-private/liquidations.ts +96 -0
- package/src/api/info-private/pnl.ts +52 -0
- package/src/api/info-private/position-funding.ts +54 -0
- package/src/api/info-private/public-pools-metadata.ts +46 -0
- package/src/api/info-private/referral-points.ts +43 -0
- package/src/api/info-private/tokens.ts +44 -0
- package/src/api/info-private/trades.ts +66 -0
- package/src/api/info-private/transfer-fee-info.ts +37 -0
- package/src/api/info-private/transfer-history.ts +54 -0
- package/src/api/info-private/withdraw-history.ts +49 -0
- package/src/client/clientManager.ts +121 -0
- package/src/client/exchange-client.ts +637 -0
- package/src/client/http/client.ts +137 -0
- package/src/client/http/index.ts +6 -0
- package/src/client/http/interface.ts +89 -0
- package/src/client/index.ts +11 -0
- package/src/client/info-client.ts +383 -0
- package/src/client/info-private-client.ts +444 -0
- package/src/client/txClient.ts +597 -0
- package/src/client/ws-client.ts +457 -0
- package/src/crypto/ecgfp5.ts +722 -0
- package/src/crypto/goldilocks.ts +136 -0
- package/src/crypto/gorand.ts +777 -0
- package/src/crypto/index.ts +6 -0
- package/src/crypto/poseidon2.ts +365 -0
- package/src/crypto/scalar.ts +375 -0
- package/src/index.ts +112 -0
- package/src/signer/index.ts +5 -0
- package/src/signer/keyManager.ts +132 -0
- package/src/types/bridge.ts +24 -0
- package/src/types/constants.ts +252 -0
- package/src/types/errors.ts +168 -0
- package/src/types/index.ts +12 -0
- package/src/types/requests.ts +197 -0
- package/src/types/txInfo.ts +1277 -0
- package/src/types/txInfoPools.ts +502 -0
- package/src/types/txInfoSerializer.ts +348 -0
- package/src/types/ws.ts +407 -0
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@andy-liquid-labs/lighter-ts-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript SDK for Lighter - signing & hashing of Lighter transactions",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"import": "./dist/index.mjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"test:watch": "vitest",
|
|
23
|
+
"lint": "eslint src --ext .ts",
|
|
24
|
+
"typecheck": "tsc --noEmit",
|
|
25
|
+
"prepublishOnly": "npm run build"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"lighter",
|
|
29
|
+
"sdk",
|
|
30
|
+
"trading",
|
|
31
|
+
"crypto",
|
|
32
|
+
"signing"
|
|
33
|
+
],
|
|
34
|
+
"author": "",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/elliottech/lighter-ts-sdk"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^25.0.10",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^6.13.0",
|
|
43
|
+
"@typescript-eslint/parser": "^6.13.0",
|
|
44
|
+
"eslint": "^8.55.0",
|
|
45
|
+
"tsup": "^8.0.0",
|
|
46
|
+
"typescript": "^5.3.0",
|
|
47
|
+
"vitest": "^1.0.0"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=18.0.0"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"axios": "^1.13.3",
|
|
54
|
+
"js-sha256": "^0.11.1",
|
|
55
|
+
"reconnecting-websocket": "^4.4.0"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
2
|
+
|
|
3
|
+
export interface ChangeAccountTierRequest {
|
|
4
|
+
account_index: number;
|
|
5
|
+
new_tier: string;
|
|
6
|
+
auth?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ChangeAccountTierResponse {
|
|
10
|
+
code: number;
|
|
11
|
+
message?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function changeAccountTier(
|
|
15
|
+
client: AxiosInstance,
|
|
16
|
+
params: ChangeAccountTierRequest,
|
|
17
|
+
authorization?: string,
|
|
18
|
+
): Promise<ChangeAccountTierResponse> {
|
|
19
|
+
const config: AxiosRequestConfig = {
|
|
20
|
+
headers: {},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if (authorization) {
|
|
24
|
+
config.headers = { Authorization: authorization };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return client
|
|
28
|
+
.post<ChangeAccountTierResponse>(
|
|
29
|
+
"/api/v1/changeAccountTier",
|
|
30
|
+
{
|
|
31
|
+
account_index: params.account_index,
|
|
32
|
+
new_tier: params.new_tier,
|
|
33
|
+
...(params.auth ? { auth: params.auth } : {}),
|
|
34
|
+
},
|
|
35
|
+
config,
|
|
36
|
+
)
|
|
37
|
+
.then((response) => response.data);
|
|
38
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
2
|
+
|
|
3
|
+
export interface FastWithdrawRequest {
|
|
4
|
+
tx_info: string;
|
|
5
|
+
to_address: string;
|
|
6
|
+
auth?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface FastWithdrawResponse {
|
|
10
|
+
code: number;
|
|
11
|
+
message?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function fastWithdraw(
|
|
15
|
+
client: AxiosInstance,
|
|
16
|
+
params: FastWithdrawRequest,
|
|
17
|
+
authorization?: string,
|
|
18
|
+
): Promise<FastWithdrawResponse> {
|
|
19
|
+
const config: AxiosRequestConfig = {
|
|
20
|
+
headers: {},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if (authorization) {
|
|
24
|
+
config.headers = { Authorization: authorization };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return client
|
|
28
|
+
.post<FastWithdrawResponse>(
|
|
29
|
+
"/api/v1/fastwithdraw",
|
|
30
|
+
{
|
|
31
|
+
tx_info: params.tx_info,
|
|
32
|
+
to_address: params.to_address,
|
|
33
|
+
...(params.auth ? { auth: params.auth } : {}),
|
|
34
|
+
},
|
|
35
|
+
config,
|
|
36
|
+
)
|
|
37
|
+
.then((response) => response.data);
|
|
38
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
|
|
3
|
+
export interface NotificationAckRequest {
|
|
4
|
+
notif_id: string;
|
|
5
|
+
account_index: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface NotificationAckResponse {
|
|
9
|
+
code: number;
|
|
10
|
+
message?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function acknowledgeNotification(
|
|
14
|
+
client: AxiosInstance,
|
|
15
|
+
params: NotificationAckRequest,
|
|
16
|
+
authorization?: string,
|
|
17
|
+
): Promise<NotificationAckResponse> {
|
|
18
|
+
const queryParams: Record<string, string> = {
|
|
19
|
+
notif_id: params.notif_id,
|
|
20
|
+
account_index: params.account_index.toString(),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const headers: Record<string, string> = {};
|
|
24
|
+
if (authorization) {
|
|
25
|
+
headers["Authorization"] = authorization;
|
|
26
|
+
headers["auth"] = authorization;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return client
|
|
30
|
+
.post<NotificationAckResponse>(
|
|
31
|
+
"/api/v1/notification/ack",
|
|
32
|
+
{},
|
|
33
|
+
{ params: queryParams, headers },
|
|
34
|
+
)
|
|
35
|
+
.then((response) => response.data);
|
|
36
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
|
|
3
|
+
export interface SendTransactionBatchFormRequest {
|
|
4
|
+
tx_types: string;
|
|
5
|
+
tx_infos: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface SendTransactionBatchJsonRequest {
|
|
9
|
+
account_index: number;
|
|
10
|
+
api_key_index: number;
|
|
11
|
+
transactions: string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type SendTransactionBatchRequest =
|
|
15
|
+
| SendTransactionBatchFormRequest
|
|
16
|
+
| SendTransactionBatchJsonRequest;
|
|
17
|
+
|
|
18
|
+
export interface TxHashesResponse {
|
|
19
|
+
hashes?: string[];
|
|
20
|
+
tx_hash?: string[];
|
|
21
|
+
code?: number;
|
|
22
|
+
message?: string;
|
|
23
|
+
predicted_execution_time_ms?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function sendTransactionBatch(
|
|
27
|
+
client: AxiosInstance,
|
|
28
|
+
params: SendTransactionBatchRequest,
|
|
29
|
+
): Promise<TxHashesResponse> {
|
|
30
|
+
if ("tx_types" in params && "tx_infos" in params) {
|
|
31
|
+
const urlParams = new URLSearchParams();
|
|
32
|
+
urlParams.append("tx_types", params.tx_types);
|
|
33
|
+
urlParams.append("tx_infos", params.tx_infos);
|
|
34
|
+
|
|
35
|
+
return client
|
|
36
|
+
.post<TxHashesResponse>("/api/v1/sendTxBatch", urlParams, {
|
|
37
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
38
|
+
})
|
|
39
|
+
.then((response) => response.data);
|
|
40
|
+
} else if ("transactions" in params) {
|
|
41
|
+
return client
|
|
42
|
+
.post<TxHashesResponse>("/api/v1/sendTxBatch", {
|
|
43
|
+
account_index: params.account_index,
|
|
44
|
+
api_key_index: params.api_key_index,
|
|
45
|
+
transactions: params.transactions,
|
|
46
|
+
})
|
|
47
|
+
.then((response) => response.data);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw new Error(
|
|
51
|
+
"Invalid batch params: must provide either (tx_types, tx_infos) or (transactions)",
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
|
|
3
|
+
export interface SendTransactionRequest {
|
|
4
|
+
account_index: number;
|
|
5
|
+
api_key_index: number;
|
|
6
|
+
transaction: string;
|
|
7
|
+
price_protection?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SendTxFormRequest {
|
|
11
|
+
tx_type: number;
|
|
12
|
+
tx_info: string;
|
|
13
|
+
price_protection?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface SendTxWithIndicesRequest {
|
|
17
|
+
tx_type: number;
|
|
18
|
+
tx_info: string;
|
|
19
|
+
account_index: number;
|
|
20
|
+
api_key_index: number;
|
|
21
|
+
price_protection?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface TxHashResponse {
|
|
25
|
+
hash?: string;
|
|
26
|
+
tx_hash?: string;
|
|
27
|
+
code?: number;
|
|
28
|
+
message?: string;
|
|
29
|
+
predicted_execution_time_ms?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function sendTransaction(
|
|
33
|
+
client: AxiosInstance,
|
|
34
|
+
params: SendTransactionRequest,
|
|
35
|
+
): Promise<TxHashResponse> {
|
|
36
|
+
return client
|
|
37
|
+
.post<TxHashResponse>("/api/v1/sendTx", {
|
|
38
|
+
account_index: params.account_index,
|
|
39
|
+
api_key_index: params.api_key_index,
|
|
40
|
+
transaction: params.transaction,
|
|
41
|
+
...(params.price_protection !== undefined
|
|
42
|
+
? { price_protection: params.price_protection }
|
|
43
|
+
: {}),
|
|
44
|
+
})
|
|
45
|
+
.then((response) => response.data);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function sendTx(
|
|
49
|
+
client: AxiosInstance,
|
|
50
|
+
params: SendTxFormRequest,
|
|
51
|
+
): Promise<TxHashResponse> {
|
|
52
|
+
const urlParams = new URLSearchParams();
|
|
53
|
+
urlParams.append("tx_type", params.tx_type.toString());
|
|
54
|
+
urlParams.append("tx_info", params.tx_info);
|
|
55
|
+
urlParams.append(
|
|
56
|
+
"price_protection",
|
|
57
|
+
params.price_protection !== false ? "true" : "false",
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return client
|
|
61
|
+
.post<TxHashResponse>("/api/v1/sendTx", urlParams, {
|
|
62
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
63
|
+
})
|
|
64
|
+
.then((response) => response.data);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function sendTxWithIndices(
|
|
68
|
+
client: AxiosInstance,
|
|
69
|
+
params: SendTxWithIndicesRequest,
|
|
70
|
+
): Promise<TxHashResponse> {
|
|
71
|
+
const urlParams = new URLSearchParams();
|
|
72
|
+
urlParams.append("tx_type", params.tx_type.toString());
|
|
73
|
+
urlParams.append("tx_info", params.tx_info);
|
|
74
|
+
urlParams.append("account_index", params.account_index.toString());
|
|
75
|
+
urlParams.append("api_key_index", params.api_key_index.toString());
|
|
76
|
+
urlParams.append(
|
|
77
|
+
"price_protection",
|
|
78
|
+
params.price_protection !== false ? "true" : "false",
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return client
|
|
82
|
+
.post<TxHashResponse>("/api/v1/sendTx", urlParams, {
|
|
83
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
84
|
+
})
|
|
85
|
+
.then((response) => response.data);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function sendTxJson(
|
|
89
|
+
client: AxiosInstance,
|
|
90
|
+
params: SendTxWithIndicesRequest,
|
|
91
|
+
): Promise<TxHashResponse> {
|
|
92
|
+
const payload = {
|
|
93
|
+
tx_type: params.tx_type,
|
|
94
|
+
tx_info: params.tx_info,
|
|
95
|
+
account_index: params.account_index,
|
|
96
|
+
api_key_index: params.api_key_index,
|
|
97
|
+
price_protection: params.price_protection !== false,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
return client
|
|
101
|
+
.post<TxHashResponse>("/api/v1/sendTx", payload, {
|
|
102
|
+
headers: { "Content-Type": "application/json" },
|
|
103
|
+
})
|
|
104
|
+
.then((response) => response.data);
|
|
105
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
2
|
+
|
|
3
|
+
export interface TokensCreateRequest {
|
|
4
|
+
name: string;
|
|
5
|
+
account_index: number;
|
|
6
|
+
expiry: number;
|
|
7
|
+
sub_account_access: boolean;
|
|
8
|
+
scopes?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface TokensCreateResponse {
|
|
12
|
+
code: number;
|
|
13
|
+
message?: string;
|
|
14
|
+
token_id: number;
|
|
15
|
+
api_token: string;
|
|
16
|
+
name: string;
|
|
17
|
+
account_index: number;
|
|
18
|
+
expiry: number;
|
|
19
|
+
sub_account_access: boolean;
|
|
20
|
+
revoked: boolean;
|
|
21
|
+
scopes: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function createToken(
|
|
25
|
+
client: AxiosInstance,
|
|
26
|
+
params: TokensCreateRequest,
|
|
27
|
+
authorization?: string,
|
|
28
|
+
): Promise<TokensCreateResponse> {
|
|
29
|
+
const config: AxiosRequestConfig = {
|
|
30
|
+
headers: {},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
if (authorization) {
|
|
34
|
+
config.headers = { Authorization: authorization };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return client
|
|
38
|
+
.post<TokensCreateResponse>(
|
|
39
|
+
"/api/v1/tokens/create",
|
|
40
|
+
{
|
|
41
|
+
name: params.name,
|
|
42
|
+
account_index: params.account_index,
|
|
43
|
+
expiry: params.expiry,
|
|
44
|
+
sub_account_access: params.sub_account_access,
|
|
45
|
+
...(params.scopes ? { scopes: params.scopes } : { scopes: "read.*" }),
|
|
46
|
+
},
|
|
47
|
+
config,
|
|
48
|
+
)
|
|
49
|
+
.then((response) => response.data);
|
|
50
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
2
|
+
|
|
3
|
+
export interface TokensRevokeRequest {
|
|
4
|
+
token_id: number;
|
|
5
|
+
account_index: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface TokensRevokeResponse {
|
|
9
|
+
code: number;
|
|
10
|
+
message?: string;
|
|
11
|
+
token_id: number;
|
|
12
|
+
revoked: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function revokeToken(
|
|
16
|
+
client: AxiosInstance,
|
|
17
|
+
params: TokensRevokeRequest,
|
|
18
|
+
authorization?: string,
|
|
19
|
+
): Promise<TokensRevokeResponse> {
|
|
20
|
+
const config: AxiosRequestConfig = {
|
|
21
|
+
headers: {},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
if (authorization) {
|
|
25
|
+
config.headers = { Authorization: authorization };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return client
|
|
29
|
+
.post<TokensRevokeResponse>(
|
|
30
|
+
"/api/v1/tokens/revoke",
|
|
31
|
+
{
|
|
32
|
+
token_id: params.token_id,
|
|
33
|
+
account_index: params.account_index,
|
|
34
|
+
},
|
|
35
|
+
config,
|
|
36
|
+
)
|
|
37
|
+
.then((response) => response.data);
|
|
38
|
+
}
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
|
|
3
|
+
export interface AccountByL1AddressRequest {
|
|
4
|
+
l1_address: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface AccountAccountByL1AddressResponse {
|
|
8
|
+
code: number;
|
|
9
|
+
message?: string;
|
|
10
|
+
account_index: number;
|
|
11
|
+
l1_address: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function getAccountByL1Address(
|
|
15
|
+
client: AxiosInstance,
|
|
16
|
+
params: AccountByL1AddressRequest,
|
|
17
|
+
): Promise<AccountAccountByL1AddressResponse> {
|
|
18
|
+
return client
|
|
19
|
+
.get<AccountAccountByL1AddressResponse>("/api/v1/accountByL1Address", {
|
|
20
|
+
params: params,
|
|
21
|
+
})
|
|
22
|
+
.then((response) => response.data);
|
|
23
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
|
|
3
|
+
export interface AccountRequest {
|
|
4
|
+
by: "index" | "l1_address";
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface AccountPosition {
|
|
9
|
+
market_id: number;
|
|
10
|
+
symbol: string;
|
|
11
|
+
initial_margin_fraction: string;
|
|
12
|
+
open_order_count: number;
|
|
13
|
+
pending_order_count: number;
|
|
14
|
+
position_tied_order_count: number;
|
|
15
|
+
sign: number;
|
|
16
|
+
position: string;
|
|
17
|
+
avg_entry_price: string;
|
|
18
|
+
position_value: string;
|
|
19
|
+
unrealized_pnl: string;
|
|
20
|
+
realized_pnl: string;
|
|
21
|
+
liquidation_price: string;
|
|
22
|
+
margin_mode: number;
|
|
23
|
+
allocated_margin: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface AccountAsset {
|
|
27
|
+
symbol: string;
|
|
28
|
+
asset_id: number;
|
|
29
|
+
balance: string;
|
|
30
|
+
locked_balance: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface AccountShare {
|
|
34
|
+
public_pool_index: number;
|
|
35
|
+
shares_amount: number;
|
|
36
|
+
entry_usdc: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface AccountInfo {
|
|
40
|
+
code: number;
|
|
41
|
+
message?: string;
|
|
42
|
+
account_type: number;
|
|
43
|
+
index: number;
|
|
44
|
+
l1_address: string;
|
|
45
|
+
cancel_all_time: number;
|
|
46
|
+
total_order_count: number;
|
|
47
|
+
total_isolated_order_count: number;
|
|
48
|
+
pending_order_count: number;
|
|
49
|
+
available_balance: string;
|
|
50
|
+
status: number;
|
|
51
|
+
collateral: string;
|
|
52
|
+
account_index: number;
|
|
53
|
+
name: string;
|
|
54
|
+
description: string;
|
|
55
|
+
can_invite: boolean;
|
|
56
|
+
referral_points_percentage: string;
|
|
57
|
+
positions: AccountPosition[];
|
|
58
|
+
assets: AccountAsset[];
|
|
59
|
+
total_asset_value: string;
|
|
60
|
+
cross_asset_value: string;
|
|
61
|
+
shares: AccountShare[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface AccountResponse {
|
|
65
|
+
code: number;
|
|
66
|
+
message?: string;
|
|
67
|
+
total: number;
|
|
68
|
+
accounts: AccountInfo[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function getAccountInfo(
|
|
72
|
+
client: AxiosInstance,
|
|
73
|
+
params: AccountRequest,
|
|
74
|
+
): Promise<AccountResponse> {
|
|
75
|
+
return client
|
|
76
|
+
.get<AccountResponse>("/api/v1/account", {
|
|
77
|
+
params: params,
|
|
78
|
+
})
|
|
79
|
+
.then((response) => response.data);
|
|
80
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
|
|
3
|
+
export interface Announcement {
|
|
4
|
+
id: number;
|
|
5
|
+
title: string;
|
|
6
|
+
content: string;
|
|
7
|
+
created_at: number;
|
|
8
|
+
updated_at: number;
|
|
9
|
+
is_active: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface AnnouncementsResponse {
|
|
13
|
+
code: number;
|
|
14
|
+
message?: string;
|
|
15
|
+
announcements: Announcement[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function getAnnouncements(
|
|
19
|
+
client: AxiosInstance,
|
|
20
|
+
): Promise<AnnouncementsResponse> {
|
|
21
|
+
return client
|
|
22
|
+
.get<AnnouncementsResponse>("/api/v1/announcements")
|
|
23
|
+
.then((response) => response.data);
|
|
24
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
|
|
3
|
+
export interface ApiKeysRequest {
|
|
4
|
+
account_index: number;
|
|
5
|
+
api_key_index: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ApiKey {
|
|
9
|
+
account_index: number;
|
|
10
|
+
api_key_index: number;
|
|
11
|
+
nonce: number;
|
|
12
|
+
public_key: string;
|
|
13
|
+
transaction_time: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ApiKeysResponse {
|
|
17
|
+
api_keys: ApiKey[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function getApiKeys(
|
|
21
|
+
client: AxiosInstance,
|
|
22
|
+
params: ApiKeysRequest,
|
|
23
|
+
): Promise<ApiKeysResponse> {
|
|
24
|
+
return client
|
|
25
|
+
.get<ApiKeysResponse>("/api/v1/apikeys", {
|
|
26
|
+
params: {
|
|
27
|
+
account_index: params.account_index,
|
|
28
|
+
api_key_index: params.api_key_index,
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
.then((response) => response.data);
|
|
32
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
2
|
+
|
|
3
|
+
export interface AssetDetailsRequest {
|
|
4
|
+
asset_id?: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface AssetDetail {
|
|
8
|
+
asset_id: number;
|
|
9
|
+
symbol: string;
|
|
10
|
+
l1_decimals: number;
|
|
11
|
+
decimals: number;
|
|
12
|
+
extension_multiplier: number;
|
|
13
|
+
min_transfer_amount: number;
|
|
14
|
+
min_withdrawal_amount: number;
|
|
15
|
+
margin_mode: number;
|
|
16
|
+
index_price: number;
|
|
17
|
+
l1_address: string;
|
|
18
|
+
tick_size: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AssetDetailsResponse {
|
|
22
|
+
code: number;
|
|
23
|
+
message?: string;
|
|
24
|
+
asset_details: AssetDetail[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function getAssetDetails(
|
|
28
|
+
client: AxiosInstance,
|
|
29
|
+
params?: AssetDetailsRequest,
|
|
30
|
+
): Promise<AssetDetailsResponse> {
|
|
31
|
+
const config: AxiosRequestConfig = {
|
|
32
|
+
params: {
|
|
33
|
+
...(params?.asset_id !== undefined
|
|
34
|
+
? { asset_id: params.asset_id }
|
|
35
|
+
: {}),
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return client
|
|
40
|
+
.get<AssetDetailsResponse>("/api/v1/assetDetails", config)
|
|
41
|
+
.then((response) => response.data);
|
|
42
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
|
|
3
|
+
export interface Candlestick {
|
|
4
|
+
t: number;
|
|
5
|
+
o: number;
|
|
6
|
+
h: number;
|
|
7
|
+
l: number;
|
|
8
|
+
c: number;
|
|
9
|
+
v: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface CandlesRequest {
|
|
13
|
+
market_id: number;
|
|
14
|
+
resolution: string;
|
|
15
|
+
start_timestamp: number;
|
|
16
|
+
end_timestamp: number;
|
|
17
|
+
count_back: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface CandlesResponse {
|
|
21
|
+
c: Candlestick[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function getCandlesticks(
|
|
25
|
+
client: AxiosInstance,
|
|
26
|
+
params: CandlesRequest,
|
|
27
|
+
): Promise<CandlesResponse> {
|
|
28
|
+
return client
|
|
29
|
+
.get<CandlesResponse>("/api/v1/candles", { params })
|
|
30
|
+
.then((response) => response.data);
|
|
31
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
|
|
3
|
+
export interface ExchangeStatsResponse {
|
|
4
|
+
total_volume_24h: string;
|
|
5
|
+
total_trades_24h: number;
|
|
6
|
+
total_orders_24h: number;
|
|
7
|
+
active_markets: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function getExchangeStats(
|
|
11
|
+
client: AxiosInstance,
|
|
12
|
+
): Promise<ExchangeStatsResponse> {
|
|
13
|
+
return client
|
|
14
|
+
.get<ExchangeStatsResponse>("/api/v1/exchangeStats")
|
|
15
|
+
.then((response) => response.data);
|
|
16
|
+
}
|