Hedger
Actions
updateWebSocketStatus
Updates the status of the WebSocket connection.updateHedgerId
Sets or updates the current hedger identifier.updatePrices
Updates the price information for various markets.updateDepths
Refreshes the depth information across multiple markets.updateDepth
Updates the depth information for a specific market.updateNotionalCap
Modifies the notional cap values applicable to markets.updateFundingRates
Updates funding rates for different markets.
Custom Hooks
Market and WebSocket Status Hooks
useMarketsStatus
: Retrieves theApiState
of market data.useOpenInterestStatus
: Accesses theApiState
for open interest data.
ApiState
outline:
useWebSocketStatus
: Fetches the current status of the WebSocket connection.
WebSocket Connection Management
useSetWebSocketStatus
: A hook to update the WebSocket connection status.
Hedger Information and Configuration
useHedgerInfo
: Gathers hedger information, including address and WebSocket URL, based on the active chain ID.useWebSocketUrl
: Retrieves the WebSocket URL for the current hedger.
Market Data Accessors
useMarkets
: Accesses the list of markets.useErrorMessages
: Retrieves any error messages related to hedger operations.useMarketNotionalCap
: Fetches market notional cap values and their status.useMarketOpenInterest
: Accesses open interest data for markets.usePrices
: Retrieves current prices for markets.useMarketPriceRange
: Gets the acceptable limit order price range from a hedger for a market.useMarketData
: Fetches market data for a specific market name.useFundingRateData
: Accesses funding rate data for a specific market.useMarketDepth
: Retrieves market depth data for a given market name.
State Updaters
useSetPrices
: Updates market prices in the state.useSetFundingRates
: Updates funding rates for markets in the state.useSetDepth
: Updates the market depth for a specific market.useSetNotionalCap
: Updates notional cap values in the state.
Thunks
Thunks in the hedger state management facilitate asynchronous interactions with hedger-related APIs, handling data fetching and state updating processes.
getMarkets
Fetches all market data including symbols and error codes from the specifiedhedgerUrl
.getOpenInterest
Retrieves open interest data for a given multi-account address from the hedger API.getNotionalCap
Obtains notional cap information for a specific market and multi-account address.getPriceRange
Fetches the price range for a given market, providing minimum and maximum price values.getMarketsDepth
Retrieves depth information for markets, detailing the best ask and bid prices and quantities. This information comes from the Binance API.getMarketsInfo
Fetches additional market information including price changes, trade volume, and notional cap for each market.getFundingRate
Collects funding rate information for specified markets.getPaidAmount
Queries the paid amount of funding for a given quote ID, utilizing the Apollo client with GraphQL.
Types
types.ts
is used for managing and representing hedger-related data within the state.
MarketData
: Represents detailed information about a market, including funding rate, mark price, and index price.
MarketDepthData
: Contains data about the best ask and bid prices and quantities for a market.
FundingRateData
: Details the next funding rate and time for both long and short positions.
PriceResponse
: Defines the structure for a price response.
r
: The funding rate.T
: The next funding time.p
: The mark price.s
: The symbol.i
: The index price.
Response and Mapping Types
DepthResponse
: Represents depth information for a market, including prices, quantities, and the symbol.MarketDataMap
: A mapping of market symbols to their respectiveMarketData
.MarketDepthMap
: Maps market symbols to theirMarketDepthData
.FundingRateMap
: A mapping of market symbols toFundingRateData
.
Market Types
MarketNotionalCap
: Stores the used and total notional cap for a market.PriceRange
: Represents the minimum and maximum price for a market.MarketsInfo
: A mapping of market names to their information, including price, change percent, trade volume, and notional cap.ErrorMessages
: Maps error codes to their corresponding error messages.
Market Information Response Types
MarketInfoValue
: Contains market information such as price, change percent, trade volume, and notional cap.MarketsInfoRes
: A response type mapping market names to theirMarketInfoValue
.FundingRateRes
: A response type for funding rate data.
Hedger State
HedgerState
: Defines the overall state structure for hedger data, including ID, prices, market depths, market listings, funding rates, open interest data, WebSocket status, and error messages.
Reducer
Initializes with a default state specifying all the necessary hedger data fields, including prices, depths, markets, and statuses.
Actions Handled
updateWebSocketStatus
: Updates the status of the WebSocket connection.updateHedgerId
: Sets the current hedger id.updatePrices
: Merges new market prices into the existing state.updateDepth
: Updates depth information for a specific market.updateDepths
: Merges new market depths into the existing state.updateNotionalCap
: Sets the notional cap information for the market.updateFundingRates
: Merges new funding rates into the existing state.
Thunks Handled
getMarkets
: Manages the loading, success, and failure states for fetching market data.getMarketsDepth
: Updates market depths on successful fetch or clears on failure.getOpenInterest
: Manages the loading, success, and failure states for fetching open interest data.getNotionalCap
: Handles the loading, success, and failure states for notional cap fetches.getPriceRange
: Manages the loading, success, and failure states for fetching market price ranges.
State Updates
Updates are performed carefully to ensure immutability of the state. Utilizes the
current
function from Redux Toolkit for safe state mutations.Error handling is incorporated directly within the reducer for thunks, logging errors and setting relevant state upon failures.
Loading states are managed for asynchronous operations to provide feedback within the UI.
Last updated