Skip to content

Commit

Permalink
Add ticker to the static typed model for Fill object. (#747)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang authored Nov 13, 2024
1 parent fbdc547 commit 0e5cba8
Show file tree
Hide file tree
Showing 25 changed files with 148 additions and 87 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.13.24"
version = "1.13.25"

repositories {
google()
Expand Down
106 changes: 58 additions & 48 deletions integration/iOS/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import exchange.dydx.abacus.state.manager.BlockAndTime
import exchange.dydx.abacus.state.manager.HistoricalTradingRewardsPeriod
import exchange.dydx.abacus.utils.mutable
import exchange.dydx.abacus.utils.safeSet
import indexer.codegen.IndexerFillResponseObject
import indexer.codegen.IndexerHistoricalTradingRewardAggregation
import indexer.codegen.IndexerPnlTicksResponseObject
import indexer.codegen.IndexerTransferResponseObject
import indexer.models.IndexerCompositeFillObject
import indexer.models.chain.OnChainAccountBalanceObject
import indexer.models.chain.OnChainDelegationResponse
import indexer.models.chain.OnChainStakingRewardsResponse
Expand Down Expand Up @@ -356,7 +356,7 @@ internal class WalletProcessor(

internal fun processFills(
existing: InternalWalletState,
payload: List<IndexerFillResponseObject>?,
payload: List<IndexerCompositeFillObject>?,
subaccountNumber: Int,
): InternalWalletState {
existing.account = v4accountProcessor.processFills(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import exchange.dydx.abacus.state.manager.HistoricalTradingRewardsPeriod
import exchange.dydx.abacus.utils.IMutableList
import exchange.dydx.abacus.utils.mutable
import exchange.dydx.abacus.utils.safeSet
import indexer.codegen.IndexerFillResponseObject
import indexer.codegen.IndexerHistoricalBlockTradingReward
import indexer.codegen.IndexerHistoricalTradingRewardAggregation
import indexer.codegen.IndexerPnlTicksResponseObject
import indexer.codegen.IndexerTransferResponseObject
import indexer.models.IndexerCompositeFillObject
import indexer.models.chain.OnChainAccountBalanceObject
import indexer.models.chain.OnChainDelegationResponse
import indexer.models.chain.OnChainStakingRewardsResponse
Expand Down Expand Up @@ -313,7 +313,7 @@ internal class V4AccountProcessor(

internal fun processFills(
existing: InternalAccountState,
payload: List<IndexerFillResponseObject>?,
payload: List<IndexerCompositeFillObject>?,
subaccountNumber: Int,
): InternalAccountState {
val subaccount = existing.subaccounts[subaccountNumber] ?: InternalSubaccountState(subaccountNumber = subaccountNumber)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import exchange.dydx.abacus.protocols.ParserProtocol
import exchange.dydx.abacus.utils.Logger
import exchange.dydx.abacus.utils.NUM_PARENT_SUBACCOUNTS
import exchange.dydx.abacus.utils.safeSet
import indexer.codegen.IndexerFillResponseObject
import indexer.models.IndexerCompositeFillObject

internal interface FillProcessorProtocol {
fun process(
payload: IndexerFillResponseObject,
payload: IndexerCompositeFillObject,
subaccountNumber: Int,
): SubaccountFill?
}
Expand Down Expand Up @@ -82,14 +82,14 @@ internal class FillProcessor(
)

override fun process(
payload: IndexerFillResponseObject,
payload: IndexerCompositeFillObject,
subaccountNumber: Int,
): SubaccountFill? {
fun doProcess(): SubaccountFill? {
val fillSubaccountNumber = parser.asInt(payload.subaccountNumber) ?: subaccountNumber

val id = payload.id ?: return null
val marketId = payload.market ?: return null
val marketId = payload.market ?: payload.ticker ?: return null
val displayId = MarketId.getDisplayId(marketId)
val side = payload.side?.name?.let { OrderSide.invoke(rawValue = it) } ?: return null
val liquidity =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import exchange.dydx.abacus.processor.base.BaseProcessor
import exchange.dydx.abacus.processor.base.mergeWithIds
import exchange.dydx.abacus.protocols.LocalizerProtocol
import exchange.dydx.abacus.protocols.ParserProtocol
import indexer.codegen.IndexerFillResponseObject
import indexer.models.IndexerCompositeFillObject

internal class FillsProcessor(
parser: ParserProtocol,
Expand All @@ -15,7 +15,7 @@ internal class FillsProcessor(

fun process(
existing: List<SubaccountFill>?,
payload: List<IndexerFillResponseObject>,
payload: List<IndexerCompositeFillObject>,
subaccountNumber: Int
): List<SubaccountFill> {
val new = payload.mapNotNull { eachPayload ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import exchange.dydx.abacus.state.manager.BlockAndTime
import exchange.dydx.abacus.utils.mutable
import exchange.dydx.abacus.utils.safeSet
import indexer.codegen.IndexerAssetPositionResponseObject
import indexer.codegen.IndexerFillResponseObject
import indexer.codegen.IndexerPerpetualPositionResponseObject
import indexer.codegen.IndexerPerpetualPositionStatus
import indexer.codegen.IndexerPnlTicksResponseObject
import indexer.codegen.IndexerSubaccountResponseObject
import indexer.codegen.IndexerTransferResponseObject
import indexer.models.IndexerCompositeFillObject
import indexer.models.IndexerCompositeOrderObject

@Suppress("UNCHECKED_CAST")
Expand Down Expand Up @@ -123,7 +123,7 @@ internal open class SubaccountProcessor(
subaccountCalculated.quoteBalance = subaccountCalculator.calculateQuoteBalance(state.assetPositions)
state.calculated[CalculationPeriod.current] = subaccountCalculated

val fills = parser.asTypedList<IndexerFillResponseObject>(content["fills"])
val fills = parser.asTypedList<IndexerCompositeFillObject>(content["fills"])
state = processFills(
subaccount = state,
payload = fills,
Expand Down Expand Up @@ -413,7 +413,7 @@ internal open class SubaccountProcessor(

private fun processFills(
subaccount: InternalSubaccountState,
payload: List<IndexerFillResponseObject>?,
payload: List<IndexerCompositeFillObject>?,
reset: Boolean,
): InternalSubaccountState {
subaccount.fills = fillsProcessor.process(
Expand Down Expand Up @@ -574,7 +574,7 @@ internal open class SubaccountProcessor(

internal fun processFills(
existing: InternalSubaccountState,
payload: List<IndexerFillResponseObject>?,
payload: List<IndexerCompositeFillObject>?,
): InternalSubaccountState {
return processFills(existing, payload, true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import exchange.dydx.abacus.state.changes.Changes
import exchange.dydx.abacus.state.changes.StateChanges
import exchange.dydx.abacus.state.manager.BlockAndTime
import exchange.dydx.abacus.utils.Logger
import indexer.codegen.IndexerFillResponse
import indexer.codegen.IndexerTransferResponse
import indexer.models.IndexerCompositeFillResponse
import indexer.models.chain.OnChainAccountBalanceObject
import indexer.models.chain.OnChainDelegationResponse
import indexer.models.chain.OnChainStakingRewardsResponse
Expand Down Expand Up @@ -202,7 +202,7 @@ internal fun TradingStateMachine.receivedFills(
val size = fills?.size ?: 0
return if (size > 0) {
if (staticTyping) {
val payload = parser.asTypedObject<IndexerFillResponse>(payload)
val payload = parser.asTypedObject<IndexerCompositeFillResponse>(payload)
walletProcessor.processFills(internalState.wallet, payload?.fills?.toList(), subaccountNumber)
} else {
wallet = walletProcessor.receivedFillsDeprecated(wallet, payload, subaccountNumber)
Expand Down
32 changes: 32 additions & 0 deletions src/commonMain/kotlin/indexer/models/IndexerCompositeFillObject.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package indexer.models

import indexer.codegen.IndexerFillType
import indexer.codegen.IndexerIsoString
import indexer.codegen.IndexerLiquidity
import indexer.codegen.IndexerMarketType
import indexer.codegen.IndexerOrderSide
import kotlinx.serialization.Serializable

@Serializable
data class IndexerCompositeFillObject(

// Copied from IndexerFillResponseObject
val id: kotlin.String? = null,
val side: IndexerOrderSide? = null,
val liquidity: IndexerLiquidity? = null,
val type: IndexerFillType? = null,
val market: kotlin.String? = null,
val marketType: IndexerMarketType? = null,
val price: kotlin.String? = null,
val size: kotlin.String? = null,
val fee: kotlin.String? = null,
val affiliateRevShare: kotlin.String? = null,
val createdAt: IndexerIsoString? = null,
val createdAtHeight: kotlin.String? = null,
val orderId: kotlin.String? = null,
val clientMetadata: kotlin.String? = null,
val subaccountNumber: kotlin.Int? = null,

// Additional fields for WS
val ticker: kotlin.String? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package indexer.models

import kotlinx.serialization.Serializable

@Serializable
data class IndexerCompositeFillResponse(
val pageSize: kotlin.Int? = null,
val totalResults: kotlin.Int? = null,
val offset: kotlin.Int? = null,
val fills: kotlin.Array<IndexerCompositeFillObject>? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import exchange.dydx.abacus.output.input.OrderSide
import exchange.dydx.abacus.output.input.OrderType
import exchange.dydx.abacus.tests.mock.LocalizerProtocolMock
import exchange.dydx.abacus.utils.Parser
import indexer.codegen.IndexerFillResponseObject
import indexer.codegen.IndexerFillType
import indexer.codegen.IndexerLiquidity
import indexer.codegen.IndexerMarketType
import indexer.codegen.IndexerOrderSide
import indexer.models.IndexerCompositeFillObject
import kotlinx.datetime.Instant
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -22,7 +22,7 @@ class FillProcessorTests {
companion object {
private val createdAt = Instant.parse("2021-01-01T00:00:00Z")

val payloadMock = IndexerFillResponseObject(
val payloadMock = IndexerCompositeFillObject(
id = "1",
side = IndexerOrderSide.BUY,
liquidity = IndexerLiquidity.MAKER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import exchange.dydx.abacus.output.account.SubaccountFill
import exchange.dydx.abacus.tests.mock.LocalizerProtocolMock
import exchange.dydx.abacus.tests.mock.processor.wallet.account.FillProcessorMock
import exchange.dydx.abacus.utils.Parser
import indexer.codegen.IndexerFillResponseObject
import indexer.models.IndexerCompositeFillObject
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -35,7 +35,7 @@ class FillsProcessorTests {
val output = fillsProcessor.process(
existing = null,
payload = listOf(
IndexerFillResponseObject(
IndexerCompositeFillObject(
id = "1",
),
),
Expand All @@ -56,10 +56,10 @@ class FillsProcessorTests {
createSubaccountFill("1"),
),
payload = listOf(
IndexerFillResponseObject(
IndexerCompositeFillObject(
id = "1",
),
IndexerFillResponseObject(
IndexerCompositeFillObject(
id = "2",
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package exchange.dydx.abacus.tests.mock.processor.wallet.account

import exchange.dydx.abacus.output.account.SubaccountFill
import exchange.dydx.abacus.processor.wallet.account.FillProcessorProtocol
import indexer.codegen.IndexerFillResponseObject
import indexer.models.IndexerCompositeFillObject

internal class FillProcessorMock : FillProcessorProtocol {
var processCallCount = 0
var processAction: ((payload: IndexerFillResponseObject, subaccountNumber: Int) -> SubaccountFill?)? = null
var processAction: ((payload: IndexerCompositeFillObject, subaccountNumber: Int) -> SubaccountFill?)? = null

override fun process(
payload: IndexerFillResponseObject,
payload: IndexerCompositeFillObject,
subaccountNumber: Int
): SubaccountFill? {
processCallCount++
Expand Down
2 changes: 1 addition & 1 deletion v4_abacus.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'v4_abacus'
spec.version = '1.13.24'
spec.version = '1.13.25'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit 0e5cba8

Please sign in to comment.