Skip to content

Commit

Permalink
Use string for clientId (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
prashanDYDX authored Sep 12, 2024
1 parent 28240c4 commit 50ac9d4
Show file tree
Hide file tree
Showing 27 changed files with 104 additions and 171 deletions.
17 changes: 16 additions & 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.10.4"
version = "1.11.0"

repositories {
google()
Expand Down Expand Up @@ -257,3 +257,18 @@ tasks.register<Exec>("v4WebHotSwapTrigger") {

commandLine = listOf("./trigger_v4web_reload.sh")
}

tasks.register<Exec>("updateAbacusPodspec") {
group = "abacus"

// replace the line "if !Dir.exist?('build/cocoapods/framework/Abacus.framework') || Dir.empty?('build/cocoapods/framework/Abacus.framework')" with "if false"
commandLine = listOf(
"sed",
"-i",
"",
"s/if !Dir.exist?('build\\/cocoapods\\/framework\\/Abacus.framework') || Dir.empty?('build\\/cocoapods\\/framework\\/Abacus.framework')/if false/",
"v4_abacus.podspec"
)
}

tasks.get("podspec").finalizedBy("updateAbacusPodspec")
7 changes: 0 additions & 7 deletions bump_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,5 @@ fi
#
./gradlew podspec

# Remove the warning step about ./gradlew :generateDummyFramework, since on iOS we use CocoaPods to
# download the source code and build locally.
PODSPEC_FILE="v4_abacus.podspec"

# replace the line "if !Dir.exist?('build/cocoapods/framework/Abacus.framework') || Dir.empty?('build/cocoapods/framework/Abacus.framework')" with "if false"
sed -i '' "s/if !Dir.exist?('build\/cocoapods\/framework\/Abacus.framework') || Dir.empty?('build\/cocoapods\/framework\/Abacus.framework')/if false/" $PODSPEC_FILE

cd integration/iOS
pod install
2 changes: 1 addition & 1 deletion docs/Account.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ An array of [SubaccountOrder](#SubaccountOrder)
data class SubaccountOrder(
&emsp;val subaccountNumber: Int,
&emsp;val id: String,
&emsp;val clientId: UInt?,
&emsp;val clientId: String?,
&emsp;val type: OrderType,
&emsp;val side: OrderSide,
&emsp;val status: OrderStatus,
Expand Down
106 changes: 48 additions & 58 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 @@ -16,7 +16,7 @@ import kotlinx.serialization.Serializable
data class SubaccountOrder(
val subaccountNumber: Int?,
val id: String,
val clientId: UInt?,
val clientId: String?,
val type: OrderType,
val side: OrderSide,
val status: OrderStatus,
Expand Down Expand Up @@ -56,7 +56,7 @@ data class SubaccountOrder(
// TODO: Remove default to 0 for subaccountNumber once new indexer response is consumed. Prevents breaking change
val subaccountNumber = parser.asInt(data["subaccountNumber"]) ?: 0
val id = parser.asString(data["id"])
val clientId = parser.asUInt(data["clientId"])
val clientId = parser.asString(data["clientId"])
val marketId = parser.asString(data["marketId"])
val displayId = parser.asString(data["displayId"])
val clobPairId = parser.asInt(data["clobPairId"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ internal class OrderProcessor(
val order = SubaccountOrder(
subaccountNumber = orderSubaccountNumber,
id = id,
clientId = parser.asUInt(payload.clientId),
clientId = parser.asString(payload.clientId),
type = type,
side = side,
status = modifiedStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ interface ParserProtocol {
// parse a field to int
fun asInt(data: Any?): Int?

// parse a field to unsigned int
fun asUInt(data: Any?): UInt?

// parse a field to int
fun asLong(data: Any?): Long?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ import kotlin.random.nextUInt

object ClientId {

fun generate() = Random.nextUInt()
/**
* Client ID on the protocol is a fixed32. And is returned from the indexer as an unsigned int string.
*
* This value is returned as a String for compaitiblity with JS. JS number seems to always interpret as signed.
*/
fun generate() = Random.nextUInt().toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data class FaucetRecord(

data class PlaceOrderRecord(
val subaccountNumber: Int,
val clientId: UInt,
val clientId: String,
val timestampInMilliseconds: Double,
val fromSlTpDialog: Boolean,
var lastOrderStatus: OrderStatus?,
Expand All @@ -27,14 +27,14 @@ data class PlaceOrderRecord(

data class CancelOrderRecord(
val subaccountNumber: Int,
val clientId: UInt,
val clientId: String,
val timestampInMilliseconds: Double,
val fromSlTpDialog: Boolean,
)

data class IsolatedPlaceOrderRecord(
val subaccountNumber: Int,
val clientId: UInt,
val clientId: String,
val destinationSubaccountNumber: Int,
)

Expand All @@ -53,7 +53,7 @@ data class PlaceOrderMarketInfo(
data class HumanReadablePlaceOrderPayload(
val subaccountNumber: Int,
val marketId: String,
val clientId: UInt,
val clientId: String,
val type: String,
val side: String,
val price: Double,
Expand All @@ -76,7 +76,7 @@ data class HumanReadableCancelOrderPayload(
val subaccountNumber: Int,
val type: String,
val orderId: String,
val clientId: UInt,
val clientId: String,
val orderFlags: Int,
val clobPairId: Int,
val goodTilBlock: Int?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package exchange.dydx.abacus.state.model

import exchange.dydx.abacus.output.account.SubaccountOrder
import exchange.dydx.abacus.output.input.OrderStatus
import exchange.dydx.abacus.responses.StateResponse
import exchange.dydx.abacus.state.changes.Changes
import exchange.dydx.abacus.state.changes.StateChanges
Expand Down Expand Up @@ -76,22 +75,7 @@ internal fun TradingStateMachine.updateHeight(
}

internal fun TradingStateMachine.findOrder(
orderId: String,
subaccountNumber: Int,
): SubaccountOrder? {
val subaccount = state?.subaccount(subaccountNumber) ?: return null
val orders = subaccount.orders ?: return null
val order = orders.firstOrNull {
it.id == orderId
} ?: return null
return when (order.status) {
OrderStatus.Open, OrderStatus.Pending, OrderStatus.Untriggered -> order
else -> null
}
}

internal fun TradingStateMachine.findOrder(
clientId: UInt,
clientId: String,
subaccountNumber: Int,
): SubaccountOrder? {
val subaccount = state?.subaccount(subaccountNumber) ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal class SubaccountTransactionSupervisor(

private val pendingIsolatedOrderRecords: IMutableList<IsolatedPlaceOrderRecord> = iMutableListOf()

private var lastOrderClientId: UInt? = null
private var lastOrderClientId: String? = null
set(value) {
if (field != value) {
field = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class AnalyticsUtils {
val stopLossOrderTypes = listOf(OrderType.StopMarket, OrderType.StopLimit)
val takeProfitOrderTypes = listOf(OrderType.TakeProfitMarket, OrderType.TakeProfitLimit)

var stopLossOrderCancelClientId: UInt? = null
var stopLossOrderPlaceClientId: UInt? = null
var takeProfitOrderCancelClientId: UInt? = null
var takeProfitOrderPlaceClientId: UInt? = null
var stopLossOrderCancelClientId: String? = null
var stopLossOrderPlaceClientId: String? = null
var takeProfitOrderCancelClientId: String? = null
var takeProfitOrderPlaceClientId: String? = null

var stopLossOrderAction: TriggerOrderAction? = null
var takeProfitOrderAction: TriggerOrderAction? = null
Expand Down
43 changes: 0 additions & 43 deletions src/commonMain/kotlin/exchange.dydx.abacus/utils/Parser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,49 +216,6 @@ class Parser : ParserProtocol {
return null
}

override fun asUInt(data: Any?): UInt? {
val jsonLiteral = data as? JsonPrimitive
if (jsonLiteral != null) {
return jsonLiteral.longOrNull?.toUInt()
}

val long = data as? Long
if (long != null) {
return long.toUInt()
}

val int = data as? Int
if (int != null) {
return int.toUInt()
}

val float = data as? Float
if (float != null) {
return float.toUInt()
}

val double = data as? Double
if (double != null) {
return double.toUInt()
}

val decimal = data as? BigDecimal
if (decimal != null) {
return decimal.doubleValue(false).toUInt()
}

val string = data as? String
if (string != null) {
return try {
string.toUInt()
} catch (e: Exception) {
null
}
}

return null
}

override fun asLong(data: Any?): Long? {
val jsonLiteral = data as? JsonPrimitive
if (jsonLiteral != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class TriggerOrderToastGeneratorTests {
cancelOrderPayloads = iListOf(
HumanReadableCancelOrderPayload(
subaccountNumber = 0,
clientId = 0u,
clientId = "0",
type = "TAKE_PROFIT",
orderId = "existingOrderId",
orderFlags = SHORT_TERM_ORDER_FLAGS,
Expand All @@ -153,7 +153,7 @@ class TriggerOrderToastGeneratorTests {
HumanReadablePlaceOrderPayload(
subaccountNumber = 0,
marketId = "ETH-USD",
clientId = 0u,
clientId = "0",
type = "STOP_LIMIT",
side = "buy",
price = 1000.0,
Expand Down Expand Up @@ -212,7 +212,7 @@ class TriggerOrderToastGeneratorTests {
cancelOrderPayloads = iListOf(
HumanReadableCancelOrderPayload(
subaccountNumber = 0,
clientId = 0u,
clientId = "0",
type = "TAKE_PROFIT",
orderId = "existingOrderId",
orderFlags = SHORT_TERM_ORDER_FLAGS,
Expand Down Expand Up @@ -244,7 +244,7 @@ class TriggerOrderToastGeneratorTests {
HumanReadablePlaceOrderPayload(
subaccountNumber = 0,
marketId = "ETH-USD",
clientId = 0u,
clientId = "0",
type = "TAKE_PROFIT_MARKET",
side = "buy",
price = 1000.0,
Expand Down Expand Up @@ -298,7 +298,7 @@ class TriggerOrderToastGeneratorTests {
HumanReadableCancelOrderPayload(
subaccountNumber = 0,
type = "TAKE_PROFIT",
clientId = 0u,
clientId = "0",
orderId = "existingOrderId",
orderFlags = SHORT_TERM_ORDER_FLAGS,
clobPairId = 0,
Expand Down
Loading

0 comments on commit 50ac9d4

Please sign in to comment.