On the example on the previous page the trading pair, threshold condition and buy/sell quantities were hard coded in the Workflow. Though good for testing, this is not ideal. In the next version below I will try to improve this using a Rules table in the database and flow variables in the Workflow.
Below a screenshot of what a possible rules table could look like (first version) with an example rule in it explained below:
The meaning of this Rule would be: for the BTC/USD pair, if the percentual value (RULE) compared to minus one day (COMPARE) changed -2 percent or more (RULE_VALUE) , then SELL (ACTION) 25 (ACTION_VALUE) percent (ACTION_TYPE) of my BTC assets.
The columns RULE and ACTION_TYPE can have the values PCT (percentual) or ABS (absolute value).
Below is a screenshot of the modified workflow, which uses this Rules table and flow variables.
Below a screenshot of the Python Place Order node after execution, so you can see it does work. (The Insufficient Balance message was expected, I deliberately exceeded the amount of BTC I possess to avoid triggering a real order)
The above workflow just 'processes' one row of the Rules table. One further improvement would be to make this loop, so we could have more than one rule in the Rules table, for different trading pairs for example.
The workflow below handles this, thru the Table Row to Variable loop start and Variable loop end nodes.
The DB writer node to the right implements a basic logging of the orders that get placed in the ORDER_LOG table , of which you can see a screenshot below. This way we have a simple audit of the actions the agent has taken.