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 runtime execution for trade, account, customer and KYC events.
Runtime¶
The runtime path is event-driven:
EventBus trade.push / account.push / customer.push / kyc.step.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
customer.push + EV_RECORD_ADD -> customer.created
customer.push + EV_RECORD_UPDATE -> customer.updated
kyc.step.push + approved status -> kyc.step.approved
kyc.step.push + rejected status -> kyc.step.rejected
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
kyc.require_step
kyc.set_required_level
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 creates or reuses a customer KYC profile and attaches a required step from a KYC step template. Required params are step_code; optional params are level and reason.
kyc.set_required_level creates or reuses a customer KYC profile and increases the required KYC level. Required param is level; optional param is reason. When the level is increased, KycManager attaches all active required templates for the same brand with template.level <= level.
KYC workflow actions require a linked customer context. They are executed through KycManager; the trading mainLoop is not involved.
For a deposit-triggered KYC flow, create a rule on deposit.created with conditions such as amount_usd >= 1 and customer.kyc_current_level < 1, then execute kyc.set_required_level with level = 1.
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.