@crypticdot/defituna-api 1.3.0 → 1.3.2

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,27 @@ 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
+ baseToken: amountWithUsd,
479
+ quoteToken: amountWithUsd,
480
+ fee: amountWithUsd,
481
+ pnlUsd: import_zod.z.nullable(import_zod.z.number()),
482
+ txSignature: import_zod.z.nullable(import_zod.z.string()),
483
+ positionAddress: import_zod.z.nullable(import_zod.z.string()),
484
+ slot: import_zod.z.coerce.bigint(),
485
+ ts: import_zod.z.coerce.date()
486
+ });
440
487
  var StakingTreasury = import_zod.z.object({
441
488
  address: import_zod.z.string(),
442
489
  stakedTokenMint: import_zod.z.string(),
@@ -555,6 +602,7 @@ var TunaPositionNotification = createNotificationSchema(TunaPosition);
555
602
  var TunaSpotPositionNotification = createNotificationSchema(TunaSpotPosition);
556
603
  var LendingPositionNotification = createNotificationSchema(LendingPosition);
557
604
  var LimitOrderNotification = createNotificationSchema(LimitOrder);
605
+ var TradeHistoryEntryNotification = createNotificationSchema(TradeHistoryEntry);
558
606
  var StakingPositionNotification = createNotificationSchema(StakingPosition);
559
607
 
560
608
  // src/client/client.ts
@@ -772,6 +820,31 @@ var TunaApiClient = class {
772
820
  const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
773
821
  return await this.httpRequest(url, LimitOrder);
774
822
  }
823
+ async getUserTradeHistory(userAddress, options) {
824
+ let query = {};
825
+ if (options) {
826
+ if (options.pool?.length) {
827
+ query.pool = options.pool.join(",");
828
+ }
829
+ if (options.action?.length) {
830
+ query.status = options.action.join(",");
831
+ }
832
+ if (options.uiDirection?.length) {
833
+ query.ui_direction = options.uiDirection.join(",");
834
+ }
835
+ if (options.limit) {
836
+ query.limit = options.limit;
837
+ }
838
+ if (options.cursor) {
839
+ query.cursor = options.cursor;
840
+ }
841
+ if (options.desc !== void 0) {
842
+ query.desc = options.desc;
843
+ }
844
+ }
845
+ const url = this.appendUrlSearchParams(this.buildURL(`users/${userAddress}/trade-history`), query);
846
+ return await this.httpRequest(url, TradeHistoryEntry.array());
847
+ }
775
848
  async getUserStakingPosition(userAddress) {
776
849
  const url = this.buildURL(`users/${userAddress}/staking-position`);
777
850
  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,27 @@ 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
+ baseToken: amountWithUsd,
444
+ quoteToken: amountWithUsd,
445
+ fee: amountWithUsd,
446
+ pnlUsd: z.nullable(z.number()),
447
+ txSignature: z.nullable(z.string()),
448
+ positionAddress: z.nullable(z.string()),
449
+ slot: z.coerce.bigint(),
450
+ ts: z.coerce.date()
451
+ });
405
452
  var StakingTreasury = z.object({
406
453
  address: z.string(),
407
454
  stakedTokenMint: z.string(),
@@ -520,6 +567,7 @@ var TunaPositionNotification = createNotificationSchema(TunaPosition);
520
567
  var TunaSpotPositionNotification = createNotificationSchema(TunaSpotPosition);
521
568
  var LendingPositionNotification = createNotificationSchema(LendingPosition);
522
569
  var LimitOrderNotification = createNotificationSchema(LimitOrder);
570
+ var TradeHistoryEntryNotification = createNotificationSchema(TradeHistoryEntry);
523
571
  var StakingPositionNotification = createNotificationSchema(StakingPosition);
524
572
 
525
573
  // src/client/client.ts
@@ -737,6 +785,31 @@ var TunaApiClient = class {
737
785
  const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
738
786
  return await this.httpRequest(url, LimitOrder);
739
787
  }
788
+ async getUserTradeHistory(userAddress, options) {
789
+ let query = {};
790
+ if (options) {
791
+ if (options.pool?.length) {
792
+ query.pool = options.pool.join(",");
793
+ }
794
+ if (options.action?.length) {
795
+ query.status = options.action.join(",");
796
+ }
797
+ if (options.uiDirection?.length) {
798
+ query.ui_direction = options.uiDirection.join(",");
799
+ }
800
+ if (options.limit) {
801
+ query.limit = options.limit;
802
+ }
803
+ if (options.cursor) {
804
+ query.cursor = options.cursor;
805
+ }
806
+ if (options.desc !== void 0) {
807
+ query.desc = options.desc;
808
+ }
809
+ }
810
+ const url = this.appendUrlSearchParams(this.buildURL(`users/${userAddress}/trade-history`), query);
811
+ return await this.httpRequest(url, TradeHistoryEntry.array());
812
+ }
740
813
  async getUserStakingPosition(userAddress) {
741
814
  const url = this.buildURL(`users/${userAddress}/staking-position`);
742
815
  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.2",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",