@crypticdot/defituna-api 1.2.1 → 1.3.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/index.d.mts +421 -85
- package/dist/index.d.ts +421 -85
- package/dist/index.js +103 -5
- package/dist/index.mjs +103 -5
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -86,6 +86,12 @@ __export(schemas_exports, {
|
|
|
86
86
|
StakingTreasury: () => StakingTreasury,
|
|
87
87
|
Tick: () => Tick,
|
|
88
88
|
TokenOraclePrice: () => TokenOraclePrice,
|
|
89
|
+
TradeHistoryAction: () => TradeHistoryAction,
|
|
90
|
+
TradeHistoryActionSchema: () => TradeHistoryActionSchema,
|
|
91
|
+
TradeHistoryEntry: () => TradeHistoryEntry,
|
|
92
|
+
TradeHistoryEntryNotification: () => TradeHistoryEntryNotification,
|
|
93
|
+
TradeHistoryUIDirection: () => TradeHistoryUIDirection,
|
|
94
|
+
TradeHistoryUIDirectionSchema: () => TradeHistoryUIDirectionSchema,
|
|
89
95
|
TunaPosition: () => TunaPosition,
|
|
90
96
|
TunaPositionNotification: () => TunaPositionNotification,
|
|
91
97
|
TunaPositionState: () => TunaPositionState,
|
|
@@ -124,7 +130,8 @@ var NotificationEntity = {
|
|
|
124
130
|
TUNA_SPOT_POSITION: "tuna_spot_position",
|
|
125
131
|
LENDING_POSITION: "lending_position",
|
|
126
132
|
STAKING_POSITION: "staking_position",
|
|
127
|
-
FUSION_LIMIT_ORDER: "fusion_limit_order"
|
|
133
|
+
FUSION_LIMIT_ORDER: "fusion_limit_order",
|
|
134
|
+
TRADE_HISTORY_ENTRY: "trade_history_entry"
|
|
128
135
|
};
|
|
129
136
|
var NotificationAction = {
|
|
130
137
|
CREATE: "create",
|
|
@@ -151,6 +158,20 @@ var LimitOrderState = {
|
|
|
151
158
|
COMPLETE: "complete",
|
|
152
159
|
CANCELLED: "cancelled"
|
|
153
160
|
};
|
|
161
|
+
var TradeHistoryAction = {
|
|
162
|
+
SWAP: "swap",
|
|
163
|
+
LIMIT_ORDER_FILL: "limit_order_fill",
|
|
164
|
+
POSITION_INCREASE: "position_increase",
|
|
165
|
+
POSITION_DECREASE: "position_decrease"
|
|
166
|
+
};
|
|
167
|
+
var TradeHistoryUIDirection = {
|
|
168
|
+
BUY: "buy",
|
|
169
|
+
SELL: "sell",
|
|
170
|
+
OPEN_LONG: "open_long",
|
|
171
|
+
CLOSE_LONG: "close_long",
|
|
172
|
+
OPEN_SHORT: "open_short",
|
|
173
|
+
CLOSE_SHORT: "close_short"
|
|
174
|
+
};
|
|
154
175
|
var StakingPositionHistoryActionType = {
|
|
155
176
|
STAKE: "stake",
|
|
156
177
|
UNSTAKE: "unstake",
|
|
@@ -179,6 +200,11 @@ var TunaSpotPositionStateSchema = import_zod.z.enum([
|
|
|
179
200
|
...Object.values(TunaSpotPositionState)
|
|
180
201
|
]);
|
|
181
202
|
var LimitOrderStateSchema = import_zod.z.enum([LimitOrderState.OPEN, ...Object.values(LimitOrderState)]);
|
|
203
|
+
var TradeHistoryActionSchema = import_zod.z.enum([TradeHistoryAction.SWAP, ...Object.values(TradeHistoryAction)]);
|
|
204
|
+
var TradeHistoryUIDirectionSchema = import_zod.z.enum([
|
|
205
|
+
TradeHistoryUIDirection.BUY,
|
|
206
|
+
...Object.values(TradeHistoryUIDirection)
|
|
207
|
+
]);
|
|
182
208
|
var StakingPositionHistoryActionTypeSchema = import_zod.z.enum([
|
|
183
209
|
StakingPositionHistoryActionType.STAKE,
|
|
184
210
|
...Object.values(StakingPositionHistoryActionType)
|
|
@@ -437,6 +463,30 @@ var LimitOrder = import_zod.z.object({
|
|
|
437
463
|
openedAt: import_zod.z.coerce.date(),
|
|
438
464
|
closedAt: import_zod.z.nullable(import_zod.z.coerce.date())
|
|
439
465
|
});
|
|
466
|
+
var TradeHistoryEntry = import_zod.z.object({
|
|
467
|
+
// Internal entry ID
|
|
468
|
+
id: import_zod.z.string(),
|
|
469
|
+
pool: import_zod.z.string(),
|
|
470
|
+
authority: import_zod.z.string(),
|
|
471
|
+
aToB: import_zod.z.boolean(),
|
|
472
|
+
// Trade action which created entry
|
|
473
|
+
action: TradeHistoryActionSchema,
|
|
474
|
+
// Trade direction formatted for ui display
|
|
475
|
+
uiDirection: TradeHistoryUIDirectionSchema,
|
|
476
|
+
// Trade price formatted for ui display
|
|
477
|
+
uiPrice: import_zod.z.number(),
|
|
478
|
+
baseTokenAmount: import_zod.z.coerce.bigint(),
|
|
479
|
+
baseTokenAmountUsd: import_zod.z.number(),
|
|
480
|
+
quoteTokenAmount: import_zod.z.coerce.bigint(),
|
|
481
|
+
quoteTokenAmountUsd: import_zod.z.number(),
|
|
482
|
+
feeAmount: import_zod.z.coerce.bigint(),
|
|
483
|
+
feeAmountUsd: import_zod.z.number(),
|
|
484
|
+
pnlUsd: import_zod.z.nullable(import_zod.z.number()),
|
|
485
|
+
txSignature: import_zod.z.nullable(import_zod.z.string()),
|
|
486
|
+
positionAddress: import_zod.z.nullable(import_zod.z.string()),
|
|
487
|
+
slot: import_zod.z.coerce.bigint(),
|
|
488
|
+
ts: import_zod.z.coerce.date()
|
|
489
|
+
});
|
|
440
490
|
var StakingTreasury = import_zod.z.object({
|
|
441
491
|
address: import_zod.z.string(),
|
|
442
492
|
stakedTokenMint: import_zod.z.string(),
|
|
@@ -555,6 +605,7 @@ var TunaPositionNotification = createNotificationSchema(TunaPosition);
|
|
|
555
605
|
var TunaSpotPositionNotification = createNotificationSchema(TunaSpotPosition);
|
|
556
606
|
var LendingPositionNotification = createNotificationSchema(LendingPosition);
|
|
557
607
|
var LimitOrderNotification = createNotificationSchema(LimitOrder);
|
|
608
|
+
var TradeHistoryEntryNotification = createNotificationSchema(TradeHistoryEntry);
|
|
558
609
|
var StakingPositionNotification = createNotificationSchema(StakingPosition);
|
|
559
610
|
|
|
560
611
|
// src/client/client.ts
|
|
@@ -740,16 +791,63 @@ var TunaApiClient = class {
|
|
|
740
791
|
const url = this.buildURL(`users/${userAddress}/spot-positions/${tunaSpotPositionAddress}`);
|
|
741
792
|
return await this.httpRequest(url, TunaSpotPosition);
|
|
742
793
|
}
|
|
743
|
-
async getUserLimitOrders(userAddress,
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
794
|
+
async getUserLimitOrders(userAddress, options) {
|
|
795
|
+
let query = {};
|
|
796
|
+
if (options) {
|
|
797
|
+
if (options.pool?.length) {
|
|
798
|
+
query.pool = options.pool.join(",");
|
|
799
|
+
}
|
|
800
|
+
if (options.status?.length) {
|
|
801
|
+
query.status = options.status.join(",");
|
|
802
|
+
}
|
|
803
|
+
if (options.openedAt?.from) {
|
|
804
|
+
query.opened_at_from = options.openedAt.from.toISOString();
|
|
805
|
+
}
|
|
806
|
+
if (options.openedAt?.to) {
|
|
807
|
+
query.opened_at_from = options.openedAt.to.toISOString();
|
|
808
|
+
}
|
|
809
|
+
if (options.limit) {
|
|
810
|
+
query.limit = options.limit;
|
|
811
|
+
}
|
|
812
|
+
if (options.cursor) {
|
|
813
|
+
query.cursor = options.cursor;
|
|
814
|
+
}
|
|
815
|
+
if (options.desc !== void 0) {
|
|
816
|
+
query.desc = options.desc;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
const url = this.appendUrlSearchParams(this.buildURL(`users/${userAddress}/limit-orders`), query);
|
|
747
820
|
return await this.httpRequest(url, LimitOrder.array());
|
|
748
821
|
}
|
|
749
822
|
async getUserLimitOrderByAddress(userAddress, limitOrderAddress) {
|
|
750
823
|
const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
|
|
751
824
|
return await this.httpRequest(url, LimitOrder);
|
|
752
825
|
}
|
|
826
|
+
async getUserTradeHistory(userAddress, options) {
|
|
827
|
+
let query = {};
|
|
828
|
+
if (options) {
|
|
829
|
+
if (options.pool?.length) {
|
|
830
|
+
query.pool = options.pool.join(",");
|
|
831
|
+
}
|
|
832
|
+
if (options.action?.length) {
|
|
833
|
+
query.status = options.action.join(",");
|
|
834
|
+
}
|
|
835
|
+
if (options.uiDirection?.length) {
|
|
836
|
+
query.ui_direction = options.uiDirection.join(",");
|
|
837
|
+
}
|
|
838
|
+
if (options.limit) {
|
|
839
|
+
query.limit = options.limit;
|
|
840
|
+
}
|
|
841
|
+
if (options.cursor) {
|
|
842
|
+
query.cursor = options.cursor;
|
|
843
|
+
}
|
|
844
|
+
if (options.desc !== void 0) {
|
|
845
|
+
query.desc = options.desc;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
const url = this.appendUrlSearchParams(this.buildURL(`users/${userAddress}/trade-history`), query);
|
|
849
|
+
return await this.httpRequest(url, TradeHistoryEntry.array());
|
|
850
|
+
}
|
|
753
851
|
async getUserStakingPosition(userAddress) {
|
|
754
852
|
const url = this.buildURL(`users/${userAddress}/staking-position`);
|
|
755
853
|
return await this.httpRequest(url, StakingPosition);
|
package/dist/index.mjs
CHANGED
|
@@ -51,6 +51,12 @@ __export(schemas_exports, {
|
|
|
51
51
|
StakingTreasury: () => StakingTreasury,
|
|
52
52
|
Tick: () => Tick,
|
|
53
53
|
TokenOraclePrice: () => TokenOraclePrice,
|
|
54
|
+
TradeHistoryAction: () => TradeHistoryAction,
|
|
55
|
+
TradeHistoryActionSchema: () => TradeHistoryActionSchema,
|
|
56
|
+
TradeHistoryEntry: () => TradeHistoryEntry,
|
|
57
|
+
TradeHistoryEntryNotification: () => TradeHistoryEntryNotification,
|
|
58
|
+
TradeHistoryUIDirection: () => TradeHistoryUIDirection,
|
|
59
|
+
TradeHistoryUIDirectionSchema: () => TradeHistoryUIDirectionSchema,
|
|
54
60
|
TunaPosition: () => TunaPosition,
|
|
55
61
|
TunaPositionNotification: () => TunaPositionNotification,
|
|
56
62
|
TunaPositionState: () => TunaPositionState,
|
|
@@ -89,7 +95,8 @@ var NotificationEntity = {
|
|
|
89
95
|
TUNA_SPOT_POSITION: "tuna_spot_position",
|
|
90
96
|
LENDING_POSITION: "lending_position",
|
|
91
97
|
STAKING_POSITION: "staking_position",
|
|
92
|
-
FUSION_LIMIT_ORDER: "fusion_limit_order"
|
|
98
|
+
FUSION_LIMIT_ORDER: "fusion_limit_order",
|
|
99
|
+
TRADE_HISTORY_ENTRY: "trade_history_entry"
|
|
93
100
|
};
|
|
94
101
|
var NotificationAction = {
|
|
95
102
|
CREATE: "create",
|
|
@@ -116,6 +123,20 @@ var LimitOrderState = {
|
|
|
116
123
|
COMPLETE: "complete",
|
|
117
124
|
CANCELLED: "cancelled"
|
|
118
125
|
};
|
|
126
|
+
var TradeHistoryAction = {
|
|
127
|
+
SWAP: "swap",
|
|
128
|
+
LIMIT_ORDER_FILL: "limit_order_fill",
|
|
129
|
+
POSITION_INCREASE: "position_increase",
|
|
130
|
+
POSITION_DECREASE: "position_decrease"
|
|
131
|
+
};
|
|
132
|
+
var TradeHistoryUIDirection = {
|
|
133
|
+
BUY: "buy",
|
|
134
|
+
SELL: "sell",
|
|
135
|
+
OPEN_LONG: "open_long",
|
|
136
|
+
CLOSE_LONG: "close_long",
|
|
137
|
+
OPEN_SHORT: "open_short",
|
|
138
|
+
CLOSE_SHORT: "close_short"
|
|
139
|
+
};
|
|
119
140
|
var StakingPositionHistoryActionType = {
|
|
120
141
|
STAKE: "stake",
|
|
121
142
|
UNSTAKE: "unstake",
|
|
@@ -144,6 +165,11 @@ var TunaSpotPositionStateSchema = z.enum([
|
|
|
144
165
|
...Object.values(TunaSpotPositionState)
|
|
145
166
|
]);
|
|
146
167
|
var LimitOrderStateSchema = z.enum([LimitOrderState.OPEN, ...Object.values(LimitOrderState)]);
|
|
168
|
+
var TradeHistoryActionSchema = z.enum([TradeHistoryAction.SWAP, ...Object.values(TradeHistoryAction)]);
|
|
169
|
+
var TradeHistoryUIDirectionSchema = z.enum([
|
|
170
|
+
TradeHistoryUIDirection.BUY,
|
|
171
|
+
...Object.values(TradeHistoryUIDirection)
|
|
172
|
+
]);
|
|
147
173
|
var StakingPositionHistoryActionTypeSchema = z.enum([
|
|
148
174
|
StakingPositionHistoryActionType.STAKE,
|
|
149
175
|
...Object.values(StakingPositionHistoryActionType)
|
|
@@ -402,6 +428,30 @@ var LimitOrder = z.object({
|
|
|
402
428
|
openedAt: z.coerce.date(),
|
|
403
429
|
closedAt: z.nullable(z.coerce.date())
|
|
404
430
|
});
|
|
431
|
+
var TradeHistoryEntry = z.object({
|
|
432
|
+
// Internal entry ID
|
|
433
|
+
id: z.string(),
|
|
434
|
+
pool: z.string(),
|
|
435
|
+
authority: z.string(),
|
|
436
|
+
aToB: z.boolean(),
|
|
437
|
+
// Trade action which created entry
|
|
438
|
+
action: TradeHistoryActionSchema,
|
|
439
|
+
// Trade direction formatted for ui display
|
|
440
|
+
uiDirection: TradeHistoryUIDirectionSchema,
|
|
441
|
+
// Trade price formatted for ui display
|
|
442
|
+
uiPrice: z.number(),
|
|
443
|
+
baseTokenAmount: z.coerce.bigint(),
|
|
444
|
+
baseTokenAmountUsd: z.number(),
|
|
445
|
+
quoteTokenAmount: z.coerce.bigint(),
|
|
446
|
+
quoteTokenAmountUsd: z.number(),
|
|
447
|
+
feeAmount: z.coerce.bigint(),
|
|
448
|
+
feeAmountUsd: z.number(),
|
|
449
|
+
pnlUsd: z.nullable(z.number()),
|
|
450
|
+
txSignature: z.nullable(z.string()),
|
|
451
|
+
positionAddress: z.nullable(z.string()),
|
|
452
|
+
slot: z.coerce.bigint(),
|
|
453
|
+
ts: z.coerce.date()
|
|
454
|
+
});
|
|
405
455
|
var StakingTreasury = z.object({
|
|
406
456
|
address: z.string(),
|
|
407
457
|
stakedTokenMint: z.string(),
|
|
@@ -520,6 +570,7 @@ var TunaPositionNotification = createNotificationSchema(TunaPosition);
|
|
|
520
570
|
var TunaSpotPositionNotification = createNotificationSchema(TunaSpotPosition);
|
|
521
571
|
var LendingPositionNotification = createNotificationSchema(LendingPosition);
|
|
522
572
|
var LimitOrderNotification = createNotificationSchema(LimitOrder);
|
|
573
|
+
var TradeHistoryEntryNotification = createNotificationSchema(TradeHistoryEntry);
|
|
523
574
|
var StakingPositionNotification = createNotificationSchema(StakingPosition);
|
|
524
575
|
|
|
525
576
|
// src/client/client.ts
|
|
@@ -705,16 +756,63 @@ var TunaApiClient = class {
|
|
|
705
756
|
const url = this.buildURL(`users/${userAddress}/spot-positions/${tunaSpotPositionAddress}`);
|
|
706
757
|
return await this.httpRequest(url, TunaSpotPosition);
|
|
707
758
|
}
|
|
708
|
-
async getUserLimitOrders(userAddress,
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
759
|
+
async getUserLimitOrders(userAddress, options) {
|
|
760
|
+
let query = {};
|
|
761
|
+
if (options) {
|
|
762
|
+
if (options.pool?.length) {
|
|
763
|
+
query.pool = options.pool.join(",");
|
|
764
|
+
}
|
|
765
|
+
if (options.status?.length) {
|
|
766
|
+
query.status = options.status.join(",");
|
|
767
|
+
}
|
|
768
|
+
if (options.openedAt?.from) {
|
|
769
|
+
query.opened_at_from = options.openedAt.from.toISOString();
|
|
770
|
+
}
|
|
771
|
+
if (options.openedAt?.to) {
|
|
772
|
+
query.opened_at_from = options.openedAt.to.toISOString();
|
|
773
|
+
}
|
|
774
|
+
if (options.limit) {
|
|
775
|
+
query.limit = options.limit;
|
|
776
|
+
}
|
|
777
|
+
if (options.cursor) {
|
|
778
|
+
query.cursor = options.cursor;
|
|
779
|
+
}
|
|
780
|
+
if (options.desc !== void 0) {
|
|
781
|
+
query.desc = options.desc;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
const url = this.appendUrlSearchParams(this.buildURL(`users/${userAddress}/limit-orders`), query);
|
|
712
785
|
return await this.httpRequest(url, LimitOrder.array());
|
|
713
786
|
}
|
|
714
787
|
async getUserLimitOrderByAddress(userAddress, limitOrderAddress) {
|
|
715
788
|
const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
|
|
716
789
|
return await this.httpRequest(url, LimitOrder);
|
|
717
790
|
}
|
|
791
|
+
async getUserTradeHistory(userAddress, options) {
|
|
792
|
+
let query = {};
|
|
793
|
+
if (options) {
|
|
794
|
+
if (options.pool?.length) {
|
|
795
|
+
query.pool = options.pool.join(",");
|
|
796
|
+
}
|
|
797
|
+
if (options.action?.length) {
|
|
798
|
+
query.status = options.action.join(",");
|
|
799
|
+
}
|
|
800
|
+
if (options.uiDirection?.length) {
|
|
801
|
+
query.ui_direction = options.uiDirection.join(",");
|
|
802
|
+
}
|
|
803
|
+
if (options.limit) {
|
|
804
|
+
query.limit = options.limit;
|
|
805
|
+
}
|
|
806
|
+
if (options.cursor) {
|
|
807
|
+
query.cursor = options.cursor;
|
|
808
|
+
}
|
|
809
|
+
if (options.desc !== void 0) {
|
|
810
|
+
query.desc = options.desc;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
const url = this.appendUrlSearchParams(this.buildURL(`users/${userAddress}/trade-history`), query);
|
|
814
|
+
return await this.httpRequest(url, TradeHistoryEntry.array());
|
|
815
|
+
}
|
|
718
816
|
async getUserStakingPosition(userAddress) {
|
|
719
817
|
const url = this.buildURL(`users/${userAddress}/staking-position`);
|
|
720
818
|
return await this.httpRequest(url, StakingPosition);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crypticdot/defituna-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"@crypticdot/eslint-config": "^1.0.2",
|
|
19
19
|
"@crypticdot/prettier-config": "^1.0.0",
|
|
20
20
|
"@crypticdot/typescript-config": "^1.0.0",
|
|
21
|
+
"@crypticdot/fusionamm-client": "^1.0.62",
|
|
21
22
|
"@solana/kit": "^2.1.0",
|
|
22
23
|
"@types/node": "^22.13.14",
|
|
23
24
|
"decimal.js": "^10.5.0",
|