from strategy_sdk import Strategy
class MyStrategy(Strategy):
LABEL = "My Strategy"
TICK_MINUTES = 1.0
CONFIG_SCHEMA = {
"risk": {"type": "float", "default": 0.01},
"window": {"type": "int", "default": 20}
}
STATE_SCHEMA = {
"prices": {"type": "list", "default": []},
"position": {"type": "int", "default": 0}
}
def init(self):
return {
"prices": [],
"position": 0
}
def on_tick(self, tick):
self.state["prices"].append(tick["price"])
def render(self):
return {
"widgets": [
{"type": "line_chart", "data": self.state["prices"]}
]
}
class Strategy:
LABEL = "Strategy"
CONFIG_SCHEMA = {}
STATE_SCHEMA = {}
def __init__(self, context, config):
self.context = context
self.config = config
self.state = self.init()
def init(self):
return {}
def on_tick(self, tick):
pass
def render(self):
return {"widgets": []}
CONFIG_SCHEMA = {
"risk": {
"type": "float",
"default": 0.01,
"min": 0.0,
"max": 1.0
},
"window": {
"type": "int",
"default": 20
}
}
class StrategyContext:
def get_price(self, symbol):
raise NotImplementedError
def place_order(self, side, amount):
raise NotImplementedError
def get_orders(self):
raise NotImplementedError
def cancel_all_orders(self):
raise NotImplementedError
def log(self, message):
raise NotImplementedError
Instantiate -> init() -> on_tick() -> render()
The engine owns persistence and restores state around reload / unload / pause boundaries.
strategy_sdk/
__init__.py
base.py
context.py
config.py (optional)
ui.py (optional)
strategies/
my_strategy.py