Trade

Actions

Trade Configuration Management

  • setTradeState: Sets the entire trade state based on the provided TradeState object.

  • updateMarketId: Updates the market ID in the trade state.

  • updateOrderType: Sets the order type (e.g., Market or Limit) for the trade.

  • updateInputField: Updates specific input fields (e.g., quantity, leverage) related to the trade.

  • updateLimitPrice: Sets the limit price for the trade, applicable in Limit order types.

  • updateTypedValue: Updates the value typed into an input field.

  • updatePositionType: Sets the position type (e.g., Long or Short) for the trade.

  • updateLockedPercentages: Updates the percentages for various locked values in the trade (e.g., CVA,MM contributions).

  • updateTpSl: Updates the TP/SL state.

  • setTpSlOpened: Sets whether the TP/SL panel is opened.

  • setTpSlConfig: Sets the TP/SL configuration parameters.

  • updateDelegateTpSl: Updates the delegate TP/SL status.

  • updateTpSlState: Updates the TP/SL process state.

  • updateTpError: Updates the TP error message.

  • updateSlError: Updates the SL error message.

Hooks

Active Market and Trade Configuration

  • useActiveMarketId: Retrieves the currently selected market ID from the trade state.

  • useActiveMarket: Fetches the active market details based on the active market ID.

  • useActiveMarketPrice: Calculates the active market price using market data and the selected market's price precision.

Trade State Management

  • usePositionType: Accesses the position type in the trade state.

  • useOrderType: Accesses the order type in the trade state.

  • useTypedValue: Accesses the typed value in the trade state.

  • useInputField: Accesses the active input field in the trade state.

  • useLimitPrice: Retrieves the limit price set for a limit order.

  • useTradeTpSl: Fetches the TP/SL state.

  • useTradeTpSlError: Fetches the TP/SL error messages.

  • useTpSlDelegate: Fetches the delegate TP/SL status.

  • useTpSlOpened: Fetches the TP/SL opened status.

  • useTpSlConfigParams: Fetches the TP/SL configuration parameters.

Setting Trade Configuration

  • useSetOrderType: Provides a callback to update the order type in the trade state.

  • useSetInputField: Provides a callback to update the active input field in the trade state.

  • useSetPositionType: Provides a callback to update the position type in the trade state.

  • useSetLimitPrice: Provides a callback to set the limit price.

  • useSetTypedValue: Provides a callback to set the typed value and active input field.

  • useSetMarketId: Provides a callback to update the active market ID in the trade state.

  • useGetLockedPercentages: Provides a callback function to fetch and set locked percentages based on the selected leverage and market.

Reducer

Defines a reducer for managing the trade configuration state in the application. This state includes details such as the selected market ID, input fields, order type, position type, and other parameters relevant to executing trades.

State Structure

  • TradeState encapsulates:

    • marketId: The currently selected market ID for the trade.

    • inputField: The active input field in the trade form.

    • orderType: The type of order being placed (Limit or Market).

    • positionType: The position type (Long or Short).

    • limitPrice: The limit price for Limit orders.

    • typedValue: The value typed into the active input field.

    • cva, partyAmm, partyBmm, lf: Percentages for various locked values in the trade.

    • tpSlOpened: A flag indicating if TP/SL is opened.

    • tpSl: The TP/SL state.

    • tpSlError: The TP/SL error state.

    • tpSlDelegateChecker: The TP/SL delegate checker state.

    • tpSlConfig: The TP/SL configuration parameters.

Types

TradeState

Represents the current configuration of a trade, including market selection, order details, and risk management settings.

  • marketId: The market id.

  • inputField: Specifies the active input field in the trade form (Price, Quantity).

  • orderType: Type of the order being placed, such as Market or Limit.

  • positionType: Indicates whether the trade is a Long or Short position.

  • limitPrice: The limit price for Limit orders, as a string to accommodate large or precise values.

  • typedValue: The current value typed into the active input field.

  • cva, partyAmm, partyBmm, lf: Strings representing locked percentages for various trade-related values. Undefined if not applicable.

  • tpSlOpened: Boolean indicating whether TP/SL is opened.

  • tpSl: The TP/SL state.

  • tpSlError: The TP/SL error state.

  • tpSlDelegateChecker: Boolean indicating whether TP/SL delegation is enabled.

  • tpSlConfig: The TP/SL configuration parameters.

GetLockedParamUrlResponse

Structure of the response from a hedger API endpoint providing locked parameter values for a trade. These parameters are modulated by the user's leverage.

  • cva: Locked percentage for the Credit Value Adjustment.

  • partyAmm: Locked percentage for the party A maintenance margin.

  • partyBmm: Locked percentage for the party BMM (Bilateral Market Maker) contributions.

  • lf: Locked percentage for the Liquidation Fee.

TpSlState

Represents the Take Profit and Stop Loss (TP/SL) state for a trade.

  • tp: The take profit price.

  • sl: The stop loss price.

  • state: The TP/SL process state.

  • quoteId: The quote ID associated with the TP/SL.

  • lastTimeUpdated: Timestamp of the last update.

  • tpSlippage: The TP slippage value.

  • slSlippage: The SL slippage value.

TpSlError

Represents the TP/SL error state.

  • tpError: The take profit error message.

  • slError: The stop loss error message.

TpSlConfigParams

Represents the configuration parameters for TP/SL.

  • state: The TP/SL configuration state.

  • MaxRequestTimeDeltaSeconds: Maximum request time delta in seconds.

  • MinPriceDistancePercent: Minimum price distance percentage.

  • MinProfitStopLossSpreadPercent: Minimum profit stop loss spread percentage.

  • MaxActiveOrdersPerUser: Maximum active orders per user.

TpSlConfigState

Enumeration representing the TP/SL configuration state.

  • VALID: The configuration is valid.

  • LOADING: The configuration is loading.

  • NOT_VALID: The configuration is not valid.

TpSlProcessState

Enumeration representing the TP/SL process state.

  • INITIALIZE: Initial state.

  • WAIT_FOR_QUOTE_RECEIVE: Waiting for quote receive.

  • WAIT_FOR_SEND_TP_SL_REQUEST: Waiting to send TP/SL request.

  • TP_SL_REQUEST_SENDED: TP/SL request sent.

TpSlUpdateProcessState

Represents the TP/SL update process state.

  • state: The TP/SL process state.

  • lastTimeUpdated: Timestamp of the last update.

Last updated