Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

How to get data from public APIs? #199

Open
omniscientcorp opened this issue Jul 26, 2018 · 1 comment
Open

How to get data from public APIs? #199

omniscientcorp opened this issue Jul 26, 2018 · 1 comment

Comments

@omniscientcorp
Copy link

Hi, I'm trying to get data from the public API, using bitex.interfaces

from bitex import Gemini
g = Gemini()
g.ticker('BTC-USD')

Gives me the following error:

return_api_response: HTTPError for url https://api.gemini.com/v1/pubticker/BTC-USD Traceback (most recent call last): File "/home/aismail/anaconda3/lib/python3.6/site-packages/bitex/utils.py", line 40, in wrapper r.raise_for_status() File "/home/aismail/anaconda3/lib/python3.6/site-packages/requests/models.py", line 935, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.gemini.com/v1/pubticker/BTC-USD Error while applying formatter! Traceback (most recent call last): File "/home/aismail/anaconda3/lib/python3.6/site-packages/bitex/utils.py", line 61, in wrapper r.formatted = formatter(data, *args, **kwargs) File "/home/aismail/anaconda3/lib/python3.6/site-packages/bitex/formatters/gemini.py", line 17, in ticker return (data['bid'], data['ask'], None, None, None, None, data['last'], KeyError: 'bid'

@raoden1
Copy link

raoden1 commented Nov 17, 2018

from bitex import Gemini
g = Gemini()
print(g.ticker('btcusd').json())

That seems to work after small modification in gemini.py :

# Import Built-Ins
import logging, json

# Import Third-Party

# Import Homebrew
from bitex.formatters.base import Formatter

# Init Logging Facilities
log = logging.getLogger(__name__)


class GmniFormatter(Formatter):

    @staticmethod
    def ticker(data, *args, **kwargs):
        data = json.dumps(data)
        return data

Originally was:

(data['bid'], data['ask'], None, None, None, None, data['last'],
                data['volume'][args[0][:3].upper()], data['volume']['timestamp'])

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants