示例#1
0
文件: api.py 项目: kostyll/stock2
def day_stat(Req, Pair):
    Current = TradePairs.objects.get(url_title=Pair)
    ##last value 17520
    cursor = connection.cursor()
    Q = cursor.execute("SELECT 	  sum(VolumeTrade) as VolumeTrade, \
                                  sum(VolumeBase) as VolumeBase,\
                                  max(Max) as Max,\
                                  min(Min) as Min \
                                  FROM main_stockstat WHERE  main_stockstat.Stock_id=%i \
                                  ORDER BY id DESC LIMIT  17520 " % Current.id)

    List = dictfetchall(cursor, Q)
    row = List[0]
    for i in row:
        if not row[i]:
            row[i] = format_numbers4(Decimal("0"))
        else:
            row[i] = format_numbers4(Decimal(row[i]))

    Dict = {"volume_base": row['VolumeBase'],
            "volume_trade": row['VolumeTrade'],
            "min": row['Min'],
            "max": row['Max'],
    }

    RespJ = json.JSONEncoder().encode(Dict)
    return RespJ
示例#2
0
文件: api.py 项目: kostyll/stock2
def last_price(Req, Pair):
    Current = None
    try:
        Current = TradePairs.objects.get(url_title=Pair)
    except:
        return json_false500(Req)
    Dict = None
    try:
        deal = DealsMemory.objects.filter(trade_pair=Current.id).latest("id")
        Dict = {"price": format_numbers4(deal.price), "price_10": format_numbers10(deal.price)}
    except:
        Dict = {"price": "0", "price_10": "0.000000000"}

    RespJ = json.JSONEncoder().encode(Dict)
    return RespJ