Wabash Simple Order Question
ptunney
Posts: 246
A simple script to start off our Wabash students...
from cloudquant.interfaces import Strategy
class testwabash(Strategy):
@classmethod
def is_symbol_qualified(cls, symbol, md, service, account):
return md.stat.prev_close>10 and md.stat.prev_close<11
def on_start(self, md, order, service, account):
self.position = 0
def on_trade(self, event, md, order, service, account):
if md.L1.last>10.90 and event.timestamp<service.time(9, 32, 0, 0) and self.position==0:
order.send(self.symbol, 'buy', 10, type='MKT')
self.position = 1
print self.symbol,md.L1.last,md.L1.last_size, service.time_to_string(event.timestamp,format="%Y-%m-%d %H:%M:%S.%f")
if event.timestamp>service.time(9, 33, 0, 0) and self.position == 1:
myshares=account[self.symbol].position.shares
order.send(self.symbol, 'sell', myshares, type='MKT')
self.position = 2
Comments
The students also expressed an interest in VANGUARD ETFs and a little confustion surrounding how "tabbing in" works in Python.
So I modified the code as follows.
I also added a lot of comments and explanation of how commenting and tabbing works...