1- import { TradeDirection } from '../../../types/index.js'
1+ import { OrderState , TradeDirection } from '../../../types/index.js'
22import 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'
38import 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}
0 commit comments