Skip to main content

createPriceRule

Creates a new price rule for monitoring cryptocurrency prices and triggering alerts based on specified conditions.

Input Parameters

input
PriceRuleInput
required
The price rule configuration

Returns

priceRule
PriceRule
The created price rule object

Example

mutation {
  createPriceRule(
    input: {
      name: "BTC Price Alert"
      description: "Alert when Bitcoin drops below $60,000"
      instrumentId: "550e8400-e29b-41d4-a716-446655440000"
      isEnabled: true
      notificationChannel: TELEGRAM
      conditions: [
        {
          conditionType: PRICE
          value: 60000.00
          additionalValues: "{\"direction\":\"below\"}"
        }
      ]
    }
  ) {
    id
    name
    description
    isEnabled
    instrument {
      id
      symbol
      name
    }
    conditions {
      conditionType
      value
      additionalValues
    }
    createdAt
  }
}
After creating a price rule, the system automatically updates the WebSocket subscriptions to monitor the specified instrument in real-time.

updatePriceRule

Updates an existing price rule. You can modify the name, description, instrument, conditions, and notification settings.

Input Parameters

input
PriceRuleInput
required
The updated price rule configuration. Must include the id field to identify which rule to update.

Returns

priceRule
PriceRule
The updated price rule object with all current values

Example

mutation {
  updatePriceRule(
    input: {
      id: "123e4567-e89b-12d3-a456-426614174000"
      name: "BTC Price Alert - Updated"
      description: "Alert when Bitcoin drops below $55,000 or rises above $70,000"
      instrumentId: "550e8400-e29b-41d4-a716-446655440000"
      isEnabled: true
      notificationChannel: TELEGRAM
      conditions: [
        {
          conditionType: PRICE
          value: 55000.00
          additionalValues: "{\"direction\":\"below\"}"
        },
        {
          conditionType: PRICE
          value: 70000.00
          additionalValues: "{\"direction\":\"above\"}"
        }
      ]
    }
  ) {
    id
    name
    description
    isEnabled
    conditions {
      conditionType
      value
      additionalValues
    }
    lastTriggeredAt
    lastTriggeredPrice
  }
}
The update mutation replaces all existing conditions with the new ones provided. Make sure to include all conditions you want to keep.

deletePriceRule

Deletes a price rule permanently. This action cannot be undone.

Input Parameters

id
ID
required
The unique identifier of the price rule to delete

Returns

priceRule
PriceRule
The deleted price rule object. This is returned so you can confirm which rule was deleted or potentially restore it.

Example

mutation {
  deletePriceRule(id: "123e4567-e89b-12d3-a456-426614174000") {
    id
    name
    description
  }
}
When a price rule is deleted, it is also automatically removed from the in-memory rule cache and WebSocket subscriptions are updated accordingly.

togglePriceRule

Toggles the enabled state of a price rule. If the rule is currently enabled, it will be disabled, and vice versa.

Input Parameters

id
ID
required
The unique identifier of the price rule to toggle

Returns

priceRule
PriceRule
The price rule object with the updated isEnabled state

Example

mutation {
  togglePriceRule(id: "123e4567-e89b-12d3-a456-426614174000") {
    id
    name
    isEnabled
    lastTriggeredAt
  }
}
Toggling a price rule updates the rule cache and WebSocket subscriptions in real-time. When disabled, the rule will not trigger any alerts even if conditions are met.

Error Handling

All price rule mutations may throw the following errors:
  • “User not found” - The authenticated user could not be identified
  • “Instrument not found” - The specified instrumentId does not exist
  • “Price rule not found” - The specified price rule ID does not exist or does not belong to the current user (for update, delete, toggle operations)
  • “Error creating price rule” - A database or system error occurred during creation
  • “Error updating price rule” - A database or system error occurred during update
  • “Error deleting price rule” - A database or system error occurred during deletion
  • “Error enabling price rule” - A database or system error occurred during toggle
All price rule operations are scoped to the authenticated user. You can only modify or delete your own price rules.

Build docs developers (and LLMs) love