def post(self): coin_name = self.request.get('name') coin_buy = self.request.get('buy') coin_noise = self.request.get('noise') coin_volatility = self.request.get('volatility') coin = Coin(name=coin_name, buy=int(coin_buy), noise=float(coin_noise), volatility=float(coin_volatility), units=0.01) coin.put() self.redirect('/')
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()