Quotes

Actions

Quote Management

  • addQuote: Adds a new quote by ID.

  • removeQuote: Removes a quote by ID.

Position Management

  • removePosition: Removes a quote from the current positions.

  • addPosition: Adds a quote to the current positions.

  • setPositions: Sets the entire list of quotes as current positions.

Pending Quotes

  • addPending: Adds a quote to the list of pending quotes.

  • setPendings: Sets the entire list of pending quotes.

Quote History

  • addQuoteToHistory: Adds a quote to the history list, associated with a specific chain ID.

  • setHistory: Sets the entire list of quotes as the history for a specific chain ID.

Quote Detail

  • setQuoteDetail: Sets or updates the details of a single quote.

  • setTpSlData: Sets take profit and stop loss data for a quote.

  • addQuoteInstantCloseData: Adds instant close data for a quote.

  • updateQuoteInstantCloseStatus: Updates the status of an instant close for a quote.

Hooks

Accessor Hooks

  • useHistoryQuotes: Returns all historical quotes for the current chain ID and account, filtered and sorted.

  • usePendingsQuotes: Retrieves all pending quotes along with their state.

  • usePositionsQuotes: Fetches all quotes currently in positions along with their state.

  • useAllQuotes: Combines pending, positions, and historical quotes into a single sorted array.

  • useQuoteDetail: Accesses the detailed data for a specific quote.

  • useListenersQuotes: Retrieves an array of quote IDs that are being listened to.

  • useInstantClosesData: Accesses data related to instant closes.

  • useQuoteInstantCloseData: Fetches the instant close data for a specific quote by ID.

  • useQuotesTpSlData: Accesses the take profit and stop loss data for all quotes.

  • useLastUpdateTimestamp: Accesses the timestamp of the last notification update.

Mutator Hooks

  • useAddQuotesToListenerCallback: Returns a callback to add a quote ID to the listeners array.

  • useSetQuoteDetailCallback: Provides a callback for setting the detailed view of a quote.

  • useSetHistoryCallback: Offers a callback to set the historical quotes for a given chain ID.

  • useSetPendingsCallback: Returns a callback to set the list of pending quotes.

  • useRemoveQuotesFromListenerCallback: Provides a callback to remove a quote ID from the listeners array.

  • useAddQuoteToHistoryCallback: Returns a callback for adding a quote to the historical quotes list for a given chain ID.

  • useInstantCloseDataCallback: Provides a callback to set instant close data for a quote.

  • useUpdateInstantCloseDataCallback: Returns a callback to update the status of an instant close for a quote.

  • useGetExistedQuoteByIdsCallback: Offers a callback to find an existing quote by its ID in the combined list of all quotes.

  • useGetOrderHistoryCallback: Provides a callback to fetch the order history for a specific account and chain ID.

  • useGetOpenInstantClosesCallback: Returns a callback to fetch open instant closes.

  • useSetTpSlDataCallback: Provides a callback to set take profit and stop loss data for a quote.

Reducer

This reducer manages the state related to quotes, including their history, pending and active positions, and detailed view of a selected quote. It responds to actions that add, set, or remove quotes from various parts of the state.

State Structure

  • history: Object mapping chain IDs to arrays of quote histories.

  • pendings: Array of pending quotes.

  • positions: Array of current positions.

  • listeners: Array of quote IDs being listened to.

  • tpSlQuoteData: Object mapping quote IDs to their take profit and stop loss data.

  • quoteDetail: Detailed data for a currently selected quote.

  • historyState: Loading state for fetching quote history.

  • hasMoreHistory: Flag indicating more history is available.

  • instantClosesStates: Object mapping quote IDs to their instant close data.

  • openInstantClosesState: Loading state for fetching open instant closes.

Thunks

getHistory

Fetches a slice of historical quotes data for a given account from a subgraph, handling pagination and determining if more data is available beyond the current fetch.

Parameters

  • account: The address of the account for which historical quotes are fetched.

  • chainId: The chain ID indicating the specific blockchain network.

  • client: The Apollo client instance used for querying.

  • skip: The number of items to skip (for pagination).

  • first: The number of items to fetch on the current query.

  • ItemsPerPage: The standard number of items per page, used to detect if additional pages of data are available.

