示例#1
0
        print 'buy '+context.stocks[index]+' '+str(buy_volume)+'@'+str(sell_1)+'\n'
    elif sell_1 < (context.maxprice[index] - context.stoprate*context.costprice[index]) and hold_volume > 0 and context.traded[index] == False:
        result = w.torder(context.stocks[index],"Sell",buy_1,hold_volume,logonid=context.logonid)
        context.maxprice[index] = buy_1
        context.cash[index] = context.cash[index] + (buy_1*hold_volume)
        context.traded[index] = True
        #print result
        print 'sell '+context.stocks[index]+' '+str(hold_volume)+'@'+str(buy_1)+'\n'

    return()
        

w.start()
context = Context()
while True:
    while Timer.almostEnd():
        if context.isTradeDay():
            context.logon()
            context.getHistory()
            context.getPosition()
            context.getPrice()
            for index,stock in enumerate(context.stocks):
                Trade(context,index)

            fp = open('trade.data','w')
            fp.write(str(context.cash))
            fp.write(str(context.costprice))
            fp.close()
            time.sleep(20)