def makeAlgs():
    TradeSize = [0.25]
    # Changing to use tradeCue combinations.
    # Only 60 at the moment but this allows for up to 1000.
    fetchCues = meSchema.tradeCue.all().fetch(1000)
    TradeCues = []
    for tradecue in fetchCues:
        TradeCues.append(tradecue.key().name())
    Cash = [100000.0]
    id = 0
    meList = []
    count = 0
    for buyCue in TradeCues:
        for sellCue in TradeCues:
            if sellCue != buyCue:
                for size in TradeSize:
                    for meCash in Cash:
                        id += 1
                        key_name = meSchema.buildAlgKey(id)
                        alg = meSchema.meAlg(key_name  = key_name,
                                             TradeSize = size,
                                             BuyCue = buyCue,
                                             SellCue = sellCue,
                                             Cash  = meCash)
                        meList.append(alg)
    meSchema.batchPut(meList)
def algorithmDo(keyname,step):
    keyname = meSchema.buildAlgKey(keyname)
    dna = meSchema.memGet(meSchema.meAlg,keyname)
    tradesize = dna.TradeSize
    buy = dna.BuyDelta
    sell = dna.SellDelta

    for stckID in [1,2,3,4]:
        deltakey = str(stckID) + "_" + str(step)    # Must eventually change key to 0-padded.
        cval = meSchema.decompCval(deltakey)
        
        if cval is None or len(cval) < dna.TimeDelta + 1:
            return None

        cue = cval[dna.TimeDelta]
        buysell = buySell(tradesize,buy,sell,cue)

        if buysell in (-1,1):
            recent = recency(keyname,step,stckID,buysell,dna.TimeDelta)
            if not recent:
                action = makeDesire(stckID,keyname,step,buysell,tradesize,dna.Cash)
                recency_key = "desire_" + keyname + "_" + str(buysell) + "_" + str(stckID)
                value = step
                meSchema.memcacheSet(recency_key, value)
                return action    # add action/desire to list and return list ?
    return None