Skip to content

Commit

Permalink
close all positions return payload
Browse files Browse the repository at this point in the history
  • Loading branch information
aforaleka committed Sep 20, 2024
1 parent 0871947 commit c68efa0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ interface AsyncAbacusStateManagerProtocol {
fun faucet(amount: Double, callback: TransactionCallback)
fun cancelOrder(orderId: String, callback: TransactionCallback)
fun cancelAllOrders(marketId: String?, callback: TransactionCallback)
fun closeAllPositions(callback: TransactionCallback)
fun closeAllPositions(callback: TransactionCallback): HumanReadableCloseAllPositionsPayload?

// Bridge functions.
// If client is not using cancelOrder function, it should call orderCanceled function with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,13 @@ class AsyncAbacusStateManagerV2(
}
}

override fun closeAllPositions(callback: TransactionCallback) {
try {
override fun closeAllPositions(callback: TransactionCallback): HumanReadableCloseAllPositionsPayload? {
return try {
adaptor?.closeAllPositions(callback)
} catch (e: Exception) {
val error = V4TransactionErrors.error(null, e.toString())
callback(false, error, null)
null
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ internal class StateManagerAdaptorV2(
accounts.cancelAllOrders(marketId, callback)
}

internal fun closeAllPositions(callback: TransactionCallback) {
accounts.closeAllPositions(currentHeight, callback)
internal fun closeAllPositions(callback: TransactionCallback): HumanReadableCloseAllPositionsPayload? {
return accounts.closeAllPositions(currentHeight, callback)
}

internal fun orderCanceled(orderId: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,8 @@ internal fun AccountSupervisor.cancelAllOrders(marketId: String?, callback: Tran
subaccount?.cancelAllOrders(marketId, callback)
}

internal fun AccountSupervisor.closeAllPositions(currentHeight: Int?, callback: TransactionCallback) {
subaccount?.closeAllPositions(currentHeight, callback)
internal fun AccountSupervisor.closeAllPositions(currentHeight: Int?, callback: TransactionCallback): HumanReadableCloseAllPositionsPayload? {
return subaccount?.closeAllPositions(currentHeight, callback)
}

internal fun AccountSupervisor.orderCanceled(orderId: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ internal fun AccountsSupervisor.cancelAllOrders(marketId: String?, callback: Tra
account?.cancelAllOrders(marketId, callback)
}

internal fun AccountsSupervisor.closeAllPositions(currentHeight: Int?, callback: TransactionCallback) {
account?.closeAllPositions(currentHeight, callback)
internal fun AccountsSupervisor.closeAllPositions(currentHeight: Int?, callback: TransactionCallback): HumanReadableCloseAllPositionsPayload? {
return account?.closeAllPositions(currentHeight, callback)
}

internal fun AccountsSupervisor.orderCanceled(orderId: String) {
Expand Down

0 comments on commit c68efa0

Please sign in to comment.