コード例 #1
0
def convertStockDay(stock,startStep,start,end):
    stckID = meSchema.getStckID(stock)
    result = meSchema.getStck(stckID,startStep)
    if len(result) == 78:
        return True  # If already 78.. then most likely already converted.
    elif len(result) > 0:
        db.delete(result)

    step = startStep
    stockRange = meSchema.getStockRange(stock,start,end)
    k = len(stockRange)
    if k < 78:
        return False
    m = k - 78
    skip = 0
    meList = []

    for i in range(k):
        if i%5 in [0,3] and skip < m:
            skip += 1
        else:
            meStck = meSchema.stck(ID    = stckID,
                                   step  = step,
                                   quote = stockRange[i].lastPrice)
            meList.append(meStck)
            if len(meList) == 78:
                db.put(meList)
                return True
            step += 1
            
    return False
コード例 #2
0
    def get(self):
        #format = "%Y-%m-%d %H:%M:%S"  # 2009-11-16 23:45:02
        self.response.headers['Content-Type'] = 'text/plain'
        action = str(self.request.get('action'))

        if action == 'put':
            import datetime as dt
            from pytz import timezone
            eastern = timezone('US/Eastern')
            datetime = dt.datetime.now(eastern)

            creds = meSchema.getCredentials()
            email = creds.email
            password = creds.password
            
            tester = meFinanceTester(email,password)
            portfolios = tester.GetPortfolios(True)
            
            for pfl in portfolios:
                positions = tester.GetPositions(pfl,True)
                for pos in positions:                
                    symbol = pos.ticker_id.split(':')[1]
                    quote = float(str(pos.position_data.market_value).replace(' USD',''))
                    bid = quote
                    ask = quote
                    if (symbol in ['GOOG','HBC','CME','INTC']):
                        result = meSchema.putStockQuote(symbol,quote,bid,ask,datetime)
                        self.response.out.write(result)
                    elif (symbol in ['.INX']):
                        self.response.out.write('putting %s\nquote: %f\n' % (symbol,quote))
                        #result = meSchema.putIndex
        elif action == 'get':
            self.response.out.write("in the get!\n")
            for symbol in ['GOOG','HBC','CME','INTC']:
                result = meSchema.getStockQuote(symbol)
                self.response.out.write('Symbol: %s\nlastPrice: %f\ndate: %s\n' % (symbol,result.lastPrice,result.date))
        elif action == 'wipeout':
            meSchema.wipeOutCreds()
            self.response.out.write('Wiped out the credentials')
        elif action == 'range':
            result = meSchema.getStockRange()
            self.response.out.write('len of result = %s\n' % len(result))
        elif action == 'token':
            myToken = meSchema.getToken()
            
            creds = meSchema.getCredentials()
            email = creds.email
            password = creds.password
            
            if not (myToken is None):
                tester = meFinanceTester(email,'',myToken)
                self.response.out.write('I in myToken auth')
            else:
                tester = meFinanceTester(email,password)
                token = tester.GetToken()
                meSchema.putToken(token)
                self.response.out.write('I putting token')
                
            token = tester.GetToken()
            self.response.out.write('meToken: %s' % token)
        else:
            self.response.out.write('You requested I do nothing!')