Workflow API¶
Workflow API manages flat automation chains:
trigger -> conditions -> actions
Workflow chains are stored as WorkflowRuleRecord. Current API covers definitions, validation, CRUD, run log reads and the first trade-event runtime path.
Runtime Phase 2¶
The first runtime path is enabled for trade and BO account events:
EventBus trade.push / account.push
-> WorkflowManager
-> ThreadPoolGlobal worker
-> WorkflowRuntimeContext
-> active rules by resolved trading group brand + trigger
-> trade/account/customer conditions
-> runtime-supported actions
-> workflow run log
Supported trigger mapping:
EV_RECORD_ADD + OP_BUY/OP_SELL -> trade.opened
EV_RECORD_ACTIVATE_TRADE + OP_BUY/OP_SELL -> trade.opened
EV_RECORD_CLOSE_TRADE + OP_BUY/OP_SELL -> trade.closed
EV_RECORD_ADD + OP_BALANCE_IN -> deposit.created
EV_RECORD_ADD + OP_BALANCE_OUT -> withdrawal.created
account.push + EV_RECORD_ADD -> account:added
account.push + EV_RECORD_UPDATE -> account:updated
account.push + EV_RECORD_DELETE -> account:deleted
Supported runtime conditions include:
brand
amount_usd
trade.order
trade.login
trade.cmd
trade.volume
trade.close_price
trade.symbol
trade.comment
account.login
account.group
account.name
account.email
account.country
account.enable
account.leverage
customer.country
customer.language
customer.email
customer.kyc_status
customer.kyc_current_level
customer.risk_level
Supported runtime actions:
notify.manager
customer.set_risk_level
customer.set_status
webhook.send
If notify.manager.params.manager_id is omitted or 0, backend first tries the linked customer's assigned_manager_id, then manager_id, then broadcasts to enabled managers.
webhook.send requires params.url and sends an outbound HTTP request from workflow runtime. Optional params are method, headers, body, and timeout_ms.
{
"type": "webhook.send",
"params": {
"url": "https://example.com/webhook",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"body": "{\"text\":\"High risk trade\"}",
"timeout_ms": 5000
}
}
method defaults to POST; timeout_ms is clamped to 1000..30000. The action succeeds only on HTTP 2xx; curl errors or non-2xx responses make the workflow run failed. Runtime logs mask common webhook tokens.
kyc.require_step and kyc.set_required_level are visible in registry metadata, but runtime execution remains disabled until the real KycManager module exists.
trade.volume is integer volume: 100 = 1.00 lot, so 10 lots is 1000.
Brand is resolved through the trading group:
TradeRecord.login -> AccountRecord.group -> GroupRecord.brand
This supports both CRM accounts linked to customers and direct BO/MT-style accounts without CRM customers. CustomerRecord.brand remains CRM metadata; trade workflow brand scope comes from the trading group. If no group brand can be resolved, the workflow is skipped and a warning is written to logs.
Access Model¶
Only SESSION_ADMIN can create, update, archive or delete workflow chains:
MngAddWorkflowRule
MngUpdateWorkflowRule
MngArchiveWorkflowRule
MngDeleteWorkflowRule
Read, metadata and validation methods are available to manager sessions:
SESSION_MANAGER
SESSION_ADMIN
SESSION_DEALER
SESSION_CRM_MANAGER
SESSION_CRM_ADMIN
SEO¶
Workflow API supports CRM workflow automation, BackOffice automation, broker rule engine, KYC automation, customer lifecycle automation and trigger condition action workflows.