Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making percentDiff 0..100 instead of 0..1 for TP/SL #296

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/SpotlessCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: SpotlessCheck

on:
pull_request:
paths:
- '**/*.kt'

jobs:
spotlessCheck:
runs-on: macos-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'

- name: Lint Kotlin Files
run: |
./gradlew spotlessCheck
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.6.35"
version = "1.6.36"

repositories {
google()
Expand Down
4 changes: 2 additions & 2 deletions integration/iOS/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ EXTERNAL SOURCES:
:path: "~/v4-abacus"

SPEC CHECKSUMS:
abacus: a57d55b0ca0d3514389573a87c47507f88eb6b0a
abacus: 46f62be6dc9b3f888093eb2c9952d0267ab40670
CryptoSwift: 562f8eceb40e80796fffc668b0cad9313284cfa6

PODFILE CHECKSUM: 37d72c15b180e62a4c42b8fb41b4836c89aa63c9

COCOAPODS: 1.12.1
COCOAPODS: 1.15.2
1 change: 1 addition & 0 deletions integration/iOS/Pods/Local Podspecs/abacus.podspec.json

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

4 changes: 2 additions & 2 deletions integration/iOS/Pods/Manifest.lock

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

214 changes: 117 additions & 97 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.

Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,14 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco
// Just in case it has more than one market, we will create
// two separate pending positions.

val mergedOrders = ParsingHelper.merge(parser.asNativeMap(
parser.value(parentSubaccount, "orders"),
), parser.asNativeMap(
parser.value(childSubaccount, "orders"),
))
val mergedOrders = ParsingHelper.merge(
parser.asNativeMap(
parser.value(parentSubaccount, "orders"),
),
parser.asNativeMap(
parser.value(childSubaccount, "orders"),
),
)

val modifiedParentSubaccount = parentSubaccount.toMutableMap()
modifiedParentSubaccount.safeSet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ internal class TriggerOrdersInputCalculator(val parser: ParserProtocol) {
if (entryPrice != null) {
val triggerPrice = parser.asDouble(parser.value(modified, "triggerPrice"))
val usdcDiff = parser.asDouble(parser.value(modified, "usdcDiff"))
val percentDiff = parser.asDouble(parser.value(modified, "percentDiff"))
val percentDiff = parser.asDouble(parser.value(modified, "percentDiff"))?.let { it / 100.0 }

when (inputType) {
"stopLossOrder.price.triggerPrice" -> {
Expand All @@ -118,8 +118,8 @@ internal class TriggerOrdersInputCalculator(val parser: ParserProtocol) {
modified.safeSet(
"percentDiff",
when (positionSide) {
"long" -> leverage.times(size.times(entryPrice.minus(triggerPrice))).div(notionalTotal)
"short" -> leverage.times(size.times(triggerPrice.minus(entryPrice))).div(notionalTotal)
"long" -> leverage.times(size.times(entryPrice.minus(triggerPrice))).div(notionalTotal).times(100)
"short" -> leverage.times(size.times(triggerPrice.minus(entryPrice))).div(notionalTotal).times(100)
else -> null
},
)
Expand All @@ -138,8 +138,8 @@ internal class TriggerOrdersInputCalculator(val parser: ParserProtocol) {
modified.safeSet(
"percentDiff",
when (positionSide) {
"long" -> leverage.times(size.times(triggerPrice.minus(entryPrice))).div(notionalTotal)
"short" -> leverage.times(size.times(entryPrice.minus(triggerPrice))).div(notionalTotal)
"long" -> leverage.times(size.times(triggerPrice.minus(entryPrice))).div(notionalTotal).times(100)
"short" -> leverage.times(size.times(entryPrice.minus(triggerPrice))).div(notionalTotal).times(100)
else -> null
},
)
Expand All @@ -157,7 +157,7 @@ internal class TriggerOrdersInputCalculator(val parser: ParserProtocol) {
)
modified.safeSet(
"percentDiff",
leverage.times(usdcDiff).div(notionalTotal),
leverage.times(usdcDiff).div(notionalTotal).times(100),
)
}
}
Expand All @@ -173,7 +173,7 @@ internal class TriggerOrdersInputCalculator(val parser: ParserProtocol) {
)
modified.safeSet(
"percentDiff",
leverage.times(usdcDiff).div(notionalTotal),
leverage.times(usdcDiff).div(notionalTotal).times(100),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ data class SubaccountOrder(
Logger.d { "creating Account Order\n" }
data?.let {
// TODO: Remove default to 0 for subaccountNumber once new indexer response is consumed. Prevents breaking change
val subaccountNumber = parser.asInt(data["subaccountNumber"])?: 0
val subaccountNumber = parser.asInt(data["subaccountNumber"]) ?: 0
val id = parser.asString(data["id"])
val clientId = parser.asInt(data["clientId"])
val marketId = parser.asString(data["marketId"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package exchange.dydx.abacus.state.manager

import exchange.dydx.abacus.output.*
import exchange.dydx.abacus.output.Compliance
import exchange.dydx.abacus.output.ComplianceStatus
import exchange.dydx.abacus.output.Notification
import exchange.dydx.abacus.output.PerpetualState
import exchange.dydx.abacus.output.Restriction
import exchange.dydx.abacus.output.SubaccountOrder
import exchange.dydx.abacus.output.TransferRecordType
import exchange.dydx.abacus.output.UsageRestriction
import exchange.dydx.abacus.output.input.OrderType
import exchange.dydx.abacus.output.input.TradeInputGoodUntil
import exchange.dydx.abacus.output.input.TriggerOrder
Expand Down Expand Up @@ -1965,9 +1972,13 @@ open class StateManagerAdaptor(
val currentHeight = calculateCurrentHeight()

val goodTilBlock =
if (isShortTermOrder(trade.type.rawValue, trade.timeInForce)) currentHeight?.plus(
SHORT_TERM_ORDER_DURATION
) else null
if (isShortTermOrder(trade.type.rawValue, trade.timeInForce)) {
currentHeight?.plus(
SHORT_TERM_ORDER_DURATION,
)
} else {
null
}

return HumanReadablePlaceOrderPayload(
subaccountNumber,
Expand Down Expand Up @@ -2034,7 +2045,7 @@ open class StateManagerAdaptor(
timeInForce,
execution,
goodTilTimeInSeconds,
goodTilBlock
goodTilBlock,
)
}

Expand Down Expand Up @@ -2387,10 +2398,8 @@ open class StateManagerAdaptor(
}

open fun complianceCheck() {

}


open fun complianceScreen(address: String) {
val url = complianceScreenUrl(address)
if (url != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package exchange.dydx.abacus.state.manager

import exchange.dydx.abacus.output.UsageRestriction
import exchange.dydx.abacus.output.input.OrderTimeInForce
import exchange.dydx.abacus.output.input.TransferType
import exchange.dydx.abacus.protocols.AnalyticsEvent
import exchange.dydx.abacus.protocols.DataNotificationProtocol
Expand Down Expand Up @@ -150,9 +149,6 @@ class V4StateManagerAdaptor(
}
}

@Suppress("PropertyName")
private val MAX_NUM_BLOCK_DELAY = 15

private var lastValidatorCallTime: Instant? = null

override fun didSetSocketConnected(socketConnected: Boolean) {
Expand Down Expand Up @@ -991,7 +987,7 @@ class V4StateManagerAdaptor(
transactionType,
transactionPayloadString,
transactionCallback,
onSubmitTransaction
onSubmitTransaction,
),
)
} else {
Expand Down Expand Up @@ -1022,8 +1018,8 @@ class V4StateManagerAdaptor(
PlaceOrderRecord(
subaccountNumber,
clientId,
submitTimeMs
)
submitTimeMs,
),
)
}
},
Expand All @@ -1042,10 +1038,14 @@ class V4StateManagerAdaptor(
send(
error,
callback,
if (isTriggerOrder) HumanReadableTriggerOrdersPayload(
listOf(payload),
emptyList(),
) else payload
if (isTriggerOrder) {
HumanReadableTriggerOrdersPayload(
listOf(payload),
emptyList(),
)
} else {
payload
},
)
},
useTransactionQueue = !isShortTermOrder(payload.type, payload.timeInForce),
Expand Down Expand Up @@ -1099,10 +1099,14 @@ class V4StateManagerAdaptor(
send(
error,
callback,
if (isTriggerOrder) HumanReadableTriggerOrdersPayload(
emptyList(),
listOf(payload),
) else payload
if (isTriggerOrder) {
HumanReadableTriggerOrdersPayload(
emptyList(),
listOf(payload),
)
} else {
payload
},
)
},
useTransactionQueue = !isShortTermOrder,
Expand All @@ -1116,7 +1120,7 @@ class V4StateManagerAdaptor(
val uiClickTimeMs = Clock.System.now().toEpochMilliseconds().toDouble()
tracking(
if (isCancel) AnalyticsEvent.TradeCancelOrderClick.rawValue else AnalyticsEvent.TradePlaceOrderClick.rawValue,
analyticsPayload
analyticsPayload,
)
return uiClickTimeMs
}
Expand Down Expand Up @@ -1186,7 +1190,7 @@ class V4StateManagerAdaptor(
val analyticsPayload = analyticsUtils.formatPlaceOrderPayload(
it,
isClosePosition = false,
fromSlTpDialog = true
fromSlTpDialog = true,
)
submitPlaceOrder(callback, it, analyticsPayload, true)
}
Expand Down Expand Up @@ -1632,4 +1636,9 @@ class V4StateManagerAdaptor(
accountBalancesTimer?.cancel()
accountBalancesTimer = null
}

companion object {
@Suppress("PropertyName")
private const val MAX_NUM_BLOCK_DELAY = 15
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import kotlinx.serialization.Serializable

@JsExport
class AppConfigs(
val subscribeToCandles: Boolean,
val loadRemote: Boolean = true,
val enableLogger: Boolean = false,
var subscribeToCandles: Boolean,
var loadRemote: Boolean = true,
var enableLogger: Boolean = false,
) {
enum class SquidVersion {
V1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ class AppConfigsV2(
val systemConfigs: SystemConfigs,
val marketConfigs: MarketsConfigs,
val accountConfigs: AccountConfigs,
val onboardingConfigs: OnboardingConfigs,
val loadRemote: Boolean = true,
val enableLogger: Boolean = false,
var onboardingConfigs: OnboardingConfigs,
var loadRemote: Boolean = true,
var enableLogger: Boolean = false,
) {
companion object {
val forApp = AppConfigsV2(
Expand Down
Loading
Loading