Touch Price Order
Touch Price Order¶
Here is a simple example that how to build your price monitor and when price touches the condition will place the order.
from pydantic import BaseModel
class TouchOrderCond(BaseModel):
contract: Contract
order: Order
order: Order
touch_price: float
class TouchOrder:
def __init__(self, api: sj.Shioaji, condition: TouchOrderCond
):
self.flag = False
self.api = api
self.order = condition.order
self.contract = condition.contract
self.touch_price = condition.touch_price
self.api.quote.subscribe(self.contract)
self.api.quote.set_quote_callback(self.touch)
def touch(self, topic, quote):
price = quote["Close"][0]
if price == self.touch_price and not self.flag:
self.flag = True
self.api.place_order(self.contract, self.order)
self.api.quote.unsubscribe(self.contract)
Complete TouchPrice Order Extention can be found here.