├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── setup.cfg
├── setup.py
├── tests
├── __init__.py
├── data
│ ├── __init__.py
│ └── testdata.json
├── test_integration.py
└── test_unit.py
└── xecd_rates_client
├── XecdClient.py
└── __init__.py
/.gitignore:
--------------------------------------------------------------------------------
1 | __pycache__/
2 | *.py[cod]
3 |
4 | .idea
5 | .vscode
6 | build/
7 | dist/
8 | venv/
9 | xecd_rates_client.egg-info/
10 |
11 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Mozilla Public License Version 2.0
2 | ==================================
3 |
4 | 1. Definitions
5 | --------------
6 |
7 | 1.1. "Contributor"
8 | means each individual or legal entity that creates, contributes to
9 | the creation of, or owns Covered Software.
10 |
11 | 1.2. "Contributor Version"
12 | means the combination of the Contributions of others (if any) used
13 | by a Contributor and that particular Contributor's Contribution.
14 |
15 | 1.3. "Contribution"
16 | means Covered Software of a particular Contributor.
17 |
18 | 1.4. "Covered Software"
19 | means Source Code Form to which the initial Contributor has attached
20 | the notice in Exhibit A, the Executable Form of such Source Code
21 | Form, and Modifications of such Source Code Form, in each case
22 | including portions thereof.
23 |
24 | 1.5. "Incompatible With Secondary Licenses"
25 | means
26 |
27 | (a) that the initial Contributor has attached the notice described
28 | in Exhibit B to the Covered Software; or
29 |
30 | (b) that the Covered Software was made available under the terms of
31 | version 1.1 or earlier of the License, but not also under the
32 | terms of a Secondary License.
33 |
34 | 1.6. "Executable Form"
35 | means any form of the work other than Source Code Form.
36 |
37 | 1.7. "Larger Work"
38 | means a work that combines Covered Software with other material, in
39 | a separate file or files, that is not Covered Software.
40 |
41 | 1.8. "License"
42 | means this document.
43 |
44 | 1.9. "Licensable"
45 | means having the right to grant, to the maximum extent possible,
46 | whether at the time of the initial grant or subsequently, any and
47 | all of the rights conveyed by this License.
48 |
49 | 1.10. "Modifications"
50 | means any of the following:
51 |
52 | (a) any file in Source Code Form that results from an addition to,
53 | deletion from, or modification of the contents of Covered
54 | Software; or
55 |
56 | (b) any new file in Source Code Form that contains any Covered
57 | Software.
58 |
59 | 1.11. "Patent Claims" of a Contributor
60 | means any patent claim(s), including without limitation, method,
61 | process, and apparatus claims, in any patent Licensable by such
62 | Contributor that would be infringed, but for the grant of the
63 | License, by the making, using, selling, offering for sale, having
64 | made, import, or transfer of either its Contributions or its
65 | Contributor Version.
66 |
67 | 1.12. "Secondary License"
68 | means either the GNU General Public License, Version 2.0, the GNU
69 | Lesser General Public License, Version 2.1, the GNU Affero General
70 | Public License, Version 3.0, or any later versions of those
71 | licenses.
72 |
73 | 1.13. "Source Code Form"
74 | means the form of the work preferred for making modifications.
75 |
76 | 1.14. "You" (or "Your")
77 | means an individual or a legal entity exercising rights under this
78 | License. For legal entities, "You" includes any entity that
79 | controls, is controlled by, or is under common control with You. For
80 | purposes of this definition, "control" means (a) the power, direct
81 | or indirect, to cause the direction or management of such entity,
82 | whether by contract or otherwise, or (b) ownership of more than
83 | fifty percent (50%) of the outstanding shares or beneficial
84 | ownership of such entity.
85 |
86 | 2. License Grants and Conditions
87 | --------------------------------
88 |
89 | 2.1. Grants
90 |
91 | Each Contributor hereby grants You a world-wide, royalty-free,
92 | non-exclusive license:
93 |
94 | (a) under intellectual property rights (other than patent or trademark)
95 | Licensable by such Contributor to use, reproduce, make available,
96 | modify, display, perform, distribute, and otherwise exploit its
97 | Contributions, either on an unmodified basis, with Modifications, or
98 | as part of a Larger Work; and
99 |
100 | (b) under Patent Claims of such Contributor to make, use, sell, offer
101 | for sale, have made, import, and otherwise transfer either its
102 | Contributions or its Contributor Version.
103 |
104 | 2.2. Effective Date
105 |
106 | The licenses granted in Section 2.1 with respect to any Contribution
107 | become effective for each Contribution on the date the Contributor first
108 | distributes such Contribution.
109 |
110 | 2.3. Limitations on Grant Scope
111 |
112 | The licenses granted in this Section 2 are the only rights granted under
113 | this License. No additional rights or licenses will be implied from the
114 | distribution or licensing of Covered Software under this License.
115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a
116 | Contributor:
117 |
118 | (a) for any code that a Contributor has removed from Covered Software;
119 | or
120 |
121 | (b) for infringements caused by: (i) Your and any other third party's
122 | modifications of Covered Software, or (ii) the combination of its
123 | Contributions with other software (except as part of its Contributor
124 | Version); or
125 |
126 | (c) under Patent Claims infringed by Covered Software in the absence of
127 | its Contributions.
128 |
129 | This License does not grant any rights in the trademarks, service marks,
130 | or logos of any Contributor (except as may be necessary to comply with
131 | the notice requirements in Section 3.4).
132 |
133 | 2.4. Subsequent Licenses
134 |
135 | No Contributor makes additional grants as a result of Your choice to
136 | distribute the Covered Software under a subsequent version of this
137 | License (see Section 10.2) or under the terms of a Secondary License (if
138 | permitted under the terms of Section 3.3).
139 |
140 | 2.5. Representation
141 |
142 | Each Contributor represents that the Contributor believes its
143 | Contributions are its original creation(s) or it has sufficient rights
144 | to grant the rights to its Contributions conveyed by this License.
145 |
146 | 2.6. Fair Use
147 |
148 | This License is not intended to limit any rights You have under
149 | applicable copyright doctrines of fair use, fair dealing, or other
150 | equivalents.
151 |
152 | 2.7. Conditions
153 |
154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155 | in Section 2.1.
156 |
157 | 3. Responsibilities
158 | -------------------
159 |
160 | 3.1. Distribution of Source Form
161 |
162 | All distribution of Covered Software in Source Code Form, including any
163 | Modifications that You create or to which You contribute, must be under
164 | the terms of this License. You must inform recipients that the Source
165 | Code Form of the Covered Software is governed by the terms of this
166 | License, and how they can obtain a copy of this License. You may not
167 | attempt to alter or restrict the recipients' rights in the Source Code
168 | Form.
169 |
170 | 3.2. Distribution of Executable Form
171 |
172 | If You distribute Covered Software in Executable Form then:
173 |
174 | (a) such Covered Software must also be made available in Source Code
175 | Form, as described in Section 3.1, and You must inform recipients of
176 | the Executable Form how they can obtain a copy of such Source Code
177 | Form by reasonable means in a timely manner, at a charge no more
178 | than the cost of distribution to the recipient; and
179 |
180 | (b) You may distribute such Executable Form under the terms of this
181 | License, or sublicense it under different terms, provided that the
182 | license for the Executable Form does not attempt to limit or alter
183 | the recipients' rights in the Source Code Form under this License.
184 |
185 | 3.3. Distribution of a Larger Work
186 |
187 | You may create and distribute a Larger Work under terms of Your choice,
188 | provided that You also comply with the requirements of this License for
189 | the Covered Software. If the Larger Work is a combination of Covered
190 | Software with a work governed by one or more Secondary Licenses, and the
191 | Covered Software is not Incompatible With Secondary Licenses, this
192 | License permits You to additionally distribute such Covered Software
193 | under the terms of such Secondary License(s), so that the recipient of
194 | the Larger Work may, at their option, further distribute the Covered
195 | Software under the terms of either this License or such Secondary
196 | License(s).
197 |
198 | 3.4. Notices
199 |
200 | You may not remove or alter the substance of any license notices
201 | (including copyright notices, patent notices, disclaimers of warranty,
202 | or limitations of liability) contained within the Source Code Form of
203 | the Covered Software, except that You may alter any license notices to
204 | the extent required to remedy known factual inaccuracies.
205 |
206 | 3.5. Application of Additional Terms
207 |
208 | You may choose to offer, and to charge a fee for, warranty, support,
209 | indemnity or liability obligations to one or more recipients of Covered
210 | Software. However, You may do so only on Your own behalf, and not on
211 | behalf of any Contributor. You must make it absolutely clear that any
212 | such warranty, support, indemnity, or liability obligation is offered by
213 | You alone, and You hereby agree to indemnify every Contributor for any
214 | liability incurred by such Contributor as a result of warranty, support,
215 | indemnity or liability terms You offer. You may include additional
216 | disclaimers of warranty and limitations of liability specific to any
217 | jurisdiction.
218 |
219 | 4. Inability to Comply Due to Statute or Regulation
220 | ---------------------------------------------------
221 |
222 | If it is impossible for You to comply with any of the terms of this
223 | License with respect to some or all of the Covered Software due to
224 | statute, judicial order, or regulation then You must: (a) comply with
225 | the terms of this License to the maximum extent possible; and (b)
226 | describe the limitations and the code they affect. Such description must
227 | be placed in a text file included with all distributions of the Covered
228 | Software under this License. Except to the extent prohibited by statute
229 | or regulation, such description must be sufficiently detailed for a
230 | recipient of ordinary skill to be able to understand it.
231 |
232 | 5. Termination
233 | --------------
234 |
235 | 5.1. The rights granted under this License will terminate automatically
236 | if You fail to comply with any of its terms. However, if You become
237 | compliant, then the rights granted under this License from a particular
238 | Contributor are reinstated (a) provisionally, unless and until such
239 | Contributor explicitly and finally terminates Your grants, and (b) on an
240 | ongoing basis, if such Contributor fails to notify You of the
241 | non-compliance by some reasonable means prior to 60 days after You have
242 | come back into compliance. Moreover, Your grants from a particular
243 | Contributor are reinstated on an ongoing basis if such Contributor
244 | notifies You of the non-compliance by some reasonable means, this is the
245 | first time You have received notice of non-compliance with this License
246 | from such Contributor, and You become compliant prior to 30 days after
247 | Your receipt of the notice.
248 |
249 | 5.2. If You initiate litigation against any entity by asserting a patent
250 | infringement claim (excluding declaratory judgment actions,
251 | counter-claims, and cross-claims) alleging that a Contributor Version
252 | directly or indirectly infringes any patent, then the rights granted to
253 | You by any and all Contributors for the Covered Software under Section
254 | 2.1 of this License shall terminate.
255 |
256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257 | end user license agreements (excluding distributors and resellers) which
258 | have been validly granted by You or Your distributors under this License
259 | prior to termination shall survive termination.
260 |
261 | ************************************************************************
262 | * *
263 | * 6. Disclaimer of Warranty *
264 | * ------------------------- *
265 | * *
266 | * Covered Software is provided under this License on an "as is" *
267 | * basis, without warranty of any kind, either expressed, implied, or *
268 | * statutory, including, without limitation, warranties that the *
269 | * Covered Software is free of defects, merchantable, fit for a *
270 | * particular purpose or non-infringing. The entire risk as to the *
271 | * quality and performance of the Covered Software is with You. *
272 | * Should any Covered Software prove defective in any respect, You *
273 | * (not any Contributor) assume the cost of any necessary servicing, *
274 | * repair, or correction. This disclaimer of warranty constitutes an *
275 | * essential part of this License. No use of any Covered Software is *
276 | * authorized under this License except under this disclaimer. *
277 | * *
278 | ************************************************************************
279 |
280 | ************************************************************************
281 | * *
282 | * 7. Limitation of Liability *
283 | * -------------------------- *
284 | * *
285 | * Under no circumstances and under no legal theory, whether tort *
286 | * (including negligence), contract, or otherwise, shall any *
287 | * Contributor, or anyone who distributes Covered Software as *
288 | * permitted above, be liable to You for any direct, indirect, *
289 | * special, incidental, or consequential damages of any character *
290 | * including, without limitation, damages for lost profits, loss of *
291 | * goodwill, work stoppage, computer failure or malfunction, or any *
292 | * and all other commercial damages or losses, even if such party *
293 | * shall have been informed of the possibility of such damages. This *
294 | * limitation of liability shall not apply to liability for death or *
295 | * personal injury resulting from such party's negligence to the *
296 | * extent applicable law prohibits such limitation. Some *
297 | * jurisdictions do not allow the exclusion or limitation of *
298 | * incidental or consequential damages, so this exclusion and *
299 | * limitation may not apply to You. *
300 | * *
301 | ************************************************************************
302 |
303 | 8. Litigation
304 | -------------
305 |
306 | Any litigation relating to this License may be brought only in the
307 | courts of a jurisdiction where the defendant maintains its principal
308 | place of business and such litigation shall be governed by laws of that
309 | jurisdiction, without reference to its conflict-of-law provisions.
310 | Nothing in this Section shall prevent a party's ability to bring
311 | cross-claims or counter-claims.
312 |
313 | 9. Miscellaneous
314 | ----------------
315 |
316 | This License represents the complete agreement concerning the subject
317 | matter hereof. If any provision of this License is held to be
318 | unenforceable, such provision shall be reformed only to the extent
319 | necessary to make it enforceable. Any law or regulation which provides
320 | that the language of a contract shall be construed against the drafter
321 | shall not be used to construe this License against a Contributor.
322 |
323 | 10. Versions of the License
324 | ---------------------------
325 |
326 | 10.1. New Versions
327 |
328 | Mozilla Foundation is the license steward. Except as provided in Section
329 | 10.3, no one other than the license steward has the right to modify or
330 | publish new versions of this License. Each version will be given a
331 | distinguishing version number.
332 |
333 | 10.2. Effect of New Versions
334 |
335 | You may distribute the Covered Software under the terms of the version
336 | of the License under which You originally received the Covered Software,
337 | or under the terms of any subsequent version published by the license
338 | steward.
339 |
340 | 10.3. Modified Versions
341 |
342 | If you create software not governed by this License, and you want to
343 | create a new license for such software, you may create and use a
344 | modified version of this License if you rename the license and remove
345 | any references to the name of the license steward (except to note that
346 | such modified license differs from this License).
347 |
348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary
349 | Licenses
350 |
351 | If You choose to distribute Source Code Form that is Incompatible With
352 | Secondary Licenses under the terms of this version of the License, the
353 | notice described in Exhibit B of this License must be attached.
354 |
355 | Exhibit A - Source Code Form License Notice
356 | -------------------------------------------
357 |
358 | This Source Code Form is subject to the terms of the Mozilla Public
359 | License, v. 2.0. If a copy of the MPL was not distributed with this
360 | file, You can obtain one at http://mozilla.org/MPL/2.0/.
361 |
362 | If it is not possible or desirable to put the notice in a particular
363 | file, then You may include the notice in a location (such as a LICENSE
364 | file in a relevant directory) where a recipient would be likely to look
365 | for such a notice.
366 |
367 | You may add additional accurate notices of copyright ownership.
368 |
369 | Exhibit B - "Incompatible With Secondary Licenses" Notice
370 | ---------------------------------------------------------
371 |
372 | This Source Code Form is "Incompatible With Secondary Licenses", as
373 | defined by the Mozilla Public License, v. 2.0.
374 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 |
2 | .PHONY: help test package dist dist_test
3 | .DEFAULT: help
4 |
5 | VENV_NAME?=venv
6 | PYTHON=${VENV_NAME}/bin/python3
7 | PIP=${VENV_NAME}/bin/pip
8 | TWINE=${VENV_NAME}/bin/twine
9 |
10 | help:
11 | @echo "make test - Run tests"
12 | @echo "make package - Builds the package for use or deployment"
13 | @echo "make dist - Uploads the package to pypi (will ask for credentials)"
14 | @echo "make dist_test - Uploads the package to test.pypi (will ask for credentials)"
15 |
16 | venv: ${VENV_NAME}/bin/activate
17 | ${VENV_NAME}/bin/activate: setup.py
18 | test -d ${VENV_NAME} || python3 -m venv ${VENV_NAME}
19 | ${PIP} install wheel twine
20 | ${PYTHON} setup.py develop
21 | touch ${VENV_NAME}/bin/activate
22 |
23 | test: venv
24 | ${PYTHON} setup.py test
25 |
26 | package: venv test
27 | ${PYTHON} setup.py sdist bdist_wheel
28 |
29 | dist: package
30 | ${TWINE} upload dist/*
31 |
32 | dist_test: package
33 | ${TWINE} upload --repository-url https://test.pypi.org/legacy/ dist/*
34 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | # XE Currency Data Client - Python
8 |
9 | XE.com Inc. is the World's Trusted Currency Authority. This project provides an SDK to interface with our XE Currency Data (XECD) product.
10 |
11 | XE Currency Data is a REST API that gives you access to daily or live rates and historic mid-market conversion rates between all of our supported currencies.
12 |
13 | You will need an api key and secret to use this sdk. Sign up for a [free trial][4] or register for a [full account][5].
14 |
15 | This client will work with both python2 and python3.
16 |
17 | ## Installation
18 |
19 | The preferred way to install this package is pip.
20 |
21 | ```
22 | pip install xecd-rates-client
23 | ```
24 |
25 | Or get the latest version from git:
26 | ```
27 | pip install git+https://github.com/XenonLab/xecd-rates-client-python.git
28 | ```
29 |
30 |
31 | This package follows [semantic versioning][3].
32 |
33 | ## Usage
34 |
35 | ```python
36 | >>> from xecd_rates_client import XecdClient
37 | >>> xecd = XecdClient('ACCOUNT_ID', 'API_KEY')
38 |
39 | >>> xecd.account_info()
40 | {'id': '11111111-1111-1111-1111-111111111111', 'organization': 'YOUR_ORG', 'package': 'ENTERPRISE_LIVE_INTERNAL', 'service_start_timestamp': '2018-01-01T00:00:00Z'}
41 |
42 | >>> xecd.convert_from("EUR", "CAD", 55)
43 | {'terms': 'http://www.xe.com/legal/dfs.php', 'privacy': 'http://www.xe.com/privacy.php', 'from': 'EUR', 'amount': 55.0, 'timestamp': '2018-08-21T15:31:00Z', 'to': [{'quotecurrency': 'CAD', 'mid': 82.7121317322}]}
44 |
45 | >>> xecd.convert_to("RUB", "CAD", 55)
46 | {'terms': 'http://www.xe.com/legal/dfs.php', 'privacy': 'http://www.xe.com/privacy.php', 'to': 'RUB', 'amount': 55.0, 'timestamp': '2018-08-21T15:32:00Z', 'from': [{'quotecurrency': 'CAD', 'mid': 1.0652293852}]}
47 |
48 | >>> xecd.historic_rate("2016-12-25", "12:34", "EUR", "CAD", 55)
49 | {'terms': 'http://www.xe.com/legal/dfs.php', 'privacy': 'http://www.xe.com/privacy.php', 'from': 'EUR', 'amount': 55.0, 'timestamp': '2016-12-25T13:00:00Z', 'to': [{'quotecurrency': 'CAD', 'mid': 77.8883951909}]}
50 |
51 | >>> xecd.historic_rate_period(55, "EUR", "RUB", "2016-02-28T12:00", "2016-03-03T12:00")
52 | {'terms': 'http://www.xe.com/legal/dfs.php', 'privacy': 'http://www.xe.com/privacy.php', 'from': 'EUR', 'amount': 55.0, 'to': {'RUB': [{'mid': 4590.1222691671, 'timestamp': '2016-02-28T12:00:00Z'}, {'mid': 4545.42879069, 'timestamp': '2016-02-29T12:00:00Z'}, {'mid': 4433.0643335184, 'timestamp': '2016-03-01T12:00:00Z'}, {'mid': 4409.6291908683, 'timestamp': '2016-03-02T12:00:00Z'}, {'mid': 4396.2068371801, 'timestamp': '2016-03-03T12:00:00Z'}]}}
53 |
54 | >>> xecd.monthly_average(55, "CAD", "EUR", 2017, 5)
55 | {'terms': 'http://www.xe.com/legal/dfs.php', 'privacy': 'http://www.xe.com/privacy.php', 'from': 'CAD', 'amount': 55.0, 'year': 2017, 'to': {'EUR': [{'monthlyAverage': 36.5976590134, 'month': 5, 'daysInMonth': 31}]}}
56 | ```
57 |
58 | ## Documentation
59 |
60 | [Technical Specifications][2]
61 |
62 | ## Contributing
63 |
64 | xecd_rates_client_python is an open-source project. Submit a pull request to contribute!
65 |
66 | ## Testing
67 |
68 | ```bash
69 | make test
70 | ```
71 |
72 | Or, to run individual test suites
73 | ```bash
74 | python -m unittest tests/test_unit.py
75 | python -m unittest tests/test_integration.py
76 | ```
77 |
78 | Note: the unit tests must be run with python3 due to its use of unittest.mock (which is not present as of python2.7). Despite this, the client itself is usable with both python 2 and 3.
79 |
80 | ## Security Issues
81 |
82 | If you discover a security vulnerability within this package, please **DO NOT** publish it publicly. Instead, contact us at **security [at] xe.com**. We will follow up with you as soon as possible.
83 |
84 | ## About Us
85 |
86 | [XE.com Inc.][1] is The World's Trusted Currency Authority. Development of this project is led by the XE.com Inc. Development Team and supported by the open-source community.
87 |
88 | [1]: http://www.xe.com
89 | [2]: http://www.xe.com/xecurrencydata/XE_Currency_Data_API_Specifications.pdf
90 | [3]: http://semver.org/
91 | [4]: https://xecd.xe.com/account/signup.php?freetrial
92 | [5]: http://www.xe.com/xecurrencydata/
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | [bdist_wheel]
2 | universal=1
3 |
4 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | import setuptools
2 |
3 | with open("README.md", "r") as fh:
4 | long_description = fh.read()
5 |
6 | setuptools.setup(
7 | name='xecd_rates_client',
8 | version='1.0.0',
9 | url='https://github.com/XenonLab/xecd-rates-client-python',
10 | packages=setuptools.find_packages(exclude=['tests*']),
11 | description='XECD REST Client',
12 | long_description=long_description,
13 | long_description_content_type="text/markdown",
14 | author='XE.com Inc. Development Team',
15 | author_email='python@xe.com',
16 | zip_safe=True,
17 | test_suite='tests',
18 | install_requires=[
19 | 'requests>=2.19.1'
20 | ],
21 | classifiers=[
22 | "Programming Language :: Python :: 2",
23 | "Programming Language :: Python :: 3",
24 | "Intended Audience :: Developers",
25 | "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
26 | "Operating System :: OS Independent",
27 | "Development Status :: 4 - Beta"
28 | ]
29 | )
30 |
--------------------------------------------------------------------------------
/tests/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XenonLab/xecd-rates-client-python/8fda56b30f054e41410d14b4afc0fef52ccc6b0e/tests/__init__.py
--------------------------------------------------------------------------------
/tests/data/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XenonLab/xecd-rates-client-python/8fda56b30f054e41410d14b4afc0fef52ccc6b0e/tests/data/__init__.py
--------------------------------------------------------------------------------
/tests/data/testdata.json:
--------------------------------------------------------------------------------
1 | {
2 | "fakeAccountInfo": {"id":"12345678-abcd-4321-aaaa-eeffeeffeeff","organization":"XE","package":"ENTERPRISE","service_start_timestamp":"2017-09-06T00:00:00Z","service_end_timestamp":"2017-12-29T00:00:00Z"},
3 |
4 | "fakeCurrencies": {"terms":"http://www.xe.com/legal/dfs.php","privacy":"http://www.xe.com/privacy.php","currencies":[{"iso":"AED","currency_name":"Emirati Dirham","is_obsolete":false},{"iso":"AFN","currency_name":"Afghan Afghani","is_obsolete":false},{"iso":"ALL","currency_name":"Albanian Lek","is_obsolete":false},{"iso":"AMD","currency_name":"Armenian Dram","is_obsolete":false},{"iso":"ANG","currency_name":"Dutch Guilder","is_obsolete":false},{"iso":"AOA","currency_name":"Angolan Kwanza","is_obsolete":false},{"iso":"ARS","currency_name":"Argentine Peso","is_obsolete":false},{"iso":"AUD","currency_name":"Australian Dollar","is_obsolete":false},{"iso":"AWG","currency_name":"Aruban or Dutch Guilder","is_obsolete":false},{"iso":"AZN","currency_name":"Azerbaijan Manat","is_obsolete":false},{"iso":"BAM","currency_name":"Bosnian Convertible Marka","is_obsolete":false},{"iso":"BBD","currency_name":"Barbadian or Bajan Dollar","is_obsolete":false},{"iso":"BDT","currency_name":"Bangladeshi Taka","is_obsolete":false},{"iso":"BGN","currency_name":"Bulgarian Lev","is_obsolete":false},{"iso":"BHD","currency_name":"Bahraini Dinar","is_obsolete":false},{"iso":"BIF","currency_name":"Burundian Franc","is_obsolete":false},{"iso":"BMD","currency_name":"Bermudian Dollar","is_obsolete":false},{"iso":"BND","currency_name":"Bruneian Dollar","is_obsolete":false},{"iso":"BOB","currency_name":"Bolivian Bolíviano","is_obsolete":false},{"iso":"BRL","currency_name":"Brazilian Real","is_obsolete":false},{"iso":"BSD","currency_name":"Bahamian Dollar","is_obsolete":false},{"iso":"BTN","currency_name":"Bhutanese Ngultrum","is_obsolete":false},{"iso":"BWP","currency_name":"Botswana Pula","is_obsolete":false},{"iso":"BYN","currency_name":"Belarusian Ruble","is_obsolete":false},{"iso":"BZD","currency_name":"Belizean Dollar","is_obsolete":false},{"iso":"CAD","currency_name":"Canadian Dollar","is_obsolete":false},{"iso":"CDF","currency_name":"Congolese Franc","is_obsolete":false},{"iso":"CHF","currency_name":"Swiss Franc","is_obsolete":false},{"iso":"CLP","currency_name":"Chilean Peso","is_obsolete":false},{"iso":"CNH","currency_name":"Chinese Yuan Renminbi Offshore","is_obsolete":false},{"iso":"CNY","currency_name":"Chinese Yuan Renminbi","is_obsolete":false},{"iso":"COP","currency_name":"Colombian Peso","is_obsolete":false},{"iso":"CRC","currency_name":"Costa Rican Colon","is_obsolete":false},{"iso":"CUC","currency_name":"Cuban Convertible Peso","is_obsolete":false},{"iso":"CUP","currency_name":"Cuban Peso","is_obsolete":false},{"iso":"CVE","currency_name":"Cape Verdean Escudo","is_obsolete":false},{"iso":"CZK","currency_name":"Czech Koruna","is_obsolete":false},{"iso":"DJF","currency_name":"Djiboutian Franc","is_obsolete":false},{"iso":"DKK","currency_name":"Danish Krone","is_obsolete":false},{"iso":"DOP","currency_name":"Dominican Peso","is_obsolete":false},{"iso":"DZD","currency_name":"Algerian Dinar","is_obsolete":false},{"iso":"EGP","currency_name":"Egyptian Pound","is_obsolete":false},{"iso":"ERN","currency_name":"Eritrean Nakfa","is_obsolete":false},{"iso":"ETB","currency_name":"Ethiopian Birr","is_obsolete":false},{"iso":"EUR","currency_name":"euro","is_obsolete":false},{"iso":"FJD","currency_name":"Fijian Dollar","is_obsolete":false},{"iso":"FKP","currency_name":"Falkland Island Pound","is_obsolete":false},{"iso":"GBP","currency_name":"British Pound","is_obsolete":false},{"iso":"GEL","currency_name":"Georgian Lari","is_obsolete":false},{"iso":"GGP","currency_name":"Guernsey Pound","is_obsolete":false},{"iso":"GHS","currency_name":"Ghanaian Cedi","is_obsolete":false},{"iso":"GIP","currency_name":"Gibraltar Pound","is_obsolete":false},{"iso":"GMD","currency_name":"Gambian Dalasi","is_obsolete":false},{"iso":"GNF","currency_name":"Guinean Franc","is_obsolete":false},{"iso":"GTQ","currency_name":"Guatemalan Quetzal","is_obsolete":false},{"iso":"GYD","currency_name":"Guyanese Dollar","is_obsolete":false},{"iso":"HKD","currency_name":"Hong Kong Dollar","is_obsolete":false},{"iso":"HNL","currency_name":"Honduran Lempira","is_obsolete":false},{"iso":"HRK","currency_name":"Croatian Kuna","is_obsolete":false},{"iso":"HTG","currency_name":"Haitian Gourde","is_obsolete":false},{"iso":"HUF","currency_name":"Hungarian Forint","is_obsolete":false},{"iso":"IDR","currency_name":"Indonesian Rupiah","is_obsolete":false},{"iso":"ILS","currency_name":"Israeli Shekel","is_obsolete":false},{"iso":"IMP","currency_name":"Isle of Man Pound","is_obsolete":false},{"iso":"INR","currency_name":"Indian Rupee","is_obsolete":false},{"iso":"IQD","currency_name":"Iraqi Dinar","is_obsolete":false},{"iso":"IRR","currency_name":"Iranian Rial","is_obsolete":false},{"iso":"ISK","currency_name":"Icelandic Krona","is_obsolete":false},{"iso":"JEP","currency_name":"Jersey Pound","is_obsolete":false},{"iso":"JMD","currency_name":"Jamaican Dollar","is_obsolete":false},{"iso":"JOD","currency_name":"Jordanian Dinar","is_obsolete":false},{"iso":"JPY","currency_name":"Japanese Yen","is_obsolete":false},{"iso":"KES","currency_name":"Kenyan Shilling","is_obsolete":false},{"iso":"KGS","currency_name":"Kyrgyzstani Som","is_obsolete":false},{"iso":"KHR","currency_name":"Cambodian Riel","is_obsolete":false},{"iso":"KMF","currency_name":"Comorian Franc","is_obsolete":false},{"iso":"KPW","currency_name":"North Korean Won","is_obsolete":false},{"iso":"KRW","currency_name":"South Korean Won","is_obsolete":false},{"iso":"KWD","currency_name":"Kuwaiti Dinar","is_obsolete":false},{"iso":"KYD","currency_name":"Caymanian Dollar","is_obsolete":false},{"iso":"KZT","currency_name":"Kazakhstani Tenge","is_obsolete":false},{"iso":"LAK","currency_name":"Lao Kip","is_obsolete":false},{"iso":"LBP","currency_name":"Lebanese Pound","is_obsolete":false},{"iso":"LKR","currency_name":"Sri Lankan Rupee","is_obsolete":false},{"iso":"LRD","currency_name":"Liberian Dollar","is_obsolete":false},{"iso":"LSL","currency_name":"Basotho Loti","is_obsolete":false},{"iso":"LYD","currency_name":"Libyan Dinar","is_obsolete":false},{"iso":"MAD","currency_name":"Moroccan Dirham","is_obsolete":false},{"iso":"MDL","currency_name":"Moldovan Leu","is_obsolete":false},{"iso":"MGA","currency_name":"Malagasy Ariary","is_obsolete":false},{"iso":"MKD","currency_name":"Macedonian Denar","is_obsolete":false},{"iso":"MMK","currency_name":"Burmese Kyat","is_obsolete":false},{"iso":"MNT","currency_name":"Mongolian Tughrik","is_obsolete":false},{"iso":"MOP","currency_name":"Macau Pataca","is_obsolete":false},{"iso":"MRO","currency_name":"Mauritanian Ouguiya","is_obsolete":false},{"iso":"MUR","currency_name":"Mauritian Rupee","is_obsolete":false},{"iso":"MVR","currency_name":"Maldivian Rufiyaa","is_obsolete":false},{"iso":"MWK","currency_name":"Malawian Kwacha","is_obsolete":false},{"iso":"MXN","currency_name":"Mexican Peso","is_obsolete":false},{"iso":"MYR","currency_name":"Malaysian Ringgit","is_obsolete":false},{"iso":"MZN","currency_name":"Mozambican Metical","is_obsolete":false},{"iso":"NAD","currency_name":"Namibian Dollar","is_obsolete":false},{"iso":"NGN","currency_name":"Nigerian Naira","is_obsolete":false},{"iso":"NIO","currency_name":"Nicaraguan Cordoba","is_obsolete":false},{"iso":"NOK","currency_name":"Norwegian Krone","is_obsolete":false},{"iso":"NPR","currency_name":"Nepalese Rupee","is_obsolete":false},{"iso":"NZD","currency_name":"New Zealand Dollar","is_obsolete":false},{"iso":"OMR","currency_name":"Omani Rial","is_obsolete":false},{"iso":"PAB","currency_name":"Panamanian Balboa","is_obsolete":false},{"iso":"PEN","currency_name":"Peruvian Sol","is_obsolete":false},{"iso":"PGK","currency_name":"Papua New Guinean Kina","is_obsolete":false},{"iso":"PHP","currency_name":"Philippine Peso","is_obsolete":false},{"iso":"PKR","currency_name":"Pakistani Rupee","is_obsolete":false},{"iso":"PLN","currency_name":"Polish Zloty","is_obsolete":false},{"iso":"PYG","currency_name":"Paraguayan Guarani","is_obsolete":false},{"iso":"QAR","currency_name":"Qatari Riyal","is_obsolete":false},{"iso":"RON","currency_name":"Romanian Leu","is_obsolete":false},{"iso":"RSD","currency_name":"Serbian Dinar","is_obsolete":false},{"iso":"RUB","currency_name":"Russian Ruble","is_obsolete":false},{"iso":"RWF","currency_name":"Rwandan Franc","is_obsolete":false},{"iso":"SAR","currency_name":"Saudi Arabian Riyal","is_obsolete":false},{"iso":"SBD","currency_name":"Solomon Islander Dollar","is_obsolete":false},{"iso":"SCR","currency_name":"Seychellois Rupee","is_obsolete":false},{"iso":"SDG","currency_name":"Sudanese Pound","is_obsolete":false},{"iso":"SEK","currency_name":"Swedish Krona","is_obsolete":false},{"iso":"SGD","currency_name":"Singapore Dollar","is_obsolete":false},{"iso":"SHP","currency_name":"Saint Helenian Pound","is_obsolete":false},{"iso":"SLL","currency_name":"Sierra Leonean Leone","is_obsolete":false},{"iso":"SOS","currency_name":"Somali Shilling","is_obsolete":false},{"iso":"SPL","currency_name":"Seborgan Luigino","is_obsolete":false},{"iso":"SRD","currency_name":"Surinamese Dollar","is_obsolete":false},{"iso":"STD","currency_name":"Sao Tomean Dobra","is_obsolete":false},{"iso":"SVC","currency_name":"Salvadoran Colon","is_obsolete":false},{"iso":"SYP","currency_name":"Syrian Pound","is_obsolete":false},{"iso":"SZL","currency_name":"Swazi Lilangeni","is_obsolete":false},{"iso":"THB","currency_name":"Thai Baht","is_obsolete":false},{"iso":"TJS","currency_name":"Tajikistani Somoni","is_obsolete":false},{"iso":"TMT","currency_name":"Turkmenistani Manat","is_obsolete":false},{"iso":"TND","currency_name":"Tunisian Dinar","is_obsolete":false},{"iso":"TOP","currency_name":"Tongan Pa\u0027anga","is_obsolete":false},{"iso":"TRY","currency_name":"Turkish Lira","is_obsolete":false},{"iso":"TTD","currency_name":"Trinidadian Dollar","is_obsolete":false},{"iso":"TVD","currency_name":"Tuvaluan Dollar","is_obsolete":false},{"iso":"TWD","currency_name":"Taiwan New Dollar","is_obsolete":false},{"iso":"TZS","currency_name":"Tanzanian Shilling","is_obsolete":false},{"iso":"UAH","currency_name":"Ukrainian Hryvnia","is_obsolete":false},{"iso":"UGX","currency_name":"Ugandan Shilling","is_obsolete":false},{"iso":"USD","currency_name":"US Dollar","is_obsolete":false},{"iso":"UYU","currency_name":"Uruguayan Peso","is_obsolete":false},{"iso":"UZS","currency_name":"Uzbekistani Som","is_obsolete":false},{"iso":"VEF","currency_name":"Venezuelan Bolívar","is_obsolete":false},{"iso":"VND","currency_name":"Vietnamese Dong","is_obsolete":false},{"iso":"VUV","currency_name":"Ni-Vanuatu Vatu","is_obsolete":false},{"iso":"WST","currency_name":"Samoan Tala","is_obsolete":false},{"iso":"XAF","currency_name":"Central African CFA Franc BEAC","is_obsolete":false},{"iso":"XAG","currency_name":"Silver Ounce","is_obsolete":false},{"iso":"XAU","currency_name":"Gold Ounce","is_obsolete":false},{"iso":"XBT","currency_name":"Bitcoin","is_obsolete":false},{"iso":"XCD","currency_name":"East Caribbean Dollar","is_obsolete":false},{"iso":"XDR","currency_name":"IMF Special Drawing Rights","is_obsolete":false},{"iso":"XOF","currency_name":"CFA Franc","is_obsolete":false},{"iso":"XPD","currency_name":"Palladium Ounce","is_obsolete":false},{"iso":"XPF","currency_name":"CFP Franc","is_obsolete":false},{"iso":"XPT","currency_name":"Platinum Ounce","is_obsolete":false},{"iso":"YER","currency_name":"Yemeni Rial","is_obsolete":false},{"iso":"ZAR","currency_name":"South African Rand","is_obsolete":false},{"iso":"ZMW","currency_name":"Zambian Kwacha","is_obsolete":false},{"iso":"ZWD","currency_name":"Zimbabwean Dollar","is_obsolete":false}]},
5 |
6 | "fakeConvertFrom": {"terms":"http://www.xe.com/legal/dfs.php","privacy":"http://www.xe.com/privacy.php","from":"EUR","amount":55.0,"timestamp":"2017-10-03T18:59:00Z","to":[{"quotecurrency":"CAD","mid":80.7057828403}]},
7 |
8 | "fakeConvertTo": {"terms":"http://www.xe.com/legal/dfs.php","privacy":"http://www.xe.com/privacy.php","to":"RUB","amount":55.0,"timestamp":"2017-10-03T18:59:00Z","from":[{"quotecurrency":"CAD","mid":1.1872421446}]},
9 |
10 | "fakeHistoricRate": {"terms":"http://www.xe.com/legal/dfs.php","privacy":"http://www.xe.com/privacy.php","from":"EUR","amount":55.0,"timestamp":"2016-12-25T13:00:00Z","to":[{"quotecurrency":"CAD","mid":77.8285483431}]},
11 |
12 | "fakeHistoricRatePeriod": {"terms":"http://www.xe.com/legal/dfs.php","privacy":"http://www.xe.com/privacy.php","from":"EUR","amount":55.0,"to":{"RUB":[{"mid":3388.9716501348,"timestamp":"2017-02-28T12:00:00Z"},{"mid":3365.0716562481,"timestamp":"2017-03-01T12:00:00Z"},{"mid":3388.0176650102,"timestamp":"2017-03-02T12:00:00Z"},{"mid":3413.1330139571,"timestamp":"2017-03-03T12:00:00Z"}]}},
13 |
14 | "fakeMonthlyAverage": {"terms":"http://www.xe.com/legal/dfs.php","privacy":"http://www.xe.com/privacy.php","from":"CAD","amount":55.0,"year":2017,"to":{"EUR":[{"monthlyAverage":36.5955301895,"month":5,"daysInMonth":31}]}}
15 | }
16 |
--------------------------------------------------------------------------------
/tests/test_integration.py:
--------------------------------------------------------------------------------
1 | from xecd_rates_client import XecdClient
2 | import unittest
3 | import os
4 |
5 |
6 | class XecdClientIntegrationTest(unittest.TestCase):
7 |
8 | def setUp(self):
9 | self.xecd = XecdClient(os.environ['XecdAccountID'], os.environ['XecdApiKey'])
10 |
11 | def testAccountInfo(self):
12 | response = self.xecd.account_info()
13 | self.assertIn('id', response)
14 | self.assertIn('organization', response)
15 | self.assertIn('package', response)
16 | self.assertIn('service_start_timestamp', response)
17 |
18 | def testCurrencies(self):
19 | response = self.xecd.currencies()
20 | self.assertIn('terms', response)
21 | self.assertIn('privacy', response)
22 | self.assertIn('currencies', response)
23 |
24 | def testConvertFrom(self):
25 | response = self.xecd.convert_from("EUR", "CAD", 55)
26 | self.assertIn('terms', response)
27 | self.assertIn('privacy', response)
28 | self.assertIn('from', response)
29 | self.assertIn('amount', response)
30 | self.assertIn('timestamp', response)
31 | self.assertIn('to', response)
32 |
33 | def testConvertTo(self):
34 | response = self.xecd.convert_to("RUB", "CAD", 55)
35 | self.assertIn('terms', response)
36 | self.assertIn('privacy', response)
37 | self.assertIn('to', response)
38 | self.assertIn('amount', response)
39 | self.assertIn('timestamp', response)
40 | self.assertIn('from', response)
41 |
42 | def testHistoricRate(self):
43 | response = self.xecd.historic_rate("2016-12-25", "12:34", "EUR", "CAD", 55)
44 | self.assertIn('terms', response)
45 | self.assertIn('privacy', response)
46 | self.assertIn('from', response)
47 | self.assertIn('amount', response)
48 | self.assertIn('timestamp', response)
49 | self.assertIn('to', response)
50 |
51 | def testHistoricRatePeriod(self):
52 | response = self.xecd.historic_rate_period(55, "EUR", "RUB", "2017-09-28T12:00", "2017-10-03T12:00")
53 | self.assertIn('terms', response)
54 | self.assertIn('privacy', response)
55 | self.assertIn('from', response)
56 | self.assertIn('amount', response)
57 | self.assertIn('to', response)
58 |
59 | def testMonthlyAverage(self):
60 | response = self.xecd.monthly_average(55, "CAD", "EUR", 2017, 5)
61 | self.assertIn('terms', response)
62 | self.assertIn('privacy', response)
63 | self.assertIn('from', response)
64 | self.assertIn('amount', response)
65 | self.assertIn('year', response)
66 | self.assertIn('to', response)
67 |
--------------------------------------------------------------------------------
/tests/test_unit.py:
--------------------------------------------------------------------------------
1 | from xecd_rates_client import XecdClient
2 | import unittest
3 | from unittest import mock
4 | import json
5 | import copy
6 | with open('tests/data/testdata.json') as json_data:
7 | data = json.load(json_data)
8 |
9 |
10 | class MockResponse:
11 | def __init__(self, json_data, status_code):
12 | self.json_data = copy.deepcopy(json_data)
13 | self.status_code = status_code
14 |
15 | def json(self):
16 | return self.json_data
17 |
18 |
19 | class XecdClientUnitTest(unittest.TestCase):
20 |
21 | def setUp(self):
22 | self.xecd = XecdClient('accountId', 'apiKey')
23 |
24 | @mock.patch('requests.get', return_value=MockResponse(data["fakeAccountInfo"], 200))
25 | def testAccountInfo(self, mock_get):
26 | self.assertEqual(data["fakeAccountInfo"], self.xecd.account_info())
27 |
28 | @mock.patch('requests.get', return_value=MockResponse(data["fakeCurrencies"], 200))
29 | def testCurrencies(self, mock_get):
30 | self.assertEqual(data["fakeCurrencies"], self.xecd.currencies())
31 |
32 | @mock.patch('requests.get', return_value=MockResponse(data["fakeConvertFrom"], 200))
33 | def testConvertFrom(self, mock_get):
34 | self.assertEqual(data["fakeConvertFrom"], self.xecd.convert_from("EUR", "CAD", 55))
35 |
36 | @mock.patch('requests.get', return_value=MockResponse(data["fakeConvertTo"], 200))
37 | def testConvertTo(self, mock_get):
38 | self.assertEqual(data["fakeConvertTo"], self.xecd.convert_to("RUB", "CAD", 55))
39 |
40 | @mock.patch('requests.get', return_value=MockResponse(data["fakeHistoricRate"], 200))
41 | def testHistoricRate(self, mock_get):
42 | self.assertEqual(data["fakeHistoricRate"], self.xecd.historic_rate("2016-12-25", "12:34", "EUR", "CAD", 55))
43 |
44 | @mock.patch('requests.get', return_value=MockResponse(data["fakeHistoricRatePeriod"], 200))
45 | def testHistoricRatePeriod(self, mock_get):
46 | self.assertEqual(data["fakeHistoricRatePeriod"], self.xecd.historic_rate_period(55, "EUR", "RUB", "2016-02-28T12:00", "2016-03-03T12:00"))
47 |
48 | @mock.patch('requests.get', return_value=MockResponse(data["fakeMonthlyAverage"], 200))
49 | def testMonthlyAverage(self, mock_get):
50 | self.assertEqual(data["fakeMonthlyAverage"], self.xecd.monthly_average(55, "CAD", "EUR", 2017, 5))
51 |
--------------------------------------------------------------------------------
/xecd_rates_client/XecdClient.py:
--------------------------------------------------------------------------------
1 | import requests
2 |
3 | class XecdClient(object):
4 | """XECD REST API Client"""
5 |
6 | def __init__(self, account_id, api_key, options = {}):
7 | self.options = {
8 | 'auth': {
9 | 'user': account_id,
10 | 'password': api_key
11 | },
12 | 'baseUrl': 'https://xecdapi.xe.com/v1/',
13 | 'qs': {}
14 | }
15 | self.options.update(options)
16 |
17 | self.accountInfoRequestUri = 'account_info.json'
18 | self.currenciesRequestUri = 'currencies.json'
19 | self.convertFromRequestUri = 'convert_from.json'
20 | self.convertToRequestUri = 'convert_to.json'
21 | self.historicRateRequestUri = 'historic_rate.json'
22 | self.historicRatePeriodRequestUri = 'historic_rate/period.json'
23 | self.monthlyAverageRequestUri = 'monthly_average.json'
24 |
25 | def __send(self, ops):
26 | self.options.update(ops)
27 | #cached for debugging purposes
28 | url = self.options["url"]
29 | username = self.options['auth']['user']
30 | password = self.options['auth']['password']
31 | qs = self.options['qs']
32 | temp = requests.get(url, auth=(username, password), params=qs)
33 | data = temp.json()
34 | return data
35 |
36 | def account_info(self, options = {}):
37 | ops = {
38 | 'url': self.options['baseUrl'] + self.accountInfoRequestUri
39 | }
40 | ops.update(options)
41 | return self.__send(ops)
42 |
43 | def currencies(self, obsolete = False, language = "en", iso = ['*'], options = {}):
44 | ops = {
45 | 'url': self.options['baseUrl'] + self.currenciesRequestUri,
46 | 'qs': {
47 | 'obsolete': True if obsolete else False,
48 | 'language': language,
49 | 'iso': ','.join(iso) #format: abc,def,ghi
50 | }
51 | }
52 | ops.update(options)
53 | return self.__send(ops)
54 |
55 | def convert_from(self, from_currency ="USD", to_currency ="*", amount = 1, obsolete = False, inverse = False, options = {}):
56 | ops = {
57 | 'url': self.options['baseUrl'] + self.convertFromRequestUri,
58 | 'qs': {
59 | 'from': from_currency,
60 | 'to': to_currency,
61 | 'amount': amount,
62 | 'obsolete': True if obsolete else False,
63 | 'inverse': True if inverse else False
64 | }
65 | }
66 | ops.update(options)
67 | return self.__send(ops)
68 |
69 | def convert_to(self, to_currency ="USD", from_currency ="*", amount = 1, obsolete = False, inverse = False, options = {}):
70 | ops = {
71 | 'url': self.options['baseUrl'] + self.convertToRequestUri,
72 | 'qs': {
73 | 'to': to_currency,
74 | 'from': from_currency,
75 | 'amount': amount,
76 | 'obsolete': True if obsolete else False,
77 | 'inverse': True if inverse else False
78 | }
79 | }
80 | ops.update(options)
81 | return self.__send(ops)
82 |
83 | def historic_rate(self, date, time, from_currency ="USD", to_currency ="*", amount = 1, obsolete = False, inverse = False, options = {}):
84 | ops = {
85 | 'url': self.options['baseUrl'] + self.historicRateRequestUri,
86 | 'qs': {
87 | 'from': from_currency,
88 | 'to': to_currency,
89 | 'amount': amount,
90 | 'date': date,
91 | 'time': time,
92 | 'obsolete': True if obsolete else False,
93 | 'inverse': True if inverse else False
94 | }
95 | }
96 | ops.update(options)
97 | return self.__send(ops)
98 |
99 | def historic_rate_period(self, amount = 1, from_currency ="USD", to_currency ="*", start_timestamp = None, end_timestamp = None, interval ="DAILY", obsolete = False, inverse = False, page = 1, per_page = 30, options = {}):
100 | ops = {
101 | 'url': self.options['baseUrl'] + self.historicRatePeriodRequestUri,
102 | 'qs': {
103 | 'from': from_currency,
104 | 'to': to_currency,
105 | 'amount': amount,
106 | 'start_timestamp': start_timestamp if (start_timestamp != None) else None,
107 | 'end_timestamp': end_timestamp if (end_timestamp != None) else None,
108 | 'interval': interval,
109 | 'obsolete': True if obsolete else False,
110 | 'inverse': True if inverse else False,
111 | 'page': page,
112 | 'per_page': per_page
113 |
114 | }
115 | }
116 | ops.update(options)
117 | return self.__send(ops)
118 |
119 | def monthly_average(self, amount = 1, from_currency ="USD", to_currency ="*", year = None, month = None, obsolete = False, inverse = False, options = {}):
120 | ops = {
121 | 'url': self.options['baseUrl'] + self.monthlyAverageRequestUri,
122 | 'qs': {
123 | 'from': from_currency,
124 | 'to': to_currency,
125 | 'amount': amount,
126 | 'year': year,
127 | 'month': month,
128 | 'obsolete': True if obsolete else False,
129 | 'inverse': True if inverse else False
130 | }
131 | }
132 | ops.update(options)
133 | return self.__send(ops)
134 |
--------------------------------------------------------------------------------
/xecd_rates_client/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | from xecd_rates_client.XecdClient import XecdClient
3 |
--------------------------------------------------------------------------------