Package: django_broker
This extremely simple and straightforward Django application facilitates the retrieval of exchange rates using theOpen Exchange Rates APIavailable athttp://openexchangerates.org.Quick StartInstall easily with pip:pip install django_brokerAdd Django Broker to your installed apps:INSTALLED_APPS = (

        ...
        'exchange',
        ...

)Import the RateFetchClient object in your modules and use as shown belowEnjoySynopsisThis application has one major object which retrieves the exchange rates by
making an API call to the Open Exchange API endpoints.Required SettingsThis application requires a set of standard settings configurations to get its job done.settings.OPENEXCHANGERATES_PAID_CXThis is a boolean value which lets the application know if the customer account is a paid account or not. It should be set toTrueorFalseaccordingly in your projectsettings.pyfile.settings.OPENEXCHANGERATES_APP_IDThis is a string which stores the API_KEY for your application as provisioned by the Open Exchange Rates API.RateFetchClientMain object for retrieving exchange rates. This object simply inherits from the pythonobject. It is initialized by passing in your Open Exchange App_ID as the singular parameter to the initializer.fetcher = RateFetchClient('APP_ID')Note that theAPP_IDdoes not have to be passed into this constructor. If you have set up the APP_ID project wide, then you do not need it here.
That’s it!You now have a new RateFetchClient object. This object has a couple methods which present the full functionality of the Open Exchange Rates API.query_rates(self, [base])This method takes an optionalbaseparameter. When specified, this parameter instructs the Open Exchange Rates API on the currency to be used as the…well, base! This means that all currency rates are provided relative to the selected base. When a base currency is not specified, theUS Dollaris assumed as the default.fetcher = RateFetchClient('APP_ID')

# Now we can make a query on this object
rates = fetcher.query_rates()Or:fetcher = RateFetchClient('APP_ID')
rates = fetcher.query_rates(base='CAD')This method returns a dictionary of exchange rates. The keys of this dictionary represent the currency codes and the values are the exchange rates relative to the base currency. Sample values will look like:{
        'DZD': Decimal('79.04391'),
        'NAD': Decimal('10.36218'),
        'GHS': Decimal('2.90095'),
        'EGP': Decimal('7.113293'),
        'BGN': Decimal('1.426792'),
        ...
}restrict_rates(self, [base, symbols])This method takes two optional parameters.Thebaseparameter is the same as that described above.
Thesymbolsparameter, when supplied, is a list of strings which represent the currencies we are interested in. This ensures that instead of receiving a massive dictionary of 160+ exchange rates, we only get back the currencies that we are interested in.It bears noting, however, that only users who have signed up for Enterprise/Unlimited accounts have access to some of the higher level functions, this one included. An example of the use of this function is shown below:fetcher = RateFetchClient('APP_ID')
symbols = ['USD', 'GBP', 'CAD']
rates = fetcher.restrict_rates(symbols=symbols)The dictionary returned by this method is exactly identical in format to that shown above, only shorterquery_currency(self)This method is somewhat similar to thequery_ratesmethod. It takes no parameters and returns a dictionary of all currencies provided by the Open Exchange Rates API.fetcher = RateFetchClient('APP_ID')
rates = fetcher.query_currency()The returned dictionay looks like:{
        u'DZD': u'Algerian Dinar',
        u'NAD': u'Namibian Dollar',
        u'GHS': u'Ghanaian Cedi',
        u'EGP': u'Egyptian Pound',
        u'BGN': u'Bulgarian Lev',
        u'PAB': u'Panamanian Balboa',
        u'BOB': u'Bolivian Boliviano',
        u'DKK': u'Danish Krone',
        ...
}exchange_currency(self, amount, _from, _to, [rate=False])This method uses the currency rates obtained from thequery_ratesmethod in converting one to the other. As the method signature shows above, it accepts 3 mandatory parameters and one optional.Theamountparameter is the amount to be changed in the_fromcurrency.
The_fromparameter is the currency from which the amount is being converted.
The_toparameter is the currency to which the amount is converted.
The optionalrateparameter determines whether or not the conversion rate is returned alongside the converted amount.When therateflag is set to True, a tuple is returned containing both the conversion rate and the converted amount. When it is set to False, only the converted amount is returned. This is set to False by default.amount = decimal.Decimal('20.00')
_from = 'EUR'
_to = 'CAD'
rate = True
conv_amount, conv_rate = fetcher.exchange_currency(amount, _from, _to, rate)And without the rate:...
conv_amount = fetcher.exchange_currency(amount, _from, _to)And that’s all folks!