brighter-trading/archived_code/test_DataCache.py

222 lines
16 KiB
Python

"""
{
"name": "fff",
"strategy_json": {
"type": "strategy",
"statements": [
{
"type": "execute_if",
"inputs": {
"CONDITION": {
"type": "comparison",
"operator": "<",
"inputs": {
"LEFT": {
"type": "risk_ratio",
"inputs": {}
},
"RIGHT": {
"type": "dynamic_value",
"values": [
{
"type": "current_balance",
"inputs": {}
}
]
}
}
}
},
"statements": {
"DO": [
{
"type": "max_position_size",
"inputs": {
"MAX_SIZE": {
"type": "available_balance",
"inputs": {}
}
},
"next": {
"type": "execute_if",
"inputs": {
"CONDITION": {
"type": "is_false",
"inputs": {
"condition": {
"type": "order_status",
"inputs": {
"order_name": "order_name",
"status": "filled"
}
}
}
}
},
"statements": {
"DO": [
{
"type": "execute_if",
"inputs": {
"CONDITION": {
"type": "comparison",
"operator": ">",
"inputs": {
"LEFT": {
"type": "dynamic_value",
"values": [
{
"type": "last_candle_value",
"inputs": {
"source": {},
"candle_part": "open"
}
}
]
},
"RIGHT": {
"type": "dynamic_value",
"values": [
44
]
}
}
}
},
"statements": {
"DO": [
{
"type": "trade_action",
"trade_type": "buy",
"inputs": {
"size": {
"type": "math_operation",
"inputs": {
"operator": "divide",
"left_operand": {
"type": "starting_balance",
"inputs": {}
},
"right_operand": 15
}
}
},
"trade_options": [
{
"type": "name_order",
"inputs": {
"order_name": "order_name"
}
},
{
"type": "target_market",
"inputs": {
"time_frame": "15m",
"exchange": "binance",
"symbol": "ETH/BTC"
}
}
]
}
]
}
}
]
}
}
},
{
"type": "execute_if",
"inputs": {
"CONDITION": {
"type": "is_false",
"inputs": {
"condition": {
"type": "order_status",
"inputs": {
"order_name": "order_name",
"status": "filled"
}
}
}
}
},
"statements": {
"DO": [
{
"type": "execute_if",
"inputs": {
"CONDITION": {
"type": "comparison",
"operator": ">",
"inputs": {
"LEFT": {
"type": "dynamic_value",
"values": [
{
"type": "last_candle_value",
"inputs": {
"source": {},
"candle_part": "open"
}
}
]
},
"RIGHT": {
"type": "dynamic_value",
"values": [
44
]
}
}
}
},
"statements": {
"DO": [
{
"type": "trade_action",
"trade_type": "buy",
"inputs": {
"size": {
"type": "math_operation",
"inputs": {
"operator": "divide",
"left_operand": {
"type": "starting_balance",
"inputs": {}
},
"right_operand": 15
}
}
},
"trade_options": [
{
"type": "name_order",
"inputs": {
"order_name": "order_name"
}
},
{
"type": "target_market",
"inputs": {
"time_frame": "15m",
"exchange": "binance",
"symbol": "ETH/BTC"
}
}
]
}
]
}
}
]
}
}
]
}
}
]
},
"workspace": "<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"execute_if\" id=\"MsS{sEm446Tq-9cZ?LEM\" x=\"50\" y=\"110\"><comment pinned=\"false\" h=\"80\" w=\"160\">Execute the enclosed statements if the condition is true.</comment><value name=\"CONDITION\"><block type=\"comparison\" id=\"o$er@YT|44pRfD2*;kC%\"><field name=\"OPERATOR\">&lt;</field><comment pinned=\"false\" h=\"80\" w=\"160\">Compare two values using operators like &gt;, &lt;, ==.</comment><value name=\"LEFT\"><block type=\"risk_ratio\" id=\"-{)}8vrsu.uQ`,}~MEf-\"><comment pinned=\"false\" h=\"80\" w=\"160\">Calculate and retrieve the current risk ratio.</comment></block></value><value name=\"RIGHT\"><block type=\"current_balance\" id=\"rG=}HE!*$H|BWca!-G+%\"><comment pinned=\"false\" h=\"80\" w=\"160\">Retrieve the current balance of the strategy.</comment></block></value></block></value><statement name=\"DO\"><block type=\"max_position_size\" id=\"p{Do;wN=r3%T.7QD!]H@\"><comment pinned=\"false\" h=\"80\" w=\"160\">Set a maximum limit on the number of positions the strategy can hold.</comment><value name=\"MAX_SIZE\"><block type=\"available_balance\" id=\"H;h(SZy-/g/;;|S_]YQb\"><comment pinned=\"false\" h=\"80\" w=\"160\">Retrieve the overall available (liquid) balance of the user.</comment></block></value><next><block type=\"execute_if\" id=\"85pyvJR)Fr*LmqgKnIUm\"><comment pinned=\"false\" h=\"80\" w=\"160\">Execute the enclosed statements if the condition is true.</comment><value name=\"CONDITION\"><block type=\"is_false\" id=\"(vRWbh:/a=bX}${W4(/t\"><comment pinned=\"false\" h=\"80\" w=\"160\">Check if a condition is false.</comment><value name=\"condition\"><block type=\"order_status\" id=\"v#j1BnPG5pKC$M?csI)8\"><field name=\"ORDER_NAME\">order_name</field><field name=\"order_status\">partial</field><comment pinned=\"false\" h=\"80\" w=\"160\">Get the status of a named order.</comment></block></value></block></value><statement name=\"DO\"><block type=\"execute_if\" id=\"+dPkaDvC^21ylWseCZV;\"><comment pinned=\"false\" h=\"80\" w=\"160\">Execute the enclosed statements if the condition is true.</comment><value name=\"CONDITION\"><block type=\"comparison\" id=\"YTu*wGkeOU0k4]D|(j*:\"><field name=\"OPERATOR\">&gt;</field><comment pinned=\"false\" h=\"80\" w=\"160\">Compare two values using operators like &gt;, &lt;, ==.</comment><value name=\"LEFT\"><block type=\"last_candle_value\" id=\"8h3nZn?#t3UXcuU}icCC\"><field name=\"candle_part\">open</field><comment pinned=\"false\" h=\"80\" w=\"160\">Retrieve a specific part (Open, High, Low, Close) of the last candle from a given source.</comment></block></value><value name=\"RIGHT\"><block type=\"value_input\" id=\"i|%1Z,IK5~WCR5t~[T=J\"><field name=\"VALUE\">44</field><comment pinned=\"false\" h=\"80\" w=\"160\">Enter a numerical value. Chain multiple for a list.</comment></block></value></block></value><statement name=\"DO\"><block type=\"trade_action\" id=\"CYMHOlTFGfsK|l:ce{bX\"><field name=\"tradeType\">buy</field><comment pinned=\"false\" h=\"80\" w=\"160\">Execute a Buy/Sell trade based on a condition with specified size and options.</comment><value name=\"size\"><block type=\"math_operation\" id=\"^+dd,6d[Yg#w+bS|C{{S\"><field name=\"operator\">DIVIDE</field><comment pinned=\"false\" h=\"80\" w=\"160\">Perform basic arithmetic operations between two values.</comment><value name=\"LEFT\"><block type=\"starting_balance\" id=\"Bi5*6JEj#xP`DK9M1-p^\"><comment pinned=\"false\" h=\"80\" w=\"160\">Retrieve the starting balance of the strategy.</comment></block></value><value name=\"RIGHT\"><block type=\"value_input\" id=\".kd4Xeke%72-6/tdATz(\"><field name=\"VALUE\">15</field><comment pinned=\"false\" h=\"80\" w=\"160\">Enter a numerical value. Chain multiple for a list.</comment></block></value></block></value><statement name=\"trade_options\"><block type=\"name_order\" id=\"c;$K`P/c1nf2Ut)yJf=]\"><field name=\"order_name\">order_name</field><comment pinned=\"false\" h=\"80\" w=\"160\">Assign a custom name to the current order.</comment><next><block type=\"target_market\" id=\"FsX9_==AQf?DKtj]1C`]\"><field name=\"TF\">15m</field><field name=\"EXC\">binance</field><field name=\"SYM\">ETH/BTC</field><comment pinned=\"false\" h=\"80\" w=\"160\">Choose the target market for posting orders.</comment></block></next></block></statement></block></statement></block></statement></block></next></block></statement></block></xml>"
}
"""