Raindex SDK Documentation
    Preparing search index...

    Class RaindexOrder

    A single order representation within a given orderbook.

    RaindexOrder represents a trading order on a specific blockchain with its associated input and output vaults, metadata, and performance tracking capabilities. Each order is deployed on a specific orderbook contract and can be queried for volume and performance metrics over time.

    The order contains both the raw order data (bytes and hash) and structured access to its vaults, which define what tokens can be traded and their current balances.

    Index

    Properties

    active: boolean
    chainId: number
    dotrainGuiState: undefined | string
    dotrainSource: undefined | string
    id: `0x${string}`
    inputsList: RaindexVaultsList
    inputsOutputsList: RaindexVaultsList
    meta: undefined | `0x${string}`
    oracleUrl: undefined | string

    Returns the signed context oracle URL if this order has oracle metadata.

    orderbook: `0x${string}`
    orderBytes: `0x${string}`
    orderHash: `0x${string}`
    outputsList: RaindexVaultsList
    owner: `0x${string}`
    parsedMeta: ParsedMeta[]
    rainlang: undefined | string
    timestampAdded: bigint
    tradesCount: number
    transaction: undefined | RaindexTransaction
    vaultsList: RaindexVaultsList

    Methods

    • Converts the order from RaindexOrder to an SgOrder type

      const sgOrder = await order.convertToSgOrder();
      // Do something with sgOrder

      Returns WasmEncodedResult<SgOrder>

      Order as SgOrder type

    • Returns void

    • Executes quotes directly from complete order objects without additional data fetching

      This function performs quote calculations using complete order data structures that typically come from previous subgraph queries. It generates quotes for all possible input/output token pairs within each order, providing comprehensive trading information without requiring additional network calls for order data.

      const result = await getOrderQuote();
      if (result.error) {
      console.error("Error:", result.error.readableMsg);
      return;
      }
      const quoteResponses = result.value;
      // Do something with the quoteResponses

      Parameters

      • OptionalblockNumber: null | bigint

        Optional specific block number for historical quotes (uses latest if None)

      • OptionalchunkSize: null | number

        Optional quote chunk size override (defaults to 16)

      Returns Promise<WasmEncodedResult<RaindexOrderQuote[]>>

      List of batch quote responses with trading pair information

    • Generates ABI-encoded calldata for the removeOrder2() function on the orderbook contract

      Takes an existing order from the subgraph and creates the transaction calldata needed to remove it from the orderbook. The order must be active and owned by the caller.

      // Generate calldata for removing an order
      const result = await order.getRemoveCalldata();
      if (result.error) {
      console.error('Failed:', result.error.readableMsg);
      } else {
      const calldata = result.value;
      // Do something with the calldata
      }

      Returns WasmEncodedResult<`0x${string}`>

      ABI-encoded calldata ready for blockchain submission

    • Generates calldata for IOrderBookV6.takeOrders4 targeting this specific order.

      Unlike getTakeOrdersCalldata on RaindexClient which discovers orders from the subgraph, this method generates calldata for taking this single known order that the user has already selected. The method fetches a fresh quote at execution time using the provided pair indices.

      This method includes preflight simulation to validate the transaction will succeed.

      Parameters:

      • inputIndex: Index of the input token in the order's validInputs array
      • outputIndex: Index of the output token in the order's validOutputs array
      • taker: Address of the account that will execute the takeOrders transaction
      • mode: One of buyExact, buyUpTo, spendExact, or spendUpTo
      • amount: Target amount (output tokens for buy modes, input tokens for spend modes)
      • priceCap: human-readable decimal string for max sell per 1 buy

      Returns calldata plus pricing info:

      • calldata: ABI-encoded bytes for takeOrders4.
      • effectivePrice: expected blended sell per 1 buy from the simulation.
      • prices: per-leg ratios (single entry for this order).
      • expectedSell: simulated sell at current quotes.
      • maxSellCap: worst-case on-chain spend cap.
      const res = await order.getTakeCalldata(
      0, // inputIndex
      0, // outputIndex
      "0xTAKER...",
      "buyUpTo",
      "10",
      "1.2",
      );
      if (res.error) {
      console.error(res.error.readableMsg);
      } else {
      const { calldata, effectivePrice, expectedSell, maxSellCap, prices, orderbook } = res.value;
      }

      Parameters

      • inputIndex: number

        Index of the input token in the order's validInputs array

      • outputIndex: number

        Index of the output token in the order's validOutputs array

      • taker: string

        Address of the taker account

      • mode: TakeOrdersMode

        Take orders mode: buyExact, buyUpTo, spendExact, or spendUpTo

      • amount: string

        Target amount as decimal string

      • priceCap: string

        Maximum price cap as decimal string

      Returns Promise<WasmEncodedResult<TakeOrdersCalldataResult>>

      Encoded takeOrders4 calldata and price information for this order

    • Counts total trades for an order within a time range

      Efficiently counts the total number of trades executed by an order without fetching all trade details.

      const result = await order.getTradeCount();
      if (result.error) {
      console.error("Cannot count trades:", result.error.readableMsg);
      return;
      }
      const count = result.value;
      // Do something with the count

      Parameters

      • OptionalstartTimestamp: null | bigint

        Optional start time filter (Unix timestamp in seconds)

      • OptionalendTimestamp: null | bigint

        Optional end time filter (Unix timestamp in seconds)

      Returns Promise<WasmEncodedResult<number>>

      Total trade count as number

    • Fetches detailed information for a specific trade

      Retrieves complete information about a single trade including vault changes and transaction details.

      const result = await order.getTradeDetail("0x1234567890abcdef1234567890abcdef12345678");
      if (result.error) {
      console.error("Trade not found:", result.error.readableMsg);
      return;
      }
      const trade = result.value;
      // Do something with the trade

      Parameters

      • tradeId: `0x${string}`

        Unique trade identifier

      Returns Promise<WasmEncodedResult<RaindexTrade>>

      Complete trade information

    • Fetches trade history with optional time filtering

      Retrieves a chronological list of trades executed by an order within an optional time range.

      const result = await order.getTradesList();
      if (result.error) {
      console.error("Cannot fetch trades:", result.error.readableMsg);
      return;
      }
      const trades = result.value;
      // Do something with the trades

      Parameters

      • OptionalstartTimestamp: null | bigint

        Optional start time filter (Unix timestamp in seconds)

      • OptionalendTimestamp: null | bigint

        Optional end time filter (Unix timestamp in seconds)

      • Optionalpage: null | number

        Optional page number (defaults to 1)

      Returns Promise<WasmEncodedResult<RaindexTrade[]>>

      Array of trade records with complete details

    • Parameters

      • OptionalstartTimestamp: null | bigint

        Unix timestamp for the start of the query period (optional)

      • OptionalendTimestamp: null | bigint

        Unix timestamp for the end of the query period (optional)

      Returns Promise<WasmEncodedResult<RaindexVaultVolume[]>>

      Volume data for each vault over the specified period