views.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:MultiExplorer 作者: priestc 项目源码 文件源码
def historical_price(request):
    fiat = request.GET['fiat'].upper()
    crypto = request.GET['currency'].upper()
    try:
        time = arrow.get(request.GET['time']).datetime
    except:
        return http.JsonResponse({'error': "Invalid Time argument"}, status=400)

    try:
        price = PriceTick.nearest(crypto, fiat, time)
    except PriceTick.DoesNotExist:
        return http.JsonResponse(
            {'error': "Can't get historical price for %s->%s" % (fiat, crypto)},
            status=400
        )

    try:
        naive_time = time.replace(tzinfo=None)
        price['estimated_supply'] = SupplyEstimator(crypto).calculate_supply(at_time=naive_time)
    except NotImplementedError:
        pass

    price['currency'] = crypto
    return http.JsonResponse(price)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号