BitMEX / api-connectors

Libraries for connecting to the BitMEX API.
https://www.bitmex.com/app/restAPI
909 stars 797 forks source link

Python Official API Connector doesn't work at all #7

Closed chrism2671 closed 7 years ago

chrism2671 commented 7 years ago

Swaggerpy is unmaintained and doesn't support Python 3. I believe we should use Bravado (https://github.com/Yelp/bravado), which is a maintained fork.

The URL in the client definition is dead:

bitMEX = SwaggerClient(
    "https://testnet.bitmex.com/api/explorer/resources",
    http_client=http_client)

I've tried my own version (w/ Bravado): client = SwaggerClient.from_url('https://www.bitmex.com/api/explorer/swagger.json') but this fails Swagger spec validation.

It does seem to load the resources correctly though if I force it:

client = SwaggerClient.from_url('https://www.bitmex.com/api/explorer/swagger.json',
                                config={'validate_swagger_spec': False)

I still get errors though when I try to make requests, even if I turn off all (other) validations (as per Bravado docs).

client = SwaggerClient.from_url('https://www.bitmex.com/api/explorer/swagger.json',
                                config={'validate_swagger_spec': False, 'validate_responses':False, 'also_return_response':True, 'use_models': False})

client.Quote.Quote_get(symbol='XBTH17').result()

Is there any chance we can get an up-to-date example of this working with Python?

STRML commented 7 years ago

Thanks for the notice; Swagger compliance is remarkably complicated due to some ambiguity in the spec and typical human error.

I'll release an update but we may have to fork bravado-core due to https://github.com/Yelp/bravado-core/issues/46. I'll see about getting our spec updated to eliminate some of the errors.

STRML commented 7 years ago

@chrism2671 This is now working on testnet; I've applied some small changes to our Swagger JSON output to keep the validators happy.

We'll roll the changes to production within the next day; in the meantime please use Testnet.

chrism2671 commented 7 years ago

@STRML This is amazing! Thank you so much! I'm gonna get stuck in today; I'll report back if I have any problems!

STRML commented 7 years ago

Glad to hear. This change has rolled out to all environments so feel free to grab data from www. as well, it should work without issue.