Hedger
Actions
updateWebSocketStatusUpdates the status of the WebSocket connection.updateHedgerIdSets or updates the current hedger identifier.updatePricesUpdates the price information for various markets.updateDepthsRefreshes the depth information across multiple markets.updateDepthUpdates the depth information for a specific market.updateNotionalCapModifies the notional cap values applicable to markets.updateFundingRatesUpdates funding rates for different markets.
Custom Hooks
Market and WebSocket Status Hooks
useMarketsStatus: Retrieves theApiStateof market data.useOpenInterestStatus: Accesses theApiStatefor open interest data.
ApiState outline:
export enum ApiState {
OK = "OK",
LOADING = "LOADING",
ERROR = "ERROR",
}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.
getMarketsFetches all market data including symbols and error codes from the specifiedhedgerUrl.getOpenInterestRetrieves open interest data for a given multi-account address from the hedger API.getNotionalCapObtains notional cap information for a specific market and multi-account address.getPriceRangeFetches the price range for a given market, providing minimum and maximum price values.getMarketsDepthRetrieves depth information for markets, detailing the best ask and bid prices and quantities. This information comes from the Binance API.getMarketsInfoFetches additional market information including price changes, trade volume, and notional cap for each market.getFundingRateCollects funding rate information for specified markets.getPaidAmountQueries 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.
export interface MarketData {
fundingRate: string;
nextFundingTime: number;
markPrice: string;
indexPrice: string;
}MarketDepthData: Contains data about the best ask and bid prices and quantities for a market.
export interface MarketDepthData {
bestAskPrice: string;
bestAskQuantity: string;
bestBidPrice: string;
bestBidQuantity: string;
}FundingRateData: Details the next funding rate and time for both long and short positions.
export interface FundingRateData {
next_funding_time: number;
next_funding_rate_long: string;
next_funding_rate_short: string;
}PriceResponse: Defines the structure for a price response.
export interface PriceResponse {
r: string;
T: number;
p: string;
s: string;
i: string;
}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.
export interface HedgerState {
hedgerId: string | number | undefined;
prices: MarketDataMap; // load from hedger socket
depths: MarketDepthMap;
markets: Market[]; //load from hedger api
fundingRates: FundingRateMap;
openInterest: OpenInterest;
webSocketStatus: ConnectionStatus;
marketsStatus: ApiState;
marketNotionalCap: MarketNotionalCap;
marketNotionalCapStatus: ApiState;
openInterestStatus: ApiState;
priceRange: PriceRange;
priceRangeStatus: ApiState;
errorMessages: ErrorMessages;
}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
currentfunction 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