GetFX NBP API module

Module implements NBP specific API to retrieve FX rates.

Provides init_cmd() function to parse command line attributes and GetFxNBP class which implements specific methods to retrieve FX rates.

It depends on cmdparser module which provides DEFAULT_CURRENCY and parse_getfx() method to parse command line arguments. It uses NBP_API_URL which contains URL for NBP API.

getfx.getfxnbp.NBP_API_URL = 'http://api.nbp.pl/api/exchangerates/rates/A'

Defines NBP API URL used for requests

getfx.getfxnbp.init_cmd(test_args=None)

Parse command line attributes and create GetFxNBP instance.

It uses parse_getfx() to parse command line attributes. It creates instance of GetFxNBP to handle request and response from NBP API.

Raises

SystemExit

for incorrect command line attributes, with following exit codes:

  • 0 - no errors

  • 1 - no connection (see _get_response() method)

  • 2 - incorrect date or currency parameter


class getfx.getfxnbp.GetFxNBP(currency='CHF', date=None)

Subclass of GetFX class to implement NBP specific FX retrieval logic.

It does not provide public methods, instead it is assumed when instance is created, NBP API is invoked and FX rate retrieved. Access to retrieved rate is achieved via printing the instance using overridden: __str__() method.

__str__()

Return formatted string to display currency rate information.

_get_response(currency, date=None)

Receive JSON response from FX provider.

Raises
  • ValueError – incorrect request parameters

  • ConnectionError – with exit code(1) when lack of internet connection