def get(self): coins = Coin.query().order(-Coin.date).fetch(len(coinKeys)) template_values = { 'coins': coins, } template = JINJA_ENVIRONMENT.get_template('index.html') self.response.write(template.render(template_values))
def getEnableCoins(self): coins = Coin.query().order(-Coin.date).fetch(len(coinKeys)) enableCoins = 0 for coin in coins: if coin.notice == True: enableCoins = enableCoins + 1 enableCoins = len(coins) - enableCoins logging.info(enableCoins) return enableCoins
def get(self): urlfetch.set_default_fetch_deadline(60) coins = Coin.query().order(-Coin.date).fetch(len(coinKeys)) for coin in coins: site = noti_site + coin.name req = urllib2.Request(site, headers=hdr) obj = json.load(urllib2.urlopen(req)) if int(obj[dataKey][lastKey]) > coin.buy and coin.notice == False: noise_coins = Coin.query( Coin.name == str(coin.name)).order(-Coin.date).fetch(30) noise = 0.0 for noise_coin in noise_coins: noise = noise + noise_coin.noise msg = "Buy:" + coin.name + ", Price:" + str( coin.buy) + ", Noise:" + str(noise / len(noise_coins)) enableCoins = self.getEnableCoins() units = api.selectUnits(coin.name, coin.volatility, enableCoins) coin.units = api.marketBuy(coin.name, units) coin.notice = True coin.put() logging.info(msg)
def get(self): urlfetch.set_default_fetch_deadline(60) coins = Coin.query().order(-Coin.date).fetch(len(coinKeys)) for coin in coins: if coin.notice: site = noti_site + coin.name req = urllib2.Request(site, headers=hdr) body = json.load(urllib2.urlopen(req)) obj = body msg = coin.name + " -> return:" + str( (float(obj[dataKey][lastKey]) / float(coin.buy) - 1) * 100) + "%" #broadcase(msg) result = api.marketSell(coin.name, coin.units) logging.info(msg) sleep(15) for key in coinKeys: site = cal_site + key req = urllib2.Request(site, headers=hdr) obj = json.load(urllib2.urlopen(req)) openValue = float(obj[dataKey][openKey]) lastValue = float(obj[dataKey][lastKey]) highValue = float(obj[dataKey][highKey]) lowValue = float(obj[dataKey][lowKey]) logging.info("key:" + key + ",last:" + str(lastValue)) buy = lastValue + 0.5 * (highValue - lowValue) noise = 1 - math.fabs(openValue - lastValue) / (highValue - lowValue) volatility = (highValue - lowValue) / lastValue * 100 coin = Coin(name=key, buy=int(buy), noise=float(noise), volatility=float(volatility), units=0.01) coin.put()