Coinbase APIv2-当前和历史现货价格总是一样吗?

时间:2018-10-29 22:55:19

标签: python coinbase-api

im试图构建一个简单的功能来充当卖出止损。将当前价格与10分钟前的价格进行比较,如果价格下降x%,则会触发当前价格。

APIv2参考here表示使用isoformat,并且似乎可以正常工作,因此我将timedelta设置为10分钟,然后在循环中每60秒获取当前价格和10分钟前的价格。

输出显示每60秒有很小的价格差异,但是“现在时间”和“ 10分钟之前的时间”始终相同。我在这里想念什么?

现在日期:2018-10-29 23:39:13.337916价格:5500.75

回溯日期:2018-10-29 23:29:13.337916价格:5500.75

现在日期:2018-10-29 23:40:14.288284价格:5501.14

回溯日期:2018-10-29 23:30:14.288284价格:5501.14

get_spot_pricetimedelta计算中的日期格式似乎有效,为什么不在循环中?

import coinbase
import datetime as dt
import time

date_now = dt.datetime.now()
date_1_min = dt.timedelta(minutes=10)
date_back = date_now - date_1_min

price_now = float(client.get_spot_price(currency_pair = 'BTC-EUR', date=date_now.isoformat()).amount)
print("Date now: ", date_now, "Price:", price_now)
price_back = float(client.get_spot_price(currency_pair = 'BTC-EUR', date=date_back.isoformat()).amount)
print("Date back:", date_back, "Price:", price_back)

price_back = float(client.get_spot_price(currency_pair = 'BTC-EUR', date="2018-10-29 23:18:05.969998").amount)
print("Date manual:", "2018-10-29 23:18:05.969998", "Price:", price_back)

print("################")

while True:
    date_now = dt.datetime.now()
    date_1_min = dt.timedelta(minutes=10)
    date_back = date_now - date_1_min

    print("################")
    price_now = float(client.get_spot_price(currency_pair = 'BTC-EUR', date=date_now.isoformat()).amount)
    print("Date now: ", date_now, "Price:", price_now)
    price_back = float(client.get_spot_price(currency_pair = 'BTC-EUR', date=date_back.isoformat()).amount)
    print("Date back:", date_back, "Price:", price_back)

    if price_now < price_back-(price_now/100*99.9999):
        print("Emergency sale")

    time.sleep(60)
    i += 1     
    if i == 20:
        break

0 个答案:

没有答案