Process

  1. Validates the presence of account and chainId.

  2. Initializes the Apollo client for querying order history data specific to the given chain ID.

  3. Executes a GraphQL query to fetch historical quotes data, passing the account address and pagination parameters (first, skip).

  4. Converts the GraphQL query response into an array of Quote objects.

  5. Determines if more data is available by checking if the number of fetched items exceeds the ItemsPerPage.

Return

Returns an object containing:

  • quotes: An array of transformed Quote objects.

  • hasMore: A boolean flag indicating if additional historical data is available.

  • chainId: The chain ID for which the history was fetched.

Implementation Details

  • Utilizes GraphQL queries defined in the Apollo client setup to fetch historical data.

  • Employs a transformation function, toQuoteFromGraph, to convert subgraph data entities into application-specific Quote objects.

getInstantCloses

Fetches instant close data for a given account from a hedger, handling the request and processing the response.

  • Parameters:

    • baseUrl: The base URL of the hedger API.

    • account: The address of the account for which instant close data is fetched.

    • appName: The name of the application making the request.

  • Process:

    1. Validates the presence of baseUrl.

    2. Constructs the URL for fetching instant close data.

    3. Executes an HTTP GET request to fetch instant close data, passing necessary headers.

    4. Processes the response and extracts the relevant data.

  • Return:

    • Returns a promise that resolves to an object containing:

      • openInstantCloses: An array of instant close response data.

  • Implementation Details:

    • Uses the makeHttpRequest utility to perform the HTTP GET request.

    • Handles potential errors and throws appropriate exceptions if the request fails.

Types

QuotesState

Represents the overall state structure for managing quotes.

  • history: Maps chain IDs to arrays of quotes, storing historical quote data for different chains.

  • pendings: An array of quotes currently pending action.

  • positions: Quotes currently held in positions.

  • listeners: An array of quote IDs that are actively being listened to for updates.

  • quoteDetail: Detailed data for a specific quote, if selected.

  • historyState: The ApiState of the historical quotes fetching process.

  • hasMoreHistory: A boolean indicating if more historical quotes are available beyond the current fetched data.

  • instantClosesStates: An object mapping quote IDs to their instant close data.

  • openInstantClosesState: The ApiState for fetching open instant closes.

  • tpSlQuoteData: An object mapping quote IDs to their take profit and stop loss data.

SubGraphData

Describes the structure of data received from a GraphQL subgraph query related to quotes.

  • Includes fields for both open and close orders, partyA and partyB addresses, quote ID and status, market and symbol IDs, position types, quantities, prices, deadline, whitelist data, and initial data including CVAs, LFs, and timestamps.

  • initialData holds the initial conditions of the quote, including initial margin data and timestamps.

Updater

The Quotes Updater module consists of two main components: QuotesUpdater and UpdaterListeners. These components are responsible for fetching, updating, and listening for changes in quotes data. They leverage React hooks for side effects and state management to ensure the quotes data is current and accurately reflects the user's interactions and the application's state.

Components

QuotesUpdater

This component manages the fetching and setting of pending quotes and positions. It performs regular updates to fetch historical quotes data and updates the application state with new positions and pending quotes based on user activity and market changes.

Key Operations:

  • Fetching Historical Quotes: Periodically fetches historical quotes data for the logged-in account and updates the state.

  • Setting Positions: Updates the current positions in the application state based on fetched positions data.

  • Setting Pendings: Sets the pending quotes in the application state once all pending IDs have been fetched and processed.

UpdaterListeners

Manages the listeners for quotes changes, adding quotes to history, and removing them from listeners based on their status. It keeps track of quote statuses and updates the history and listener arrays accordingly.

Key Operations:

  • Quote Listener Updates: Removes quotes from listeners and adds them to history if their status is finalized (e.g., canceled, liquidated, expired, or closed).

  • Pending and Positions Updates: Adds or removes quotes from listeners based on changes in pending and positions data, ensuring that the listeners array is always up-to-date with the latest quote statuses.

Last updated