@imbingox/acex 0.3.0-beta.1 → 0.3.0-beta.3
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 +71 -24
- package/docs/api.md +1457 -0
- package/package.json +5 -2
- package/src/adapters/binance/adapter.ts +11 -2
- package/src/adapters/binance/market-catalog.ts +2 -2
- package/src/adapters/binance/private-adapter.ts +44 -4
- package/src/adapters/juplend/private-adapter.ts +517 -0
- package/src/adapters/types.ts +34 -4
- package/src/client/context.ts +16 -11
- package/src/client/private-subscription-coordinator.ts +101 -47
- package/src/client/runtime.ts +64 -20
- package/src/client/venue-capabilities.ts +109 -0
- package/src/errors.ts +1 -1
- package/src/internal/filters.ts +9 -9
- package/src/managers/account-manager.ts +95 -58
- package/src/managers/market-manager.ts +45 -45
- package/src/managers/order-manager.ts +49 -56
- package/src/types/account.ts +30 -10
- package/src/types/client.ts +73 -2
- package/src/types/market.ts +12 -16
- package/src/types/order.ts +7 -7
- package/src/types/shared.ts +43 -7
package/src/types/account.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type BigNumber from "bignumber.js";
|
|
2
2
|
import type {
|
|
3
|
-
Exchange,
|
|
4
3
|
PrivateRuntimeReason,
|
|
5
4
|
PrivateRuntimeStatus,
|
|
6
5
|
SubscriptionActivity,
|
|
6
|
+
Venue,
|
|
7
7
|
} from "./shared.ts";
|
|
8
8
|
|
|
9
9
|
export interface AccountDataStatus {
|
|
10
10
|
accountId: string;
|
|
11
|
-
|
|
11
|
+
venue: Venue;
|
|
12
12
|
activity: SubscriptionActivity;
|
|
13
13
|
ready: boolean;
|
|
14
14
|
runtimeStatus?: PrivateRuntimeStatus;
|
|
@@ -21,7 +21,7 @@ export interface AccountDataStatus {
|
|
|
21
21
|
export interface AccountStatusChangedEvent {
|
|
22
22
|
type: "account.status_changed";
|
|
23
23
|
accountId: string;
|
|
24
|
-
|
|
24
|
+
venue: Venue;
|
|
25
25
|
status: AccountDataStatus;
|
|
26
26
|
ts: number;
|
|
27
27
|
}
|
|
@@ -44,13 +44,13 @@ export interface PositionKeyInput {
|
|
|
44
44
|
|
|
45
45
|
export interface AccountEventFilter {
|
|
46
46
|
accountId?: string;
|
|
47
|
-
|
|
47
|
+
venue?: Venue;
|
|
48
48
|
symbol?: string;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
export interface BalanceSnapshot {
|
|
52
52
|
accountId: string;
|
|
53
|
-
|
|
53
|
+
venue: Venue;
|
|
54
54
|
asset: string;
|
|
55
55
|
free: BigNumber;
|
|
56
56
|
used: BigNumber;
|
|
@@ -59,11 +59,21 @@ export interface BalanceSnapshot {
|
|
|
59
59
|
receivedAt: number;
|
|
60
60
|
updatedAt: number;
|
|
61
61
|
seq: number;
|
|
62
|
+
lending?: LendingBalanceFacet;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface LendingBalanceFacet {
|
|
66
|
+
supplied: BigNumber;
|
|
67
|
+
borrowed: BigNumber;
|
|
68
|
+
interest: BigNumber;
|
|
69
|
+
netAsset: BigNumber;
|
|
70
|
+
supplyAPY?: BigNumber;
|
|
71
|
+
borrowAPY?: BigNumber;
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
export interface PositionSnapshot {
|
|
65
75
|
accountId: string;
|
|
66
|
-
|
|
76
|
+
venue: Venue;
|
|
67
77
|
symbol: string;
|
|
68
78
|
side: PositionSide;
|
|
69
79
|
size: BigNumber;
|
|
@@ -80,20 +90,30 @@ export interface PositionSnapshot {
|
|
|
80
90
|
|
|
81
91
|
export interface RiskSnapshot {
|
|
82
92
|
accountId: string;
|
|
83
|
-
|
|
93
|
+
venue: Venue;
|
|
84
94
|
equity?: BigNumber;
|
|
85
|
-
|
|
95
|
+
riskRatio?: BigNumber;
|
|
86
96
|
initialMargin?: BigNumber;
|
|
87
97
|
maintenanceMargin?: BigNumber;
|
|
88
98
|
exchangeTs?: number;
|
|
89
99
|
receivedAt: number;
|
|
90
100
|
updatedAt: number;
|
|
91
101
|
seq: number;
|
|
102
|
+
lending?: LendingRiskFacet;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface LendingRiskFacet {
|
|
106
|
+
marginLevel?: BigNumber;
|
|
107
|
+
healthFactor?: BigNumber;
|
|
108
|
+
ltv?: BigNumber;
|
|
109
|
+
liquidationThreshold?: BigNumber;
|
|
110
|
+
totalCollateralUSD?: BigNumber;
|
|
111
|
+
totalDebtUSD?: BigNumber;
|
|
92
112
|
}
|
|
93
113
|
|
|
94
114
|
export interface AccountSnapshot {
|
|
95
115
|
accountId: string;
|
|
96
|
-
|
|
116
|
+
venue: Venue;
|
|
97
117
|
balances: Record<string, BalanceSnapshot>;
|
|
98
118
|
positions: PositionSnapshot[];
|
|
99
119
|
risk?: RiskSnapshot;
|
|
@@ -104,7 +124,7 @@ export interface AccountSnapshot {
|
|
|
104
124
|
|
|
105
125
|
export interface AccountEventBase {
|
|
106
126
|
accountId: string;
|
|
107
|
-
|
|
127
|
+
venue: Venue;
|
|
108
128
|
ts: number;
|
|
109
129
|
}
|
|
110
130
|
|
package/src/types/client.ts
CHANGED
|
@@ -7,8 +7,10 @@ import type {
|
|
|
7
7
|
MarketDataStatus,
|
|
8
8
|
MarketManager,
|
|
9
9
|
MarketStatusChangedEvent,
|
|
10
|
+
MarketType,
|
|
10
11
|
} from "./market.ts";
|
|
11
12
|
import type {
|
|
13
|
+
CreateOrderType,
|
|
12
14
|
OrderDataStatus,
|
|
13
15
|
OrderManager,
|
|
14
16
|
OrderStatusChangedEvent,
|
|
@@ -18,10 +20,10 @@ import type {
|
|
|
18
20
|
AcexInternalError,
|
|
19
21
|
ClientStatus,
|
|
20
22
|
CreateClientOptions,
|
|
21
|
-
Exchange,
|
|
22
23
|
RegisterAccountInput,
|
|
23
24
|
RegisterAccountResult,
|
|
24
25
|
StopOptions,
|
|
26
|
+
Venue,
|
|
25
27
|
} from "./shared.ts";
|
|
26
28
|
|
|
27
29
|
export interface ClientHealthSnapshot {
|
|
@@ -46,7 +48,7 @@ export type HealthEvent =
|
|
|
46
48
|
|
|
47
49
|
export interface HealthEventFilter {
|
|
48
50
|
scope?: "client" | "market" | "account" | "order";
|
|
49
|
-
|
|
51
|
+
venue?: Venue;
|
|
50
52
|
accountId?: string;
|
|
51
53
|
symbol?: string;
|
|
52
54
|
}
|
|
@@ -56,6 +58,73 @@ export interface ClientEventStreams {
|
|
|
56
58
|
errors(): AsyncIterable<AcexInternalError>;
|
|
57
59
|
}
|
|
58
60
|
|
|
61
|
+
export type VenueRuntimeStatus = "available" | "type_only" | "reserved";
|
|
62
|
+
|
|
63
|
+
export type VenueCapabilitySupport = "supported" | "unsupported";
|
|
64
|
+
|
|
65
|
+
export type VenueCapabilityReason =
|
|
66
|
+
| "not_implemented"
|
|
67
|
+
| "read_only"
|
|
68
|
+
| "market_type_unsupported"
|
|
69
|
+
| "sdk_reserved";
|
|
70
|
+
|
|
71
|
+
export type FundingRateCapability = VenueCapabilitySupport | "market_dependent";
|
|
72
|
+
|
|
73
|
+
export type PrivateUpdateCapability = "websocket" | "polling" | "unsupported";
|
|
74
|
+
|
|
75
|
+
export type CancelAllOrdersCapability = "symbol" | "account" | "unsupported";
|
|
76
|
+
|
|
77
|
+
export type PositionSideCapability =
|
|
78
|
+
| "optional"
|
|
79
|
+
| "required_for_hedge"
|
|
80
|
+
| "unsupported";
|
|
81
|
+
|
|
82
|
+
export type OrderTimeInForceCapability = "gtc" | "post_only";
|
|
83
|
+
|
|
84
|
+
export interface VenueMarketCapabilities {
|
|
85
|
+
catalog: VenueCapabilitySupport;
|
|
86
|
+
l1Book: VenueCapabilitySupport;
|
|
87
|
+
fundingRate: FundingRateCapability;
|
|
88
|
+
marketTypes: MarketType[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface VenueAccountCapabilities {
|
|
92
|
+
register: VenueCapabilitySupport;
|
|
93
|
+
snapshot: VenueCapabilitySupport;
|
|
94
|
+
updates: PrivateUpdateCapability;
|
|
95
|
+
balances: VenueCapabilitySupport;
|
|
96
|
+
positions: VenueCapabilitySupport;
|
|
97
|
+
risk: VenueCapabilitySupport;
|
|
98
|
+
lending: VenueCapabilitySupport;
|
|
99
|
+
credentialsRequired: boolean;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface VenueOrderCapabilities {
|
|
103
|
+
supported: boolean;
|
|
104
|
+
openOrders: VenueCapabilitySupport;
|
|
105
|
+
updates: PrivateUpdateCapability;
|
|
106
|
+
create: VenueCapabilitySupport;
|
|
107
|
+
cancel: VenueCapabilitySupport;
|
|
108
|
+
cancelAll: CancelAllOrdersCapability;
|
|
109
|
+
orderTypes: CreateOrderType[];
|
|
110
|
+
timeInForce: OrderTimeInForceCapability[];
|
|
111
|
+
postOnly: boolean;
|
|
112
|
+
reduceOnly: boolean;
|
|
113
|
+
positionSide: PositionSideCapability;
|
|
114
|
+
clientOrderId: boolean;
|
|
115
|
+
reason?: VenueCapabilityReason;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface VenueCapabilities {
|
|
119
|
+
venue: Venue;
|
|
120
|
+
runtimeStatus: VenueRuntimeStatus;
|
|
121
|
+
readOnly: boolean;
|
|
122
|
+
notes: string[];
|
|
123
|
+
market: VenueMarketCapabilities;
|
|
124
|
+
account: VenueAccountCapabilities;
|
|
125
|
+
order: VenueOrderCapabilities;
|
|
126
|
+
}
|
|
127
|
+
|
|
59
128
|
export interface AcexClient {
|
|
60
129
|
readonly market: MarketManager;
|
|
61
130
|
readonly account: AccountManager;
|
|
@@ -64,6 +133,8 @@ export interface AcexClient {
|
|
|
64
133
|
|
|
65
134
|
getStatus(): ClientStatus;
|
|
66
135
|
getHealth(): ClientHealthSnapshot;
|
|
136
|
+
getVenueCapabilities(venue: Venue): VenueCapabilities;
|
|
137
|
+
listVenueCapabilities(): VenueCapabilities[];
|
|
67
138
|
|
|
68
139
|
registerAccount(input: RegisterAccountInput): Promise<RegisterAccountResult>;
|
|
69
140
|
updateAccountCredentials(
|
package/src/types/market.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type BigNumber from "bignumber.js";
|
|
2
|
-
import type {
|
|
3
|
-
Exchange,
|
|
4
|
-
MarketFreshness,
|
|
5
|
-
SubscriptionActivity,
|
|
6
|
-
} from "./shared.ts";
|
|
2
|
+
import type { MarketFreshness, SubscriptionActivity, Venue } from "./shared.ts";
|
|
7
3
|
|
|
8
4
|
export type MarketType = "spot" | "swap" | "future";
|
|
9
5
|
|
|
10
6
|
export interface MarketDefinition {
|
|
11
|
-
|
|
7
|
+
venue: Venue;
|
|
12
8
|
symbol: string;
|
|
13
9
|
id: string;
|
|
14
10
|
type: MarketType;
|
|
@@ -31,7 +27,7 @@ export interface MarketDefinition {
|
|
|
31
27
|
}
|
|
32
28
|
|
|
33
29
|
export interface MarketDataStatus {
|
|
34
|
-
|
|
30
|
+
venue: Venue;
|
|
35
31
|
symbol: string;
|
|
36
32
|
activity: SubscriptionActivity;
|
|
37
33
|
ready: boolean;
|
|
@@ -53,7 +49,7 @@ export interface MarketDataStreamStatus {
|
|
|
53
49
|
}
|
|
54
50
|
|
|
55
51
|
export interface MarketKeyInput {
|
|
56
|
-
|
|
52
|
+
venue: Venue;
|
|
57
53
|
symbol: string;
|
|
58
54
|
}
|
|
59
55
|
|
|
@@ -89,12 +85,12 @@ export interface SubscribeL1BookInput extends MarketKeyInput {}
|
|
|
89
85
|
export interface SubscribeFundingRateInput extends MarketKeyInput {}
|
|
90
86
|
|
|
91
87
|
export interface MarketEventFilter {
|
|
92
|
-
|
|
88
|
+
venue?: Venue;
|
|
93
89
|
symbol?: string;
|
|
94
90
|
}
|
|
95
91
|
|
|
96
92
|
export interface L1Book {
|
|
97
|
-
|
|
93
|
+
venue: Venue;
|
|
98
94
|
symbol: string;
|
|
99
95
|
bidPrice: BigNumber;
|
|
100
96
|
bidSize: BigNumber;
|
|
@@ -108,7 +104,7 @@ export interface L1Book {
|
|
|
108
104
|
}
|
|
109
105
|
|
|
110
106
|
export interface FundingRateSnapshot {
|
|
111
|
-
|
|
107
|
+
venue: Venue;
|
|
112
108
|
symbol: string;
|
|
113
109
|
fundingRate: BigNumber;
|
|
114
110
|
nextFundingTime?: number;
|
|
@@ -123,7 +119,7 @@ export interface FundingRateSnapshot {
|
|
|
123
119
|
|
|
124
120
|
export interface MarketStatusChangedEvent {
|
|
125
121
|
type: "market.status_changed";
|
|
126
|
-
|
|
122
|
+
venue: Venue;
|
|
127
123
|
symbol: string;
|
|
128
124
|
status: MarketDataStatus;
|
|
129
125
|
ts: number;
|
|
@@ -131,7 +127,7 @@ export interface MarketStatusChangedEvent {
|
|
|
131
127
|
|
|
132
128
|
export interface L1BookUpdatedEvent {
|
|
133
129
|
type: "l1_book.updated";
|
|
134
|
-
|
|
130
|
+
venue: Venue;
|
|
135
131
|
symbol: string;
|
|
136
132
|
snapshot: L1Book;
|
|
137
133
|
ts: number;
|
|
@@ -139,7 +135,7 @@ export interface L1BookUpdatedEvent {
|
|
|
139
135
|
|
|
140
136
|
export interface FundingRateUpdatedEvent {
|
|
141
137
|
type: "funding_rate.updated";
|
|
142
|
-
|
|
138
|
+
venue: Venue;
|
|
143
139
|
symbol: string;
|
|
144
140
|
snapshot: FundingRateSnapshot;
|
|
145
141
|
ts: number;
|
|
@@ -168,9 +164,9 @@ export interface MarketManager {
|
|
|
168
164
|
subscribeFundingRate(input: SubscribeFundingRateInput): Promise<void>;
|
|
169
165
|
unsubscribeFundingRate(input: SubscribeFundingRateInput): Promise<void>;
|
|
170
166
|
|
|
171
|
-
getMarket(
|
|
167
|
+
getMarket(venue: Venue, symbol: string): MarketDefinition | undefined;
|
|
172
168
|
getMarkets(symbol: string): MarketDefinition[];
|
|
173
|
-
listMarkets(
|
|
169
|
+
listMarkets(venue?: Venue): MarketDefinition[];
|
|
174
170
|
normalizeOrderInput(input: NormalizeOrderInputInput): NormalizedOrderInput;
|
|
175
171
|
getL1Book(key: MarketKeyInput): L1Book | undefined;
|
|
176
172
|
getL1Books(symbol: string): L1Book[];
|
package/src/types/order.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type BigNumber from "bignumber.js";
|
|
2
2
|
import type { PositionSide } from "./account.ts";
|
|
3
3
|
import type {
|
|
4
|
-
Exchange,
|
|
5
4
|
PrivateRuntimeReason,
|
|
6
5
|
PrivateRuntimeStatus,
|
|
7
6
|
SubscriptionActivity,
|
|
7
|
+
Venue,
|
|
8
8
|
} from "./shared.ts";
|
|
9
9
|
|
|
10
10
|
export interface OrderDataStatus {
|
|
11
11
|
accountId: string;
|
|
12
|
-
|
|
12
|
+
venue: Venue;
|
|
13
13
|
activity: SubscriptionActivity;
|
|
14
14
|
ready: boolean;
|
|
15
15
|
runtimeStatus?: PrivateRuntimeStatus;
|
|
@@ -22,7 +22,7 @@ export interface OrderDataStatus {
|
|
|
22
22
|
export interface OrderStatusChangedEvent {
|
|
23
23
|
type: "order.status_changed";
|
|
24
24
|
accountId: string;
|
|
25
|
-
|
|
25
|
+
venue: Venue;
|
|
26
26
|
status: OrderDataStatus;
|
|
27
27
|
ts: number;
|
|
28
28
|
}
|
|
@@ -89,13 +89,13 @@ export interface CancelAllOrdersInput {
|
|
|
89
89
|
|
|
90
90
|
export interface OrderEventFilter {
|
|
91
91
|
accountId?: string;
|
|
92
|
-
|
|
92
|
+
venue?: Venue;
|
|
93
93
|
symbol?: string;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
export interface OrderSnapshot {
|
|
97
97
|
accountId: string;
|
|
98
|
-
|
|
98
|
+
venue: Venue;
|
|
99
99
|
orderId?: string;
|
|
100
100
|
clientOrderId?: string;
|
|
101
101
|
symbol: string;
|
|
@@ -118,7 +118,7 @@ export interface OrderSnapshot {
|
|
|
118
118
|
|
|
119
119
|
export interface OrderEventBase {
|
|
120
120
|
accountId: string;
|
|
121
|
-
|
|
121
|
+
venue: Venue;
|
|
122
122
|
symbol: string;
|
|
123
123
|
ts: number;
|
|
124
124
|
}
|
|
@@ -146,7 +146,7 @@ export interface OrderRejectedEvent extends OrderEventBase {
|
|
|
146
146
|
export interface OrderSnapshotReplacedEvent {
|
|
147
147
|
type: "order.snapshot_replaced";
|
|
148
148
|
accountId: string;
|
|
149
|
-
|
|
149
|
+
venue: Venue;
|
|
150
150
|
snapshot: OrderSnapshot[];
|
|
151
151
|
ts: number;
|
|
152
152
|
}
|
package/src/types/shared.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const SUPPORTED_VENUES = [
|
|
2
|
+
"binance",
|
|
3
|
+
"okx",
|
|
4
|
+
"bybit",
|
|
5
|
+
"gate",
|
|
6
|
+
"juplend",
|
|
7
|
+
] as const;
|
|
2
8
|
|
|
3
|
-
export type
|
|
9
|
+
export type Venue = (typeof SUPPORTED_VENUES)[number];
|
|
4
10
|
|
|
5
11
|
export type ClientStatus =
|
|
6
12
|
| "idle"
|
|
@@ -30,6 +36,9 @@ export interface AccountRuntimeOptions {
|
|
|
30
36
|
streamReconnectDelayMs?: number;
|
|
31
37
|
streamReconnectMaxDelayMs?: number;
|
|
32
38
|
listenKeyKeepAliveMs?: number;
|
|
39
|
+
juplend?: {
|
|
40
|
+
pollIntervalMs?: number;
|
|
41
|
+
};
|
|
33
42
|
}
|
|
34
43
|
|
|
35
44
|
export interface CreateClientOptions {
|
|
@@ -47,16 +56,41 @@ export interface AccountCredentials {
|
|
|
47
56
|
extra?: Record<string, string>;
|
|
48
57
|
}
|
|
49
58
|
|
|
50
|
-
export interface
|
|
59
|
+
export interface BinanceAccountOptions {
|
|
60
|
+
timestamp?: number;
|
|
61
|
+
recvWindow?: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface JuplendAccountCredentials {
|
|
65
|
+
apiKey: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface JuplendAccountOptions {
|
|
69
|
+
walletAddress: string;
|
|
70
|
+
positionId?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface RegisterCexAccountInput {
|
|
51
74
|
accountId: string;
|
|
52
|
-
|
|
75
|
+
venue: Exclude<Venue, "juplend">;
|
|
53
76
|
credentials?: AccountCredentials;
|
|
54
|
-
options?:
|
|
77
|
+
options?: BinanceAccountOptions;
|
|
55
78
|
}
|
|
56
79
|
|
|
80
|
+
export interface RegisterJuplendAccountInput {
|
|
81
|
+
accountId: string;
|
|
82
|
+
venue: "juplend";
|
|
83
|
+
credentials: JuplendAccountCredentials;
|
|
84
|
+
options: JuplendAccountOptions;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type RegisterAccountInput =
|
|
88
|
+
| RegisterCexAccountInput
|
|
89
|
+
| RegisterJuplendAccountInput;
|
|
90
|
+
|
|
57
91
|
export interface RegisterAccountResult {
|
|
58
92
|
accountId: string;
|
|
59
|
-
|
|
93
|
+
venue: Venue;
|
|
60
94
|
}
|
|
61
95
|
|
|
62
96
|
export interface StopOptions {
|
|
@@ -66,7 +100,7 @@ export interface StopOptions {
|
|
|
66
100
|
|
|
67
101
|
export interface AcexInternalError {
|
|
68
102
|
source: "client" | "market" | "account" | "order" | "adapter" | "runtime";
|
|
69
|
-
|
|
103
|
+
venue?: Venue;
|
|
70
104
|
accountId?: string;
|
|
71
105
|
symbol?: string;
|
|
72
106
|
error: Error;
|
|
@@ -88,6 +122,8 @@ export type PrivateRuntimeStatus =
|
|
|
88
122
|
export type PrivateRuntimeReason =
|
|
89
123
|
| "credentials_missing"
|
|
90
124
|
| "auth_failed"
|
|
125
|
+
| "http_failed"
|
|
126
|
+
| "rate_limited"
|
|
91
127
|
| "ws_disconnected"
|
|
92
128
|
| "heartbeat_timeout"
|
|
93
129
|
| "reconciling";
|