@reyaxyz/common 0.276.0 → 0.277.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.
@@ -41,19 +41,14 @@ type Order = {
41
41
  id: string;
42
42
  market_id: Decimal | null;
43
43
  account_id: Decimal | null;
44
- order_base: Decimal | null;
44
+ executed_base: Decimal | null;
45
45
  fee: Decimal | null;
46
46
  price: Decimal | null;
47
- type: string;
48
- processed: boolean;
47
+ is_match_order: boolean | null;
48
+ liquidation_type: Decimal | null;
49
49
  transaction_hash: string;
50
- r_pnl: Decimal | null;
51
- price_variation_pnl: Decimal | null;
52
- funding_pnl: Decimal | null;
53
- average_entry_price: Decimal | null;
54
50
  block_timestamp: Decimal | null;
55
51
  block_number: Decimal;
56
- source: string | null;
57
52
  unique_id: bigint | null;
58
53
  created_at: Date;
59
54
  };
@@ -63,11 +58,8 @@ type Position = {
63
58
  account_id: Decimal;
64
59
  base: Decimal | null;
65
60
  realized_pnl: Decimal | null;
66
- realized_pnl_latest_snapshot: Decimal | null;
67
- average_entry_price_off_chain_tracker: Decimal | null;
68
- funding_value_off_chain_tracker: Decimal | null;
69
61
  last_price: Decimal | null;
70
- position_data_last_price_data_timestamp: Decimal | null;
62
+ last_price_timestamp: Decimal | null;
71
63
  funding_value: Decimal | null;
72
64
  base_multiplier: Decimal | null;
73
65
  adl_unwind_price: Decimal | null;
@@ -85,6 +77,13 @@ type ConditionalOrder = {
85
77
  is_long: boolean;
86
78
  trigger_price: number;
87
79
  order_base: Decimal;
80
+ status: string;
81
+ creation_timestamp_ms: bigint;
82
+ last_update_timestamp_ms: bigint;
83
+ transaction_hash: string | null;
84
+ };
85
+
86
+ type ConditionalOrderSensitive = ConditionalOrder & {
88
87
  exchange_id: bigint;
89
88
  inputs: string;
90
89
  counterparty_account_id: bigint;
@@ -93,10 +92,6 @@ type ConditionalOrder = {
93
92
  signer_address: string;
94
93
  nonce: Decimal;
95
94
  signature: string;
96
- status: string;
97
- creation_timestamp_ms: bigint;
98
- last_update_timestamp_ms: bigint;
99
- transaction_hash: string | null;
100
95
  };
101
96
 
102
97
  type Market = {
@@ -324,12 +319,12 @@ export type TradingApiSource = {
324
319
  {
325
320
  marketId: string;
326
321
  },
327
- 'order_history'
322
+ 'orders'
328
323
  >;
329
324
  'wallet/:address/positions': TradingApiListEndpoint<
330
325
  Position,
331
326
  AddressParam,
332
- 'position_raw'
327
+ 'position'
333
328
  >;
334
329
  'wallet/:address/conditionalOrders': TradingApiListEndpoint<
335
330
  ConditionalOrder,
@@ -360,7 +355,7 @@ export type TradingApiSource = {
360
355
  'wallet/:address/accounts': TradingApiListEndpoint<
361
356
  Account,
362
357
  AddressParam,
363
- 'accountProfile'
358
+ 'AccountProfile'
364
359
  >;
365
360
  'wallet/:address/accounts/tiers': TradingApiListEndpoint<
366
361
  {
@@ -525,6 +520,11 @@ export type GenericReplicationMessage<T, model extends ReplicationModel> =
525
520
  model: model;
526
521
  result: T[];
527
522
  operation: 'updateMany';
523
+ }
524
+ | {
525
+ model: model;
526
+ result: T[];
527
+ operation: 'createMany';
528
528
  };
529
529
 
530
530
  type account_collateral_balance_entries = {
@@ -558,6 +558,10 @@ type ReplicationMessage =
558
558
  | GenericReplicationMessage<
559
559
  account_collateral_balance_entries,
560
560
  'account_collateral_balance_entries'
561
+ >
562
+ | GenericReplicationMessage<
563
+ ConditionalOrderSensitive,
564
+ 'ConditionalOrdersSensitive'
561
565
  >;
562
566
 
563
567
  export type Replication = {
@@ -566,3 +570,9 @@ export type Replication = {
566
570
  { model: K['model'] }
567
571
  >;
568
572
  };
573
+
574
+ export type ReplaceDecimals<T, D> = T extends Decimal
575
+ ? D
576
+ : T extends (infer U)[]
577
+ ? ReplaceDecimals<U, D>[]
578
+ : { [K in keyof T]: ReplaceDecimals<T[K], D> };
package/src/types.ts CHANGED
@@ -998,22 +998,36 @@ export type TransactionExecutionOutput = {
998
998
  executionPrice?: number;
999
999
  base?: number;
1000
1000
  };
1001
- positions?: Omit<
1002
- Stringified<TradingApiSource['wallet/:address/positions']['response'][0]>,
1003
- | 'realized_pnl_latest_snapshot'
1004
- | 'average_entry_price_off_chain_tracker'
1005
- | 'funding_value_off_chain_tracker'
1006
- >[];
1007
- orders?: Omit<
1008
- Stringified<
1009
- TradingApiSource['market/:marketId/orders']['response']['data'][0]
1010
- >,
1011
- | 'r_pnl'
1012
- | 'price_variation_pnl'
1013
- | 'funding_pnl'
1014
- | 'average_entry_price'
1015
- | 'created_at'
1016
- >[];
1001
+ positions?: {
1002
+ market_id: string;
1003
+ account_id: string;
1004
+ base: string | null;
1005
+ realized_pnl: string | null;
1006
+ last_price: string | null;
1007
+ position_data_last_price_data_timestamp: string | null;
1008
+ funding_value: string | null;
1009
+ base_multiplier: string | null;
1010
+ adl_unwind_price: string | null;
1011
+ transaction_hash: string;
1012
+ block_timestamp: string | null;
1013
+ block_number: string;
1014
+ unique_id: string | null;
1015
+ }[];
1016
+ orders?: {
1017
+ id: string;
1018
+ market_id: string | null;
1019
+ account_id: string | null;
1020
+ order_base: string | null;
1021
+ fee: string | null;
1022
+ price: string | null;
1023
+ type: string;
1024
+ processed: boolean;
1025
+ transaction_hash: string;
1026
+ block_timestamp: string | null;
1027
+ block_number: string;
1028
+ source: string | null;
1029
+ unique_id: string | null;
1030
+ }[];
1017
1031
  accounts?: Omit<
1018
1032
  Stringified<TradingApiSource['wallet/:address/accounts']['response'][0]>,
1019
1033
  'status'
@@ -1255,6 +1269,7 @@ interface PositionData {
1255
1269
  }
1256
1270
 
1257
1271
  export interface PassivePerpOrderAndPositionUpdate {
1272
+ id: string;
1258
1273
  marketId: bigint;
1259
1274
  accountId: bigint;
1260
1275
  counterpartyAccountId: bigint;
@@ -1267,6 +1282,9 @@ export interface PassivePerpOrderAndPositionUpdate {
1267
1282
  positionData: PositionData;
1268
1283
  counterpartyPositionData: PositionData;
1269
1284
  blockTimestamp: bigint;
1285
+ blockNumber: string;
1286
+ transactionHash: string;
1287
+ uniqueId: bigint;
1270
1288
  }
1271
1289
 
1272
1290
  export type AssetPair =
@@ -134,6 +134,9 @@ export const VOLUME_TIER_MAP: Record<number, number> = {
134
134
 
135
135
  export const SPECIAL_TIER_THRESHOLD = 100;
136
136
 
137
+ export const MA_HEALTH_DANGER_THRESHOLD = 95;
138
+ export const MA_HEALTH_WARNING_THRESHOLD = 80;
139
+
137
140
  export const marketAssetPairIdMapper: Record<string, string> = {
138
141
  ETHUSDMARK: '1',
139
142
  BTCUSDMARK: '2',
@@ -23,10 +23,10 @@ export const filterBy = <T, K extends keyof T, V>(a: T[], k: K, v: V) =>
23
23
  export const findBy = <T, K extends keyof T, V>(a: T[], k: K, v: V) =>
24
24
  a.find((a) => a[k] === v);
25
25
 
26
- export const groupBy = <T, K>(items: T[], key: (item: T) => K) => {
26
+ export const groupBy = <T, K>(items: T[], key: (item: T) => K | K) => {
27
27
  const groupedItems = new Map<K, T[]>();
28
28
  items.forEach((item) => {
29
- const keyValue = typeof key === 'function' ? key(item) : item[key];
29
+ const keyValue = key(item);
30
30
  if (!keyValue) return;
31
31
  if (!groupedItems.has(keyValue)) {
32
32
  groupedItems.set(keyValue, [] as T[]);