@imbingox/acex 0.3.0-beta.4 → 0.3.0-beta.6
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 +18 -9
- package/docs/api.md +47 -19
- package/package.json +3 -1
- package/src/adapters/binance/private-adapter.ts +16 -12
- package/src/adapters/juplend/lend-read.ts +150 -0
- package/src/adapters/juplend/private-adapter.ts +434 -163
- package/src/adapters/types.ts +3 -2
- package/src/client/context.ts +1 -1
- package/src/client/private-subscription-coordinator.ts +2 -2
- package/src/client/runtime.ts +4 -1
- package/src/managers/account-manager.ts +12 -8
- package/src/managers/order-manager.ts +8 -0
- package/src/types/account.ts +3 -2
- package/src/types/shared.ts +14 -9
package/src/adapters/types.ts
CHANGED
|
@@ -119,9 +119,10 @@ export interface RawPositionUpdate {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
export interface RawRiskUpdate {
|
|
122
|
-
|
|
122
|
+
netEquity?: string;
|
|
123
|
+
riskEquity?: string;
|
|
123
124
|
riskRatio?: string;
|
|
124
|
-
|
|
125
|
+
riskLeverage?: string;
|
|
125
126
|
initialMargin?: string;
|
|
126
127
|
maintenanceMargin?: string;
|
|
127
128
|
exchangeTs?: number;
|
package/src/client/context.ts
CHANGED
|
@@ -467,7 +467,7 @@ export class PrivateSubscriptionCoordinator {
|
|
|
467
467
|
account: RegisteredAccountRecord,
|
|
468
468
|
): Promise<void> {
|
|
469
469
|
const credentials = account.credentials;
|
|
470
|
-
if (!credentials) {
|
|
470
|
+
if (!credentials && record.venue !== "juplend") {
|
|
471
471
|
throw new AcexError(
|
|
472
472
|
"CREDENTIALS_MISSING",
|
|
473
473
|
`Account credentials are required for private subscriptions: ${account.accountId}`,
|
|
@@ -476,7 +476,7 @@ export class PrivateSubscriptionCoordinator {
|
|
|
476
476
|
|
|
477
477
|
const adapter = this.getAdapter(record.venue);
|
|
478
478
|
const stream = adapter.createPrivateStream(
|
|
479
|
-
credentials,
|
|
479
|
+
credentials ?? {},
|
|
480
480
|
{
|
|
481
481
|
onAccountSnapshot: (snapshot) => {
|
|
482
482
|
if (!record.accountSubscribed) {
|
package/src/client/runtime.ts
CHANGED
|
@@ -106,7 +106,10 @@ export class AcexClientImpl implements AcexClient, ClientContext {
|
|
|
106
106
|
this.marketAdapters = new Map([[marketAdapter.venue, marketAdapter]]);
|
|
107
107
|
const privateAdapters = [
|
|
108
108
|
new BinancePrivateAdapter(),
|
|
109
|
-
new JuplendPrivateAdapter(
|
|
109
|
+
new JuplendPrivateAdapter(
|
|
110
|
+
options.account?.juplend?.rpcUrl,
|
|
111
|
+
options.account?.juplend?.jupApiKey,
|
|
112
|
+
),
|
|
110
113
|
];
|
|
111
114
|
this.privateAdapters = new Map(
|
|
112
115
|
privateAdapters.map((adapter) => [adapter.venue, adapter]),
|
|
@@ -589,18 +589,22 @@ export class AccountManagerImpl
|
|
|
589
589
|
return {
|
|
590
590
|
accountId,
|
|
591
591
|
venue,
|
|
592
|
-
|
|
593
|
-
input.
|
|
594
|
-
? previous?.
|
|
595
|
-
: new BigNumber(input.
|
|
592
|
+
netEquity:
|
|
593
|
+
input.netEquity === undefined
|
|
594
|
+
? previous?.netEquity
|
|
595
|
+
: new BigNumber(input.netEquity),
|
|
596
|
+
riskEquity:
|
|
597
|
+
input.riskEquity === undefined
|
|
598
|
+
? previous?.riskEquity
|
|
599
|
+
: new BigNumber(input.riskEquity),
|
|
596
600
|
riskRatio:
|
|
597
601
|
input.riskRatio === undefined
|
|
598
602
|
? previous?.riskRatio
|
|
599
603
|
: new BigNumber(input.riskRatio),
|
|
600
|
-
|
|
601
|
-
input.
|
|
602
|
-
? previous?.
|
|
603
|
-
: new BigNumber(input.
|
|
604
|
+
riskLeverage:
|
|
605
|
+
input.riskLeverage === undefined
|
|
606
|
+
? previous?.riskLeverage
|
|
607
|
+
: new BigNumber(input.riskLeverage),
|
|
604
608
|
initialMargin:
|
|
605
609
|
input.initialMargin === undefined
|
|
606
610
|
? previous?.initialMargin
|
|
@@ -101,6 +101,13 @@ export class OrderManagerImpl
|
|
|
101
101
|
async subscribeOrders(input: SubscribeOrdersInput): Promise<void> {
|
|
102
102
|
this.context.assertStarted();
|
|
103
103
|
const account = this.context.getRegisteredAccount(input.accountId);
|
|
104
|
+
if (account.venue === "juplend") {
|
|
105
|
+
throw this.createError(
|
|
106
|
+
"VENUE_NOT_SUPPORTED",
|
|
107
|
+
`Venue does not support private order subscriptions: ${account.venue}`,
|
|
108
|
+
{ accountId: input.accountId, venue: account.venue },
|
|
109
|
+
);
|
|
110
|
+
}
|
|
104
111
|
this.context.ensurePrivateCredentials(input.accountId);
|
|
105
112
|
|
|
106
113
|
const record = this.getOrCreateRecord(input.accountId, account.venue);
|
|
@@ -635,6 +642,7 @@ export class OrderManagerImpl
|
|
|
635
642
|
|
|
636
643
|
private createError(
|
|
637
644
|
code:
|
|
645
|
+
| "VENUE_NOT_SUPPORTED"
|
|
638
646
|
| "ORDER_CANCEL_ALL_FAILED"
|
|
639
647
|
| "ORDER_CANCEL_FAILED"
|
|
640
648
|
| "ORDER_CREATE_FAILED"
|
package/src/types/account.ts
CHANGED
|
@@ -91,9 +91,10 @@ export interface PositionSnapshot {
|
|
|
91
91
|
export interface RiskSnapshot {
|
|
92
92
|
accountId: string;
|
|
93
93
|
venue: Venue;
|
|
94
|
-
|
|
94
|
+
netEquity?: BigNumber;
|
|
95
|
+
riskEquity?: BigNumber;
|
|
95
96
|
riskRatio?: BigNumber;
|
|
96
|
-
|
|
97
|
+
riskLeverage?: BigNumber;
|
|
97
98
|
initialMargin?: BigNumber;
|
|
98
99
|
maintenanceMargin?: BigNumber;
|
|
99
100
|
exchangeTs?: number;
|
package/src/types/shared.ts
CHANGED
|
@@ -41,6 +41,8 @@ export interface AccountRuntimeOptions {
|
|
|
41
41
|
};
|
|
42
42
|
juplend?: {
|
|
43
43
|
pollIntervalMs?: number;
|
|
44
|
+
rpcUrl?: string;
|
|
45
|
+
jupApiKey?: string;
|
|
44
46
|
};
|
|
45
47
|
}
|
|
46
48
|
|
|
@@ -64,14 +66,17 @@ export interface BinanceAccountOptions {
|
|
|
64
66
|
recvWindow?: number;
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
export
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
export type JuplendAccountOptions =
|
|
70
|
+
| {
|
|
71
|
+
walletAddress: string;
|
|
72
|
+
vaultId?: string;
|
|
73
|
+
positionId?: string;
|
|
74
|
+
}
|
|
75
|
+
| {
|
|
76
|
+
walletAddress?: string;
|
|
77
|
+
vaultId: string;
|
|
78
|
+
positionId: string;
|
|
79
|
+
};
|
|
75
80
|
|
|
76
81
|
export interface RegisterCexAccountInput {
|
|
77
82
|
accountId: string;
|
|
@@ -83,7 +88,7 @@ export interface RegisterCexAccountInput {
|
|
|
83
88
|
export interface RegisterJuplendAccountInput {
|
|
84
89
|
accountId: string;
|
|
85
90
|
venue: "juplend";
|
|
86
|
-
credentials
|
|
91
|
+
credentials?: AccountCredentials;
|
|
87
92
|
options: JuplendAccountOptions;
|
|
88
93
|
}
|
|
89
94
|
|