<p><a href="https://github.com/coinbase/coinbase-python/blob/master/coinbase/wallet/client.py#L206" rel="noreferrer">source code</a>永远是你的朋友。</p>
<pre class="lang-py prettyprint-override"><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)
</code></pre>
<p>我们可以看到两个函数都调用同一个api端点。我们看到<code>get_spot_price</code>支持<code>currency_pair</code>参数,并将其作为api调用的一部分传递。另一方面,<code>get_historic_prices</code>没有。</p>
<p>我想知道如果那样会发生什么。我们试试看:</p>
<pre><code>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"
},
.....
</code></pre>
<p>成功!</p>
<p>我会按他们的方式发送公关。但现在你可以用我的代码片段。</p>
<hr/>
<p><a href="https://github.com/coinbase/coinbase-python/pull/38" rel="noreferrer">PR submitted</a></p>