Skip to content

Commit

Permalink
Auto-generated v20 API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
HerbSears-OANDA committed Oct 13, 2016
1 parent aadbf39 commit a276e8b
Show file tree
Hide file tree
Showing 12 changed files with 824 additions and 239 deletions.
10 changes: 10 additions & 0 deletions src/ChangeLog
@@ -1,5 +1,15 @@
OANDA v20 API Change Log

Version 3.0.3 (August 25, 2016)

* Added support for Pricing and Transaction streaming endpoints.

* Deprecated "includeUnitsAvailable" for REST pricing endpoint.

* Deprecated "quoteHomeConversionFactors" and "unitsAvailable" for
the Price object.


Version 3.0.2 (August 02, 2016)

* Added support for Python 3.5
Expand Down
2 changes: 1 addition & 1 deletion src/setup.py
Expand Up @@ -25,7 +25,7 @@ def main():
# setup dictionary
setup_options = {
"name": "v20",
"version": "3.0.2.1",
"version": "3.0.3.8",
"description": "OANDA v20 bindings for Python",
"long_description": read("README.rst"),
"author": "OANDA Corporation",
Expand Down
37 changes: 11 additions & 26 deletions src/v20/__init__.py
@@ -1,6 +1,7 @@
import requests
from v20 import account
from v20 import transaction
from v20 import user
from v20 import trade
from v20 import pricing
from v20 import position
Expand All @@ -21,16 +22,23 @@ def __str__(self):
)

class Context(object):
def __init__(self, hostname, port, ssl=False):
def __init__(self, hostname, port, ssl=False, application=""):
"""Create an API context for a specific host/port"""

# Currnet username for the context
self.username = None

extensions = ""

if application != "":
extensions = " ({})".format(application)

# Context headers to add to every request sent to the server
self._headers = {
"Content-Type" : "application/json",
"User-Agent" : "OANDA/3.0.2 (client; python)"
"OANDA-Agent" : "v20-python/3.0.3{}".format(
extensions
)
}

# Current authentication token
Expand All @@ -51,35 +59,12 @@ def __init__(self, hostname, port, ssl=False):

self.account = account.EntitySpec(self)
self.transaction = transaction.EntitySpec(self)
self.user = user.EntitySpec(self)
self.trade = trade.EntitySpec(self)
self.pricing = pricing.EntitySpec(self)
self.position = position.EntitySpec(self)
self.order = order.EntitySpec(self)

def authenticate(self, username, password):
"""Log in using a username and password. Store the authorization token
and fetch the list of Accounts accessible for that token"""

response = self.authorization.login(
username=username,
password=password
)

if response.status != 200:
raise AuthenticationError(
username,
response.status,
response.reason
)

self.set_token(response.body.get("token"))

self.username = username

response = self.account.list()

self.token_account_ids = response.body.get("accounts")

def set_token(self, token):
self.token = token

