Closed Klapeyron closed 1 month ago
@coderabbitai review
[!TIP] For best results, initiate chat on the files or code changes.
@Klapeyron, to track separate opening prices for each side of the position, we need to make the following changes:
Update the Position
class in src/model/generated/position.model.ts
to include separate fields for the opening prices of the long and short sides:
@BigDecimalColumn_({nullable: false})
createPriceLong!: BigDecimal
@BigDecimalColumn_({nullable: false})
createPriceShort!: BigDecimal
Update the GraphQL schema in schema.graphql
to reflect these changes:
type Position @entity {
id: ID!
market: Market!
createPriceLong: BigDecimal!
createPriceShort: BigDecimal!
price: BigDecimal!
quantity: BigInt!
quantityLeft: BigInt!
long: String!
short: String!
blockHeight: BigInt!
timestamp: DateTime!
status: PositionStatus
}
Modify the event processor in src/eventprocessor/market/postionCreatedEventProcessor.ts
to set the new fields:
let position = new Position({
id: parsedEvent.positionId.toString(),
market: market,
quantity: BigInt(parsedEvent.quantity),
long: encodeUserValue(parsedEvent.long),
short: encodeUserValue(parsedEvent.short),
blockHeight: BigInt(block.header.height),
timestamp: new Date(block.header.timestamp),
status: PositionStatus.OPEN,
quantityLeft: BigInt(parsedEvent.quantity),
createPriceLong: BigDecimal(parsedEvent.priceLong, USDC_DECIMALS),
createPriceShort: BigDecimal(parsedEvent.priceShort, USDC_DECIMALS),
price: BigDecimal(parsedEvent.price, USDC_DECIMALS), // temporary - set in the next event
});
These changes will ensure that the indexer tracks separate opening prices for each side of the position accurately.
Indexer is not tracking correctly opening position prices. Right now, it stores opening price as
createPrice
variable which is fine for brand new positions. If position is created out of existing position, thencreatePrice
is set for new trade, which cases ambiguous value for position side that was passive in this transaction. Indexer should track separate opening price for each side of the position and update it in accordance with the information if position is just created or is offset.