source code將永遠是你的朋友。
def get_spot_price(self, **params):
"""https://developers.coinbase.com/api/v2#get-spot-price"""
if 'currency_pair' in params:
currency_pair = params['currency_pair']
else:
currency_pair = 'BTC-USD'
response = self._get('v2', 'prices', currency_pair, 'spot', data=params)
return self._make_api_object(response, APIObject)
def get_historic_prices(self, **params):
"""https://developers.coinbase.com/api/v2#get-historic-prices"""
response = self._get('v2', 'prices', 'historic', data=params)
return self._make_api_object(response, APIObject)
我們可以看到,無論函數調用相同的API端點。我們看到get_spot_price
支持currency_pair
參數並將它作爲api調用的一部分傳遞。另一方面get_historic_prices
沒有。
我想知道如果發生了什麼會發生什麼。我們試試吧:
from coinbase.wallet.client import Client
from coinbase.wallet.model import APIObject
client = Client(api_key, api_secret)
client._make_api_object(client._get('v2', 'prices', 'ETH-USD', 'historic'), APIObject)
<APIObject @ 0x10dd04938> {
"currency": "USD",
"prices": [
{
"price": "52.60",
"time": "2017-03-30T17:03:48Z"
},
{
"price": "52.60",
"time": "2017-03-30T17:03:38Z"
},
{
"price": "52.54",
"time": "2017-03-30T17:03:28Z"
},
{
"price": "52.54",
"time": "2017-03-30T17:03:18Z"
},
{
"price": "52.54",
"time": "2017-03-30T17:03:08Z"
},
{
"price": "52.53",
"time": "2017-03-30T17:02:58Z"
},
{
"price": "52.53",
"time": "2017-03-30T17:02:48Z"
},
{
"price": "52.53",
"time": "2017-03-30T17:02:38Z"
},
{
"price": "52.53",
"time": "2017-03-30T17:02:28Z"
},
.....
成功了!
我會派他們的PR他們的方式。但現在你可以使用我的代碼片段。
PR submitted
@sam,順便說一下,除了歷史數據,所有的方法應與貨幣對工作了。如果他們似乎沒有工作,也許你需要在coinbase網站更新您的個人資料中的API版本andalso確保你是不是想向您的代碼 –
舊的API版本我不知道蟒蛇,我是iOS開發者,基本上我使用的網址來獲取數據和分析數據。可以請你給我的網址此歷史數據,最後你的程序生成的URL來獲取數據。 THX ..我 –