Skip to content

Commit 644dfb7

Browse files
committed
chore: tc endpoints alignment
1 parent acab92c commit 644dfb7

3 files changed

Lines changed: 41 additions & 25 deletions

File tree

packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcTcDerivativesApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class IndexerGrpcTcDerivativesApi extends BaseIndexerGrpcConsumer {
2121
direction?: string
2222
accountAddress?: string
2323
}) {
24-
const { marketId, direction, perPage, token, accountAddress } = params || {}
24+
const { token, perPage, marketId, direction, accountAddress } = params || {}
2525

2626
const request = InjectiveTCDerivativesRpcPb.OrdersHistoryRequest.create()
2727

packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcTcDerivativesTransformer.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import { TradeDirection } from '../../../types/index.js'
1+
import { OrderState, TradeDirection } from '../../../types/index.js'
22
import type * as InjectiveTCDerivativesRpcPb from '@injectivelabs/indexer-proto-ts-v2/generated/injective_tc_derivatives_rpc_pb'
3+
import type {
4+
OrderSide,
5+
TradeExecutionSide,
6+
TradeExecutionType,
7+
} from '../../../types/index.js'
38
import type {
49
TcPositionDelta,
510
GrpcTcPositionDelta,
611
TcDerivativePosition,
712
TcDerivativeLimitOrder,
813
TcDerivativeTradeHistory,
9-
TcDerivativeOrderHistory,
1014
GrpcTcDerivativePosition,
15+
TcDerivativeOrderHistory,
1116
GrpcTcDerivativeLimitOrder,
1217
TcDerivativeTradesResponse,
1318
TcDerivativeOrdersResponse,
@@ -32,10 +37,10 @@ export class IndexerGrpcTcDerivativesTransformer {
3237
positionDelta: GrpcTcPositionDelta,
3338
): TcPositionDelta {
3439
return {
35-
tradeDirection: positionDelta.tradeDirection,
3640
executionPrice: positionDelta.executionPrice,
3741
executionMargin: positionDelta.executionMargin,
3842
executionQuantity: positionDelta.executionQuantity,
43+
tradeDirection: positionDelta.tradeDirection as TradeDirection,
3944
}
4045
}
4146

@@ -45,15 +50,14 @@ export class IndexerGrpcTcDerivativesTransformer {
4550
return {
4651
cid: order.cid,
4752
price: order.price,
48-
state: order.state,
4953
margin: order.margin,
5054
txHash: order.txHash,
5155
marketId: order.marketId,
5256
isActive: order.isActive,
5357
quantity: order.quantity,
5458
orderHash: order.orderHash,
5559
orderType: order.orderType,
56-
direction: order.direction,
60+
state: order.state as OrderState,
5761
subaccountId: order.subaccountId,
5862
triggerPrice: order.triggerPrice,
5963
isReduceOnly: order.isReduceOnly,
@@ -64,6 +68,7 @@ export class IndexerGrpcTcDerivativesTransformer {
6468
triggerAt: Number(order.triggerAt),
6569
filledQuantity: order.filledQuantity,
6670
placedOrderHash: order.placedOrderHash,
71+
direction: order.direction as TradeDirection,
6772
}
6873
}
6974

@@ -88,9 +93,9 @@ export class IndexerGrpcTcDerivativesTransformer {
8893
subaccountId: trade.subaccountId,
8994
feeRecipient: trade.feeRecipient,
9095
isLiquidation: trade.isLiquidation,
91-
executionSide: trade.executionSide,
9296
executedAt: Number(trade.executedAt),
93-
tradeExecutionType: trade.tradeExecutionType,
97+
executionSide: trade.executionSide as TradeExecutionSide,
98+
tradeExecutionType: trade.tradeExecutionType as TradeExecutionType,
9499
...mappedPositionDelta,
95100
}
96101
}
@@ -104,14 +109,14 @@ export class IndexerGrpcTcDerivativesTransformer {
104109
margin: position.margin,
105110
marketId: position.marketId,
106111
quantity: position.quantity,
107-
direction: position.direction,
108112
markPrice: position.markPrice,
109113
entryPrice: position.entryPrice,
110114
fundingSum: position.fundingSum,
111115
fundingLast: position.fundingLast,
112116
subaccountId: position.subaccountId,
113117
updatedAt: Number(position.updatedAt),
114118
liquidationPrice: position.liquidationPrice,
119+
direction: position.direction as TradeDirection,
115120
cumulativeFundingEntry: position.cumulativeFundingEntry,
116121
effectiveCumulativeFundingEntry: position.effectiveCumulativeFundingEntry,
117122
}
@@ -123,36 +128,40 @@ export class IndexerGrpcTcDerivativesTransformer {
123128
return {
124129
cid: order.cid,
125130
price: order.price,
126-
state: order.state,
127131
margin: order.margin,
128132
marketId: order.marketId,
129133
quantity: order.quantity,
130134
orderHash: order.orderHash,
131-
orderSide: order.orderSide,
132135
orderType: order.orderType,
133136
subaccountId: order.subaccountId,
134137
isReduceOnly: order.isReduceOnly,
135138
triggerPrice: order.triggerPrice,
136139
feeRecipient: order.feeRecipient,
140+
state: order.state as OrderState,
137141
createdAt: Number(order.createdAt),
138142
updatedAt: Number(order.updatedAt),
139143
isConditional: order.isConditional,
140144
triggerAt: Number(order.triggerAt),
141145
executionType: order.executionType,
142146
orderNumber: Number(order.orderNumber),
143147
placedOrderHash: order.placedOrderHash,
148+
orderSide: order.orderSide as OrderSide,
144149
unfilledQuantity: order.unfilledQuantity,
145150
}
146151
}
147152

148153
static ordersHistoryResponseToOrdersHistory(
149154
response: InjectiveTCDerivativesRpcPb.OrdersHistoryResponse,
150155
): TcDerivativesOrdersHistoryResponse {
156+
const filteredOrderHistory = response.orders?.filter(
157+
(order) => order.state !== OrderState.Booked,
158+
)
159+
151160
return {
152-
orders: response.orders.map(
161+
next: response.next,
162+
orders: filteredOrderHistory.map(
153163
IndexerGrpcTcDerivativesTransformer.grpcOrderHistoryToOrderHistory,
154164
),
155-
next: response.next,
156165
}
157166
}
158167

@@ -171,22 +180,22 @@ export class IndexerGrpcTcDerivativesTransformer {
171180
response: InjectiveTCDerivativesRpcPb.TradesResponse,
172181
): TcDerivativeTradesResponse {
173182
return {
183+
next: response.next,
174184
trades: response.trades.map(
175185
IndexerGrpcTcDerivativesTransformer.grpcTradeToTrade,
176186
),
177-
next: response.next,
178187
}
179188
}
180189

181190
static positionsResponseToPositions(
182191
response: InjectiveTCDerivativesRpcPb.PositionsResponse,
183192
): TcDerivativesPositionsResponse {
184193
return {
194+
next: response.next,
195+
total: response.total ? Number(response.total) : undefined,
185196
positions: response.positions.map(
186197
IndexerGrpcTcDerivativesTransformer.grpcPositionToPosition,
187198
),
188-
next: response.next,
189-
total: response.total ? Number(response.total) : undefined,
190199
}
191200
}
192201
}

packages/sdk-ts/src/client/indexer/types/tc-derivatives.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import type * as InjectiveTCDerivativesRpcPb from '@injectivelabs/indexer-proto-ts-v2/generated/injective_tc_derivatives_rpc_pb'
2+
import type {
3+
OrderSide,
4+
OrderState,
5+
TradeDirection,
6+
TradeExecutionSide,
7+
TradeExecutionType,
8+
} from '../../../types/index.js'
29

310
export interface TcPositionDelta {
4-
tradeDirection: string
11+
tradeDirection: TradeDirection
512
executionPrice: string
613
executionQuantity: string
714
executionMargin: string
@@ -10,17 +17,16 @@ export interface TcPositionDelta {
1017
export interface TcDerivativeOrderHistory {
1118
cid: string
1219
price: string
13-
state: string
1420
margin: string
1521
txHash: string
1622
marketId: string
1723
quantity: string
24+
state: OrderState
1825
orderHash: string
1926
isActive: boolean
2027
orderType: string
2128
createdAt: number
2229
updatedAt: number
23-
direction: string
2430
triggerAt: number
2531
subaccountId: string
2632
triggerPrice: string
@@ -29,6 +35,7 @@ export interface TcDerivativeOrderHistory {
2935
filledQuantity: string
3036
isConditional: boolean
3137
placedOrderHash: string
38+
direction: TradeDirection
3239
}
3340

3441
export interface TcDerivativeTradeHistory {
@@ -42,13 +49,13 @@ export interface TcDerivativeTradeHistory {
4249
executedAt: number
4350
subaccountId: string
4451
feeRecipient: string
45-
executionSide: string
4652
isLiquidation: boolean
47-
tradeDirection: string
4853
executionPrice: string
4954
executionMargin: string
5055
executionQuantity: string
51-
tradeExecutionType: string
56+
tradeDirection: TradeDirection
57+
executionSide: TradeExecutionSide
58+
tradeExecutionType: TradeExecutionType
5259
}
5360

5461
export interface TcDerivativePosition {
@@ -57,32 +64,32 @@ export interface TcDerivativePosition {
5764
margin: string
5865
marketId: string
5966
quantity: string
60-
direction: string
6167
markPrice: string
6268
updatedAt: number
6369
entryPrice: string
6470
fundingSum: string
6571
fundingLast: string
6672
subaccountId: string
6773
liquidationPrice: string
74+
direction: TradeDirection
6875
cumulativeFundingEntry: string
6976
effectiveCumulativeFundingEntry: string
7077
}
7178

7279
export interface TcDerivativeLimitOrder {
7380
cid: string
7481
price: string
75-
state: string
7682
margin: string
7783
marketId: string
7884
quantity: string
85+
state: OrderState
7986
orderHash: string
80-
orderSide: string
8187
createdAt: number
8288
updatedAt: number
8389
orderType: string
8490
triggerAt: number
8591
orderNumber: number
92+
orderSide: OrderSide
8693
subaccountId: string
8794
triggerPrice: string
8895
feeRecipient: string

0 commit comments

Comments
 (0)