When user select a market or position, FE app should call
appStateMachine.setMarket(marketId)
This will retrieve the following data for this market:
prices
trades
orderbook
Then call the trade(...)
function to make trade the current input.
fun trade(data: String?, type: TradeInputField?): AppStateResponse
All trading params are set up using the same function, but with different types.
When user brings up the trade input panel, use trade(null, null)
to make it the active input, without changing data.
Process the response like any other AppStateResponse.
The input state is in response.state.input.trade
as a TradeInput.
Data input in string format
An enum specifying the type of trade input
Order type
Order side
Size of the order
USDC amount of the order
Leverage of the order
Limit price
Trigger/stop price
Trailing percent for Trailing Stop order
TimeInForce
Numeric duration of GoodTil
Time unit of the GoodTil
Execution option
Whether the order is reduce-only
Whether the order is post-only
Bracket order stop loss price
Bracket order stop loss percentage
Whether the stop loss bracket order is reduce only
Bracket order take profit price
Bracket order take profit percentage
Whether the take profit bracket order is reduce only
Bracket orders goodTil numeric duration
Bracket order goodTil time unit
Bracket order execution option
fun closePosition(data: String?, type: ClosePositionInputField?): AppStateResponse
All closePosition params are set up using the same function, but with different types.
Process the response like any other AppStateResponse.
The input state is in response.state.input.closePosition
as a ClosePositionInput.
Data input in string format
The market ID of the position to be closed
Size of the order
Percent of the order relative to the position size. If the user directly edited size
, percent
is cleared
fun transfer(data: String?, type: TransferInputField?): AppStateResponse
All transfer params are set up using the same function, but with different types.
Process the response like any other AppStateResponse.
The input state is in response.state.input.transfer
as a TransferInput.
Data input in string format
Amount in USDC
Fee in USDC
Address input, used for transfer
Option to use fastSpeed, used by v3 withdrawal
fun triggerOrders(data: String?, TriggerOrdersInputField?): AppStateResponse
All trigger order params are set up using the same function, but with different types.
Process the response like any other AppStateResponse.
The input state is in response.state.input.triggerOrders
as a TriggerOrdersInput.
Data input in string format
Size to apply to stop loss and take profit order.
Stop loss order type
Stop loss order limit price
Stop loss order trigger price
Stop loss order trigger price's percentage difference from the position's average entry price
Stop loss order trigger price's usdc difference from the position's average entry price
Take profit order type
Take profit order limit price
Take profit order trigger price
Take profit order trigger price's percentage difference from the position's average entry price
Take profit order trigger price's usdc difference from the position's average entry price
fun adjustIsolatedMargin(data: String?, type: AdjustIsolatedMarginInputField?): AppStateResponse
The input state is in response.state.input.adjustIsolatedMargin
as a AdjustIsolatedMarginInput.
Data input in string format
IsolatedMarginAdjustmentType Add - Add margin to the child's isolated margin account from the parent's cross margin account Remove - Remove margin from the child's isolated margin account to the parent's cross margin account
Amount of USDC to remove or add
Subaccount number for the child whose margin is to be adjusted