示例#1
0
 def chart_history_lines(self, id):
     if Stock.get(id=id):
         return_dict = {'GroupedData':{}}
         stock = Stock[id]
         query = select((hl.date.year, hl.date.month, avg(hl.close)) for s in Stock for hl in s.history_lines if
                s.id == stock.id and hl.date.year == datetime.date.today().year)
         data = query.order_by(1, 2)[:]
         changed_data = []
         for d in data:
             changed_data.append({'label': month_replacer.get(d[1]), 'value': round(d[2], 2)})
         return_dict['GroupedData'] = changed_data
         return_dict['maxYaxis'] = max(changed_data, key=lambda x: x['value'])
         return return_dict
     abort(404)
示例#2
0
 def populate_lines(self, id):
     date_from = request.args.get('date_from', '1970-01-01')[:10]
     date_to = request.args.get('date_to', str(datetime.date.today()))[:10]
     if Stock.get(id=id):
         stock = Stock[id]
         history_dict = ystockquote.get_historical_prices(stock.code, date_from, date_to)
         for date, values in history_dict.items():
             new_vals = {
                 'date': date, 'volume': values['Volume'], 'high': values['High'],
                 'low': values['Low'], 'open': values['Open'], 'close': values['Close']
             }
             if not StockHistory.get(stock=stock, date=date):
                 stock.history_lines.create(**new_vals)
             else:
                 StockHistory.get(stock=stock, date=date).set(**new_vals)
         return convert_stocks(to_dict(Stock[id]))
     abort(404)
示例#3
0
 def delete(self, id):
     stock = Stock.get(id=id)
     if stock:
         stock.delete()
         return '', 204
     abort(404)
示例#4
0
 def put(self, id):
     # data = parser.parse_args()
     data = json.loads(request.data)
     stock = Stock.get(id=id)
     stock.set(**data)
     return Stock[id], 201