From 0bb05f63daaadc68f31d8d90ce73e2f2e32d9ad4 Mon Sep 17 00:00:00 2001 From: Rui Date: Mon, 11 Nov 2024 10:57:02 -0800 Subject: [PATCH] Fix code_gen of enum values with underscores --- .../processor/markets/MarketProcessor.kt | 6 +-- .../model/TradingStateMachine+Sparklines.kt | 4 +- .../state/v2/supervisor/MarketsSupervisor.kt | 4 +- .../IndexerAffiliateSnapshotResponseObject.kt | 8 +++- .../codegen/IndexerComplianceReason.kt | 12 +++--- .../codegen/IndexerComplianceStatus.kt | 8 ++-- .../codegen/IndexerPerpetualMarketStatus.kt | 8 ++-- .../codegen/IndexerSparklineTimePeriod.kt | 6 +-- .../processor/markets/MarketProcessorTests.kt | 6 +-- .../markets/MarketsProcessorTests.kt | 2 +- .../TradingStateMachine+TestUtils.kt | 2 +- swagger_codegen.sh | 38 +++++++++++++++++++ 12 files changed, 74 insertions(+), 30 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/markets/MarketProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/markets/MarketProcessor.kt index 9c51a3dfc..177285f55 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/markets/MarketProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/markets/MarketProcessor.kt @@ -186,10 +186,10 @@ internal class MarketProcessor( ): PerpetualMarket? { cachedIndexerSparklines[marketId] = payload.mapNotNull { parser.asDouble(it) }.reversed() when (period) { - IndexerSparklineTimePeriod.ONEDAY -> { + IndexerSparklineTimePeriod.ONE_DAY -> { return createPerpetualMarket(marketId) } - IndexerSparklineTimePeriod.SEVENDAYS -> { + IndexerSparklineTimePeriod.SEVEN_DAYS -> { val sevenDaySparklineEntries = 42 cachedIsNew[marketId] = payload.size < sevenDaySparklineEntries return createPerpetualMarket(marketId) @@ -249,7 +249,7 @@ internal class MarketProcessor( canTrade = true, canReduce = true, ) - IndexerPerpetualMarketStatus.CANCELONLY -> MarketStatus( + IndexerPerpetualMarketStatus.CANCEL_ONLY -> MarketStatus( canTrade = false, canReduce = true, ) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine+Sparklines.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine+Sparklines.kt index 4e2f9ffe7..f77ff2c91 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine+Sparklines.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine+Sparklines.kt @@ -16,10 +16,10 @@ internal fun TradingStateMachine.sparklines( return if (sparklines != null) { marketsProcessor.processSparklines(internalState.marketsSummary, sparklines, period) when (period) { - IndexerSparklineTimePeriod.ONEDAY -> { + IndexerSparklineTimePeriod.ONE_DAY -> { StateChanges(iListOf(Changes.sparklines, Changes.markets), null) } - IndexerSparklineTimePeriod.SEVENDAYS -> { + IndexerSparklineTimePeriod.SEVEN_DAYS -> { StateChanges(iListOf(Changes.markets), null) } } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/MarketsSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/MarketsSupervisor.kt index ce438673d..8df121ae2 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/MarketsSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/MarketsSupervisor.kt @@ -150,7 +150,7 @@ internal class MarketsSupervisor( val url = helper.configs.publicApiUrl("sparklines") if (url != null) { // Get 1 day sparkline for market display - val period = IndexerSparklineTimePeriod.ONEDAY + val period = IndexerSparklineTimePeriod.ONE_DAY helper.get(url, iMapOf("timePeriod" to period.value), null) { _, response, httpCode, _ -> if (helper.success(httpCode) && response != null) { parseSparklinesResponse(response, period) @@ -159,7 +159,7 @@ internal class MarketsSupervisor( if (configs.retrieveSevenDaySparkline) { // Get 7 day sparkline to determine if market is new - val period = IndexerSparklineTimePeriod.SEVENDAYS + val period = IndexerSparklineTimePeriod.SEVEN_DAYS helper.get(url, iMapOf("timePeriod" to period.value), null) { _, response, httpCode, _ -> if (helper.success(httpCode) && response != null) { parseSparklinesResponse(response, period) diff --git a/src/commonMain/kotlin/indexer/codegen/IndexerAffiliateSnapshotResponseObject.kt b/src/commonMain/kotlin/indexer/codegen/IndexerAffiliateSnapshotResponseObject.kt index 104ded4b5..cc4304c38 100644 --- a/src/commonMain/kotlin/indexer/codegen/IndexerAffiliateSnapshotResponseObject.kt +++ b/src/commonMain/kotlin/indexer/codegen/IndexerAffiliateSnapshotResponseObject.kt @@ -24,6 +24,9 @@ import kotlin.js.JsExport * @param affiliateReferredUsers * @param affiliateReferredNetProtocolEarnings * @param affiliateReferredTotalVolume + * @param affiliateReferredMakerFees + * @param affiliateReferredTakerFees + * @param affiliateReferredMakerRebates */ @JsExport @Serializable @@ -36,5 +39,8 @@ data class IndexerAffiliateSnapshotResponseObject( val affiliateTotalReferredFees: kotlin.Double? = null, val affiliateReferredUsers: kotlin.Double? = null, val affiliateReferredNetProtocolEarnings: kotlin.Double? = null, - val affiliateReferredTotalVolume: kotlin.Double? = null + val affiliateReferredTotalVolume: kotlin.Double? = null, + val affiliateReferredMakerFees: kotlin.Double? = null, + val affiliateReferredTakerFees: kotlin.Double? = null, + val affiliateReferredMakerRebates: kotlin.Double? = null ) diff --git a/src/commonMain/kotlin/indexer/codegen/IndexerComplianceReason.kt b/src/commonMain/kotlin/indexer/codegen/IndexerComplianceReason.kt index 913da0f92..515ead74b 100644 --- a/src/commonMain/kotlin/indexer/codegen/IndexerComplianceReason.kt +++ b/src/commonMain/kotlin/indexer/codegen/IndexerComplianceReason.kt @@ -16,15 +16,15 @@ import kotlin.js.JsExport /** * - * Values: MANUAL,USGEO,CAGEO,GBGEO,SANCTIONEDGEO,COMPLIANCEPROVIDER + * Values: MANUAL,US_GEO,CA_GEO,GB_GEO,SANCTIONED_GEO,COMPLIANCE_PROVIDER */ @JsExport @Serializable enum class IndexerComplianceReason(val value: kotlin.String) { MANUAL("MANUAL"), // :/ - USGEO("US_GEO"), // :/ - CAGEO("CA_GEO"), // :/ - GBGEO("GB_GEO"), // :/ - SANCTIONEDGEO("SANCTIONED_GEO"), // :/ - COMPLIANCEPROVIDER("COMPLIANCE_PROVIDER"); // :/ + US_GEO("US_GEO"), // :/ + CA_GEO("CA_GEO"), // :/ + GB_GEO("GB_GEO"), // :/ + SANCTIONED_GEO("SANCTIONED_GEO"), // :/ + COMPLIANCE_PROVIDER("COMPLIANCE_PROVIDER"); // :/ } diff --git a/src/commonMain/kotlin/indexer/codegen/IndexerComplianceStatus.kt b/src/commonMain/kotlin/indexer/codegen/IndexerComplianceStatus.kt index 33952e842..18ed88ffb 100644 --- a/src/commonMain/kotlin/indexer/codegen/IndexerComplianceStatus.kt +++ b/src/commonMain/kotlin/indexer/codegen/IndexerComplianceStatus.kt @@ -16,14 +16,14 @@ import kotlin.js.JsExport /** * - * Values: COMPLIANT,FIRSTSTRIKECLOSEONLY,FIRSTSTRIKE,CLOSEONLY,BLOCKED + * Values: COMPLIANT,FIRST_STRIKE_CLOSE_ONLY,FIRST_STRIKE,CLOSE_ONLY,BLOCKED */ @JsExport @Serializable enum class IndexerComplianceStatus(val value: kotlin.String) { COMPLIANT("COMPLIANT"), // :/ - FIRSTSTRIKECLOSEONLY("FIRST_STRIKE_CLOSE_ONLY"), // :/ - FIRSTSTRIKE("FIRST_STRIKE"), // :/ - CLOSEONLY("CLOSE_ONLY"), // :/ + FIRST_STRIKE_CLOSE_ONLY("FIRST_STRIKE_CLOSE_ONLY"), // :/ + FIRST_STRIKE("FIRST_STRIKE"), // :/ + CLOSE_ONLY("CLOSE_ONLY"), // :/ BLOCKED("BLOCKED"); // :/ } diff --git a/src/commonMain/kotlin/indexer/codegen/IndexerPerpetualMarketStatus.kt b/src/commonMain/kotlin/indexer/codegen/IndexerPerpetualMarketStatus.kt index da7f09f80..b0c064dea 100644 --- a/src/commonMain/kotlin/indexer/codegen/IndexerPerpetualMarketStatus.kt +++ b/src/commonMain/kotlin/indexer/codegen/IndexerPerpetualMarketStatus.kt @@ -16,15 +16,15 @@ import kotlin.js.JsExport /** * - * Values: ACTIVE,PAUSED,CANCELONLY,POSTONLY,INITIALIZING,FINALSETTLEMENT + * Values: ACTIVE,PAUSED,CANCEL_ONLY,POST_ONLY,INITIALIZING,FINAL_SETTLEMENT */ @JsExport @Serializable enum class IndexerPerpetualMarketStatus(val value: kotlin.String) { ACTIVE("ACTIVE"), // :/ PAUSED("PAUSED"), // :/ - CANCELONLY("CANCEL_ONLY"), // :/ - POSTONLY("POST_ONLY"), // :/ + CANCEL_ONLY("CANCEL_ONLY"), // :/ + POST_ONLY("POST_ONLY"), // :/ INITIALIZING("INITIALIZING"), // :/ - FINALSETTLEMENT("FINAL_SETTLEMENT"); // :/ + FINAL_SETTLEMENT("FINAL_SETTLEMENT"); // :/ } diff --git a/src/commonMain/kotlin/indexer/codegen/IndexerSparklineTimePeriod.kt b/src/commonMain/kotlin/indexer/codegen/IndexerSparklineTimePeriod.kt index d204ac645..ea0ce8d2f 100644 --- a/src/commonMain/kotlin/indexer/codegen/IndexerSparklineTimePeriod.kt +++ b/src/commonMain/kotlin/indexer/codegen/IndexerSparklineTimePeriod.kt @@ -16,11 +16,11 @@ import kotlin.js.JsExport /** * - * Values: ONEDAY,SEVENDAYS + * Values: ONE_DAY,SEVEN_DAYS */ @JsExport @Serializable enum class IndexerSparklineTimePeriod(val value: kotlin.String) { - ONEDAY("ONE_DAY"), // :/ - SEVENDAYS("SEVEN_DAYS"); // :/ + ONE_DAY("ONE_DAY"), // :/ + SEVEN_DAYS("SEVEN_DAYS"); // :/ } diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/processor/markets/MarketProcessorTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/processor/markets/MarketProcessorTests.kt index e24fc36b0..f25b574b9 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/processor/markets/MarketProcessorTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/processor/markets/MarketProcessorTests.kt @@ -153,21 +153,21 @@ class MarketProcessorTests { val output = processor.processSparklines( marketId = "BTC-USD", payload = listOf("1", "2", "3"), - period = IndexerSparklineTimePeriod.ONEDAY, + period = IndexerSparklineTimePeriod.ONE_DAY, ) assertEquals(output?.perpetual?.line, listOf(3.0, 2.0, 1.0).toIList()) val output2 = processor.processSparklines( marketId = "BTC-USD", payload = listOf("1", "2", "3"), - period = IndexerSparklineTimePeriod.SEVENDAYS, + period = IndexerSparklineTimePeriod.SEVEN_DAYS, ) assertEquals(output2?.perpetual?.isNew, true) val output3 = processor.processSparklines( marketId = "BTC-USD", payload = MutableList(42) { "1" }, // 42 elements - period = IndexerSparklineTimePeriod.SEVENDAYS, + period = IndexerSparklineTimePeriod.SEVEN_DAYS, ) assertEquals(output3?.perpetual?.isNew, false) } diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/processor/markets/MarketsProcessorTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/processor/markets/MarketsProcessorTests.kt index 294ef02fa..09827dac0 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/processor/markets/MarketsProcessorTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/processor/markets/MarketsProcessorTests.kt @@ -100,7 +100,7 @@ class MarketsProcessorTests { "BTC-USD" to listOf("1", "2", "3"), "ETH-USD" to listOf("1", "2", "3"), ) - val result = processor.processSparklines(state, sparklines, IndexerSparklineTimePeriod.ONEDAY) + val result = processor.processSparklines(state, sparklines, IndexerSparklineTimePeriod.ONE_DAY) assertEquals(2, marketProcessor.processSparklinesCallCount) assertEquals(2, result.markets.size) } diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/tests/extensions/TradingStateMachine+TestUtils.kt b/src/commonTest/kotlin/exchange.dydx.abacus/tests/extensions/TradingStateMachine+TestUtils.kt index faf3b76ec..7dfc7824d 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/tests/extensions/TradingStateMachine+TestUtils.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/tests/extensions/TradingStateMachine+TestUtils.kt @@ -579,7 +579,7 @@ fun TradingStateMachine.rest( } "/v4/sparklines" -> { - changes = sparklines(payload, IndexerSparklineTimePeriod.ONEDAY) + changes = sparklines(payload, IndexerSparklineTimePeriod.ONE_DAY) } "/v4/fills" -> { diff --git a/swagger_codegen.sh b/swagger_codegen.sh index fa253cec1..871f86c86 100755 --- a/swagger_codegen.sh +++ b/swagger_codegen.sh @@ -106,6 +106,44 @@ sed -i '' 's/_4HOURS("4HOURS")/@SerialName("4HOURS")\n _4HOURS("4HOURS")/' ge # add @SerialName("1DAY") to _1DAY("1DAY") in CandleResolution.kt sed -i '' 's/_1DAY("1DAY")/@SerialName("1DAY")\n _1DAY("1DAY")/' generated/src/main/kotlin/indexer/codegen/CandleResolution.kt +# replace CANCELONLY with CANCEL_ONLY in PerpetualMarketStatus.kt +sed -i '' 's/CANCELONLY/CANCEL_ONLY/' generated/src/main/kotlin/indexer/codegen/PerpetualMarketStatus.kt + +# replace POSTONLY with POST_ONLY in PerpetualMarketStatus.kt +sed -i '' 's/POSTONLY/POST_ONLY/' generated/src/main/kotlin/indexer/codegen/PerpetualMarketStatus.kt + +# replace FINALSETTLEMENT with FINAL_SETTLEMENT in PerpetualMarketStatus.kt +sed -i '' 's/FINALSETTLEMENT/FINAL_SETTLEMENT/' generated/src/main/kotlin/indexer/codegen/PerpetualMarketStatus.kt + +# replace SANCTIONEDGEO with SANCTIONED_GEO in ComplianceReason.kt +sed -i '' 's/SANCTIONEDGEO/SANCTIONED_GEO/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt + +# replace COMPLIANCEPROVIDER with COMPLIANCE_PROVIDER in ComplianceReason.kt +sed -i '' 's/COMPLIANCEPROVIDER/COMPLIANCE_PROVIDER/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt + +# replace USGEO with US_GEO in ComplianceReason.kt +sed -i '' 's/USGEO/US_GEO/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt + +# replace CAGEO with CA_GEO in ComplianceReason.kt +sed -i '' 's/CAGEO/CA_GEO/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt + +# replace GBGEO with GB_GEO in ComplianceReason.kt +sed -i '' 's/GBGEO/GB_GEO/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt + +# replace FIRSTSTRIKECLOSEONLY with FIRST_STRIKE_CLOSE_ONLY in ComplianceStatus.kt +sed -i '' 's/FIRSTSTRIKECLOSEONLY/FIRST_STRIKE_CLOSE_ONLY/' generated/src/main/kotlin/indexer/codegen/ComplianceStatus.kt + +# replace FIRSTSTRIKE with FIRST_STRIKE in ComplianceStatus.kt +sed -i '' 's/FIRSTSTRIKE/FIRST_STRIKE/' generated/src/main/kotlin/indexer/codegen/ComplianceStatus.kt + +# replace CLOSEONLY with CLOSE_ONLY in ComplianceStatus.kt +sed -i '' 's/CLOSEONLY/CLOSE_ONLY/' generated/src/main/kotlin/indexer/codegen/ComplianceStatus.kt + +# replace ONEDAY with ONE_DAY in SparklineTimePeriod.kt +sed -i '' 's/ONEDAY/ONE_DAY/' generated/src/main/kotlin/indexer/codegen/SparklineTimePeriod.kt + +# replace SEVENDAYS with SEVEN_DAYS in SparklineTimePeriod.kt +sed -i '' 's/SEVENDAYS/SEVEN_DAYS/' generated/src/main/kotlin/indexer/codegen/SparklineTimePeriod.kt # for each of the time in the generated code, run "swagger_update_file.sh " find generated/src/main/kotlin/indexer -type f \