Raindex SDK Documentation
    Preparing search index...

    Class DotrainOrder

    DotrainOrder represents a parsed and validated dotrain configuration that combines YAML frontmatter with Rainlang code for orderbook operations.

    A dotrain file contains:

    • YAML frontmatter defining networks, tokens, orders, scenarios, and deployments
    • Rainlang code sections for order evaluation logic

    This struct provides methods to compose scenarios and deployments into Rainlang code with scenario-specific bindings applied.

    Examples

    // Create from dotrain text
    const result = await DotrainOrder.create(dotrainText);
    if (result.error) {
    console.error('Failed:', result.error.readableMsg);
    } else {
    const dotrainOrder = result.value;
    // Do something with the dotrainOrder
    }

    // Compile scenario to Rainlang
    const result = await dotrainOrder.composeScenarioToRainlang("my-scenario");
    if (result.error) {
    console.error('Failed:', result.error.readableMsg);
    } else {
    const rainlang = result.value;
    // Do something with the rainlang
    }
    Index

    Methods

    • Composes a specific deployment configuration into Rainlang code.

      A deployment combines an order definition with a scenario to create a complete configuration ready for deployment. This method resolves the deployment's scenario and composes the Rainlang code with the appropriate bindings.

      // Compose a production deployment
      const result = await dotrainOrder.composeDeploymentToRainlang("production");
      if (result.error) {
      console.error('Failed:', result.error.readableMsg);
      } else {
      const rainlang = result.value;
      // Do something with the rainlang
      }

      Parameters

      • deployment: string

        Name of the deployment defined in the dotrain YAML frontmatter

      Returns Promise<WasmEncodedResult<string>>

      Composed Rainlang code for the deployment's scenario

    • Composes handle-add-order entrypoint for a specific scenario into Rainlang code for immediate execution after an order is added.

      This is useful for scenarios that need to perform actions immediately after an order is added.

      const result = await dotrainOrder.composeScenarioToPostTaskRainlang("scenario");
      if (result.error) {
      console.error('Failed:', result.error.readableMsg);
      } else {
      const postTaskCode = result.value;
      // Do something with the postTaskCode
      }

      Parameters

      • scenario: string

        Name of the scenario defined in the dotrain YAML frontmatter

      Returns Promise<WasmEncodedResult<string>>

      Composed handle-add-order Rainlang code with scenario bindings applied

    • Composes a specific scenario into Rainlang code.

      Takes a scenario name from the dotrain configuration and composes the Rainlang code with that scenario's bindings applied.

      // Compile a trading scenario
      const result = await dotrainOrder.composeScenarioToRainlang("market-making");
      if (result.error) {
      console.error('Failed:', result.error.readableMsg);
      } else {
      const rainlang = result.value;
      // Do something with the rainlang
      }

      Parameters

      • scenario: string

        Name of the scenario defined in the dotrain YAML frontmatter

      Returns Promise<WasmEncodedResult<string>>

      Composed Rainlang code with scenario bindings applied

    • Returns the original dotrain text used to create this DotrainOrder instance.

      const result = dotrainOrder.dotrain();
      if (result.error) {
      console.error('Failed:', result.error.readableMsg);
      } else {
      const dotrain = result.value;
      // Do something with the dotrain
      }

      Returns WasmEncodedResult<string>

      The complete dotrain text including YAML frontmatter and Rainlang code

    • Returns void

    • Creates a new DotrainOrder instance by parsing dotrain configuration text along with additional configuration.

      Parses the YAML frontmatter and validates the configuration including:

      • Spec version compatibility
      • Remote network configurations
      • Remote token definitions
      // Basic usage
      const result = await DotrainOrder.create(dotrainText);
      if (result.error) {
      console.error('Failed:', result.error.readableMsg);
      } else {
      const dotrainOrder = result.value;
      // Do something with the dotrainOrder
      }

      // With additional settings
      const result = await DotrainOrder.create(dotrainText, [additionalConfig]);
      if (result.error) {
      console.error('Failed:', result.error.readableMsg);
      } else {
      const dotrainOrder = result.value;
      // Do something with the dotrainOrder
      }

      Parameters

      • dotrain: string

        Complete dotrain text containing YAML frontmatter and Rainlang code

      • Optionalsettings: null | string[]

        Optional additional YAML configuration strings to merge with the frontmatter

      Returns Promise<WasmEncodedResult<DotrainOrder>>

      Successfully parsed and validated DotrainOrder instance