Code for trailing stop

I saw in the documentation that trailing stop orders are to come.

Any help with code (python) that could monitor 1 minute price moves and create a market sell order when the ‘trailing stop’ has been reached?

For example:
Buy SPY @ $300
Currently, I could open a limit sell at $270 (down 10%).
If SPY runs to $350, I’d like to have code that is checking every minute if SPY falls below $315 (down 10% from $350). Once the current price hits $315, I’d automatically enter a market sell order.

I’m learning python, so my rough logic would be:

def high_price()
executed_order_price = [get from orders]
current_price = [get from market]
if(current_price > executed_order_price):
return current_price

def price_trigger
if current_price < (high_price * 0.9)
api.submit_order(‘SPY’,qty=100,side=‘sell’,type=‘market’)

Thanks,
–Jim

Ok, here’s how I’m implementing. I think this essentially gets me there:

current_position_price = api.polygon.last_trade(ticker).price

barset = api.get_barset(ticker,‘minute’,)
ticker_bars = barset[ticker]
price_1m_ago = ticker_bars[-2].c

if current_position_price < price_1m_ago:
Sell

My algo runs ~ every minute, so it will update with the last trade and compare to the last completed minute. If a stock is rising, the current_position_price will be greater than the previous minute. At the next refresh, the price_1m_ago will then be higher, and ‘trail’ the current price on its way up.