Expand Down
55 changes: 29 additions & 26 deletions src/v20/account.py
Expand Up @@ -1357,15 +1357,15 @@ def list(

parsed_body = {}

if response.status is 200:
if str(response.status) == "200":
if jbody.get('accounts') is not None:
parsed_body['accounts'] = [
AccountProperties.from_dict(d)
for d in jbody.get('accounts')
]


if response.status is 401:
if str(response.status) == "401":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand All @@ -1375,7 +1375,7 @@ def list(
jbody.get('errorMessage')


if response.status is 405:
if str(response.status) == "405":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand Down Expand Up @@ -1431,7 +1431,7 @@ def get(

parsed_body = {}

if response.status is 200:
if str(response.status) == "200":
if jbody.get('account') is not None:
parsed_body['account'] = \
Account.from_dict(
Expand All @@ -1443,7 +1443,7 @@ def get(
jbody.get('lastTransactionID')


if response.status is 401:
if str(response.status) == "401":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand All @@ -1453,7 +1453,7 @@ def get(
jbody.get('errorMessage')


if response.status is 404:
if str(response.status) == "404":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand All @@ -1463,7 +1463,7 @@ def get(
jbody.get('errorMessage')


if response.status is 405:
if str(response.status) == "405":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand Down Expand Up @@ -1517,7 +1517,7 @@ def summary(

parsed_body = {}

if response.status is 200:
if str(response.status) == "200":
if jbody.get('account') is not None:
parsed_body['account'] = \
AccountSummary.from_dict(
Expand All @@ -1529,7 +1529,7 @@ def summary(
jbody.get('lastTransactionID')


if response.status is 401:
if str(response.status) == "401":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand All @@ -1539,7 +1539,7 @@ def summary(
jbody.get('errorMessage')


if response.status is 404:
if str(response.status) == "404":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand All @@ -1549,7 +1549,7 @@ def summary(
jbody.get('errorMessage')


if response.status is 405:
if str(response.status) == "405":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand All @@ -1571,7 +1571,10 @@ def instruments(
):
"""Account Instruments
Get the list of tradeable instruments for the given Account.
Get the list of tradeable instruments for the given Account. The list
of tradeable instruments is dependent on the regulatory division that
the Account is located in, thus should be the same for all Accounts
owned by a single user.
Parameters
----------
Expand Down Expand Up @@ -1610,15 +1613,15 @@ def instruments(

parsed_body = {}

if response.status is 200:
if str(response.status) == "200":
if jbody.get('instruments') is not None:
parsed_body['instruments'] = [
primitives.Instrument.from_dict(d)
for d in jbody.get('instruments')\
]


if response.status is 401:
if str(response.status) == "401":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand All @@ -1628,7 +1631,7 @@ def instruments(
jbody.get('errorMessage')


if response.status is 404:
if str(response.status) == "404":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand All @@ -1638,7 +1641,7 @@ def instruments(
jbody.get('errorMessage')


if response.status is 405:
if str(response.status) == "405":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand Down Expand Up @@ -1704,7 +1707,7 @@ def configure(

parsed_body = {}

if response.status is 200:
if str(response.status) == "200":
if jbody.get('configureTransaction') is not None:
parsed_body['configureTransaction'] = \
transaction.ClientConfigureTransaction.from_dict(
Expand All @@ -1716,7 +1719,7 @@ def configure(
jbody.get('lastTransactionID')


if response.status is 400:
if str(response.status) == "400":
if jbody.get('configureRejectTransaction') is not None:
parsed_body['configureRejectTransaction'] = \
transaction.ClientConfigureRejectTransaction.from_dict(
Expand All @@ -1736,7 +1739,7 @@ def configure(
jbody.get('errorMessage')


if response.status is 401:
if str(response.status) == "401":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand All @@ -1746,7 +1749,7 @@ def configure(
jbody.get('errorMessage')


if response.status is 404:
if str(response.status) == "404":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand All @@ -1756,7 +1759,7 @@ def configure(
jbody.get('errorMessage')


if response.status is 405:
if str(response.status) == "405":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand Down Expand Up @@ -1818,7 +1821,7 @@ def changes(

parsed_body = {}

if response.status is 200:
if str(response.status) == "200":
if jbody.get('changes') is not None:
parsed_body['changes'] = \
AccountChanges.from_dict(
Expand All @@ -1836,7 +1839,7 @@ def changes(
jbody.get('lastTransactionID')


if response.status is 401:
if str(response.status) == "401":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand All @@ -1846,7 +1849,7 @@ def changes(
jbody.get('errorMessage')


if response.status is 404:
if str(response.status) == "404":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand All @@ -1856,7 +1859,7 @@ def changes(
jbody.get('errorMessage')


if response.status is 405:
if str(response.status) == "405":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand All @@ -1866,7 +1869,7 @@ def changes(
jbody.get('errorMessage')


if response.status is 416:
if str(response.status) == "416":
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
Expand Down

0 comments on commit a276e8b

Please sign in to comment.