Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/sdk-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
"@injectivelabs/grpc-web": "^0.0.1",
"@injectivelabs/grpc-web-node-http-transport": "^0.0.2",
"@injectivelabs/grpc-web-react-native-transport": "^0.0.2",
"@injectivelabs/indexer-proto-ts-v2": "1.18.10",
"@injectivelabs/indexer-proto-ts-v2": "1.18.11",
"@injectivelabs/mito-proto-ts-v2": "1.17.3",
"@injectivelabs/networks": "workspace:*",
"@injectivelabs/olp-proto-ts-v2": "1.17.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ describe('IndexerGrpcRFQApi', () => {
try {
const response = await indexerGrpcRfqApi.submitRequest({
direction: 'LONG',
status: 'PENDING',
clientId: '1717000000',
expiry: BigInt(1717000000),
margin: '1000000000000000000',
Expand Down
139 changes: 132 additions & 7 deletions packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcRfqApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ export class IndexerGrpcRFQApi extends BaseIndexerGrpcConsumer {
async submitRequest({
margin,
expiry,
status,
clientId,
marketId,
quantity,
direction,
worstPrice,
priceCheck,
requestAddress,
transactionTime,
}: {
margin: string
expiry?: bigint
status?: string
marketId: string
quantity: string
direction: string
clientId?: string
worstPrice: string
priceCheck?: boolean
requestAddress?: string
transactionTime?: bigint
}) {
const request = InjectiveRFQExchangeRpcPb.RFQRequestType.create()
const request = InjectiveRFQExchangeRpcPb.RFQRequestInputType.create()

if (clientId) {
request.clientId = clientId
Expand Down Expand Up @@ -72,14 +72,14 @@ export class IndexerGrpcRFQApi extends BaseIndexerGrpcConsumer {
request.expiry = expiry
}

if (status) {
request.status = status
}

if (transactionTime) {
request.transactionTime = transactionTime
}

if (priceCheck) {
request.priceCheck = priceCheck
}

const requestMessage = InjectiveRFQExchangeRpcPb.RequestRequest.create()
requestMessage.request = request

Expand Down Expand Up @@ -247,4 +247,129 @@ export class IndexerGrpcRFQApi extends BaseIndexerGrpcConsumer {
response,
)
}

async createConditionalOrder({
margin,
orderId,
marketId,
quantity,
direction,
orderType,
signature,
worstPrice,
triggerPrice,
requestAddress,
}: {
margin: string
orderId: string
marketId: string
quantity: string
direction: string
orderType: string
signature: string
worstPrice: string
triggerPrice: string
requestAddress: string
}) {
const order = InjectiveRFQExchangeRpcPb.ConditionalOrderInputType.create()

order.margin = margin
order.orderId = orderId
order.marketId = marketId
order.quantity = quantity
order.direction = direction
order.orderType = orderType
order.signature = signature
order.worstPrice = worstPrice
order.triggerPrice = triggerPrice
order.requestAddress = requestAddress

const request =
InjectiveRFQExchangeRpcPb.CreateConditionalOrderRequest.create()
request.order = order

const response = await this.executeGrpcCall<
InjectiveRFQExchangeRpcPb.CreateConditionalOrderRequest,
InjectiveRFQExchangeRpcPb.CreateConditionalOrderResponse
>(request, this.client.createConditionalOrder.bind(this.client))

return {
order: response.order
? IndexerGrpcRfqTransformer.grpcConditionalOrderToConditionalOrder(
response.order,
)
: undefined,
}
}

async listConditionalOrders(params?: {
token?: string
status?: string
perPage?: number
marketId?: string
requestAddress?: string
}) {
const { requestAddress, status, marketId, perPage, token } = params || {}
const request =
InjectiveRFQExchangeRpcPb.ListConditionalOrdersRequest.create()

if (requestAddress) {
request.requestAddress = requestAddress
}

if (status) {
request.status = status
}

if (marketId) {
request.marketId = marketId
}

if (perPage) {
request.perPage = perPage
}

if (token) {
request.token = token
}

const response = await this.executeGrpcCall<
InjectiveRFQExchangeRpcPb.ListConditionalOrdersRequest,
InjectiveRFQExchangeRpcPb.ListConditionalOrdersResponse
>(request, this.client.listConditionalOrders.bind(this.client))

return IndexerGrpcRfqTransformer.listConditionalOrdersResponseToConditionalOrders(
response,
)
}

async cancelConditionalOrder({
orderId,
requestAddress,
signature,
}: {
orderId: string
requestAddress: string
signature: string
}) {
const request =
InjectiveRFQExchangeRpcPb.CancelConditionalOrderRequest.create()

request.orderId = orderId
request.requestAddress = requestAddress
request.signature = signature

const response = await this.executeGrpcCall<
InjectiveRFQExchangeRpcPb.CancelConditionalOrderRequest,
InjectiveRFQExchangeRpcPb.CancelConditionalOrderResponse
>(request, this.client.cancelConditionalOrder.bind(this.client))

return {
order: response.order
? IndexerGrpcRfqTransformer.grpcConditionalOrderToConditionalOrder(
response.order,
)
: undefined,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,20 @@ export class IndexerGrpcTcDerivativesApi extends BaseIndexerGrpcConsumer {
token?: string
perPage?: number
marketId?: string
withUpnl?: boolean
direction?: string
withCount?: boolean
accountAddress?: string
}) {
const { marketId, direction, perPage, token, accountAddress, withCount } =
params || {}
const {
marketId,
direction,
perPage,
token,
accountAddress,
withCount,
withUpnl,
} = params || {}

const request = InjectiveTCDerivativesRpcPb.PositionsRequest.create()

Expand All @@ -123,6 +131,10 @@ export class IndexerGrpcTcDerivativesApi extends BaseIndexerGrpcConsumer {
request.withCount = withCount
}

if (withUpnl !== undefined) {
request.withUpnl = withUpnl
}

if (perPage) {
request.perPage = perPage
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,19 +555,20 @@ export class IndexerGrpcDerivativeTransformer {
position: GrpcDerivativePositionV2,
): PositionV2 {
return {
upnl: position.upnl,
denom: position.denom,
margin: position.margin,
ticker: position.ticker,
marketId: position.marketId,
subaccountId: position.subaccountId,
direction: position.direction as TradeDirection,
quantity: position.quantity,
entryPrice: position.entryPrice,
margin: position.margin,
denom: position.denom,
liquidationPrice: position.liquidationPrice,
markPrice: position.markPrice,
ticker: position.ticker,
updatedAt: Number(position.updatedAt),
entryPrice: position.entryPrice,
fundingSum: position.fundingSum,
fundingLast: position.fundingLast,
subaccountId: position.subaccountId,
updatedAt: Number(position.updatedAt),
liquidationPrice: position.liquidationPrice,
direction: position.direction as TradeDirection,
cumulativeFundingEntry: position.cumulativeFundingEntry,
effectiveCumulativeFundingEntry: position.effectiveCumulativeFundingEntry,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import type {
RFQSettlementType,
GrpcRFQSettlement,
SettlementsResponse,
RFQConditionalOrder,
RFQProcessedQuoteType,
GrpcRFQProcessedQuote,
GrpcRFQConditionalOrder,
RFQConditionalOrdersResponse,
} from '../types'

/**
Expand Down Expand Up @@ -46,9 +49,11 @@ export class IndexerGrpcRfqTransformer {
chainId: grpcQuote.chainId,
marketId: grpcQuote.marketId,
quantity: grpcQuote.quantity,
clientId: grpcQuote.clientId,
signature: grpcQuote.signature,
rfqId: Number(grpcQuote.rfqId),
height: Number(grpcQuote.height),
priceCheck: grpcQuote.priceCheck,
createdAt: Number(grpcQuote.createdAt),
updatedAt: Number(grpcQuote.updatedAt),
eventTime: Number(grpcQuote.eventTime),
Expand Down Expand Up @@ -114,8 +119,10 @@ export class IndexerGrpcRfqTransformer {
marketId: grpcProcessedQuote.marketId,
quantity: grpcProcessedQuote.quantity,
signature: grpcProcessedQuote.signature,
clientId: grpcProcessedQuote.clientId,
rfqId: Number(grpcProcessedQuote.rfqId),
height: Number(grpcProcessedQuote.height),
priceCheck: grpcProcessedQuote.priceCheck,
createdAt: Number(grpcProcessedQuote.createdAt),
updatedAt: Number(grpcProcessedQuote.updatedAt),
eventTime: Number(grpcProcessedQuote.eventTime),
Expand Down Expand Up @@ -149,4 +156,35 @@ export class IndexerGrpcRfqTransformer {
next: response.next,
}
}

static grpcConditionalOrderToConditionalOrder(
grpcOrder: GrpcRFQConditionalOrder,
): RFQConditionalOrder {
return {
orderId: grpcOrder.orderId,
marketId: grpcOrder.marketId,
direction: grpcOrder.direction,
margin: grpcOrder.margin,
quantity: grpcOrder.quantity,
worstPrice: grpcOrder.worstPrice,
requestAddress: grpcOrder.requestAddress,
orderType: grpcOrder.orderType,
triggerPrice: grpcOrder.triggerPrice,
status: grpcOrder.status,
createdAt: Number(grpcOrder.createdAt),
updatedAt: Number(grpcOrder.updatedAt),
expiresAt: Number(grpcOrder.expiresAt),
}
}

static listConditionalOrdersResponseToConditionalOrders(
response: InjectiveRFQRpcPb.ListConditionalOrdersResponse,
): RFQConditionalOrdersResponse {
return {
orders: response.orders.map(
IndexerGrpcRfqTransformer.grpcConditionalOrderToConditionalOrder,
),
next: response.next,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class IndexerGrpcTcDerivativesTransformer {
position: GrpcTcDerivativePosition,
): TcDerivativePosition {
return {
upnl: position.upnl,
denom: position.denom,
ticker: position.ticker,
margin: position.margin,
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-ts/src/client/indexer/types/derivatives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface PositionV2 extends Omit<
Position,
'aggregateReduceOnlyQuantity'
> {
upnl: string
denom: string
fundingSum: string
fundingLast: string
Expand Down
Loading