hootnot / oanda-api-v20

OANDA REST-V20 API wrapper. Easy access to OANDA's REST v20 API with oandapyV20 package. Checkout the Jupyter notebooks!
MIT License
398 stars 107 forks source link

Health API #89

Closed hootnot closed 7 years ago

hootnot commented 7 years ago

Provide support to the health-API endpoints.

In case of exceptions on the REST-V1 / REST-V20 this API can (possibly) provide extra information regarding the status of the services.

import sys
import json
import oandapyV20
from oandapyV20.exceptions import V20Error
import oandapyV20.contrib.healthAPI as health

# for time being: add health URL's to available environments
setattr(sys.modules["oandapyV20.oandapyV20"],
                   "TRADING_ENVIRONMENTS",
                    {"health": {
                     "stream": "http://api-status.oanda.com",
                     "api": "http://api-status.oanda.com",
                     }})

api = oandapyV20.API(access_token=None, environment="health")

r = health.Services()
print("REQ: {}".format(r))
try:
    api.request(r)

except Exception as err:
    print("Pretty bad! health service not accessible")
    exit(2)

else:
    print("{}".format(json.dumps(r.response, indent=2)))
    print("# services: ", len(r.response['services']))
    # show some info
    for service in r.response['services']:
        print('ID  : {}'.format(service['id']))
        print('DESC: {}'.format(service['name']))
        print('ST: {}'.format(service.get('current-event').get('status').get('description')))
hootnot commented 7 years ago

see #88