@crypticdot/defituna-api 1.3.0 → 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.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
@@ -772,6 +823,31 @@ var TunaApiClient = class {
772
823
  const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
773
824
  return await this.httpRequest(url, LimitOrder);
774
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
+ }
775
851
  async getUserStakingPosition(userAddress) {
776
852
  const url = this.buildURL(`users/${userAddress}/staking-position`);
777
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
@@ -737,6 +788,31 @@ var TunaApiClient = class {
737
788
  const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
738
789
  return await this.httpRequest(url, LimitOrder);
739
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
+ }
740
816
  async getUserStakingPosition(userAddress) {
741
817
  const url = this.buildURL(`users/${userAddress}/staking-position`);
742
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.0",
3
+ "version": "1.3.1",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",