Skip to content

Commit

Permalink
Merge pull request #5 from clober-dex/feat/add-chart-inverted-info
Browse files Browse the repository at this point in the history
feat: add chart inverted info
  • Loading branch information
Dorvin authored Jul 26, 2024
2 parents 5201fc7 + 01bbc8f commit f1c2389
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ type ChartLog @entity {
low: BigDecimal!
close: BigDecimal!
baseVolume: BigDecimal!
bidBookBaseVolume: BigDecimal!
askBookBaseVolume: BigDecimal!
}
11 changes: 10 additions & 1 deletion src/book-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, BigInt, store } from '@graphprotocol/graph-ts'
import { Address, BigDecimal, BigInt, store } from '@graphprotocol/graph-ts'

import {
BookManager,
Expand Down Expand Up @@ -239,6 +239,8 @@ export function handleTake(event: Take): void {
chartLog.low = formattedPrice
chartLog.close = formattedPrice
chartLog.baseVolume = formattedBaseTakenAmount
chartLog.bidBookBaseVolume = formattedBaseTakenAmount
chartLog.askBookBaseVolume = BigDecimal.zero()
} else {
if (formattedPrice.gt(chartLog.high)) {
chartLog.high = formattedPrice
Expand All @@ -248,6 +250,9 @@ export function handleTake(event: Take): void {
}
chartLog.close = formattedPrice
chartLog.baseVolume = chartLog.baseVolume.plus(formattedBaseTakenAmount)
chartLog.bidBookBaseVolume = chartLog.bidBookBaseVolume.plus(
formattedBaseTakenAmount,
)
}
chartLog.save()

Expand Down Expand Up @@ -279,6 +284,8 @@ export function handleTake(event: Take): void {
invertedChartLog.low = formattedInvertedPrice
invertedChartLog.close = formattedInvertedPrice
invertedChartLog.baseVolume = formattedQuoteTakenAmount
invertedChartLog.bidBookBaseVolume = BigDecimal.zero()
invertedChartLog.askBookBaseVolume = formattedQuoteTakenAmount
} else {
if (formattedInvertedPrice.gt(invertedChartLog.high)) {
invertedChartLog.high = formattedInvertedPrice
Expand All @@ -290,6 +297,8 @@ export function handleTake(event: Take): void {
invertedChartLog.baseVolume = invertedChartLog.baseVolume.plus(
formattedQuoteTakenAmount,
)
invertedChartLog.askBookBaseVolume =
invertedChartLog.askBookBaseVolume.plus(formattedQuoteTakenAmount)
}
invertedChartLog.save()
}
Expand Down

0 comments on commit f1c2389

Please sign in to comment.