Skip to content

Commit

Permalink
Parameter names + unittests + doc
Browse files Browse the repository at this point in the history
  • Loading branch information
hootnot committed Nov 13, 2016
1 parent 53f741c commit 82b4b5d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 32 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Contents:
modules
oandapyV20.endpoints
oandapyV20.definitions
oandapyV20.types
oandapyV20

examples
Expand Down
9 changes: 9 additions & 0 deletions docs/oandapyV20.types.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
oandapyV20.types
================

.. automodule:: oandapyV20.types
:members:
:undoc-members:
:inherited-members:
.. ..:show-inheritance:
:special-members: __init__
64 changes: 47 additions & 17 deletions oandapyV20/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,83 @@ def value(self):


class OrderID(OAType):
"""representation of an orderID, string value of an integer."""
"""representation of an orderID, string value of an integer.
def __init__(self, v):
if int(v) < 0:
Parameters
----------
orderID : integer or string (required)
the orderID as a positive integer or as a string
Example
-------
>>> print OrderID(1234).value
A ValueError exception is raised in case of a negative integer value
"""

def __init__(self, orderID):
if int(orderID) < 0:
raise ValueError("OrderID must be a positive integer value")
self._v = "{:d}".format(int(v))
self._v = "{:d}".format(int(orderID))


class TradeID(OAType):
"""representation of a tradeID, string value of an integer."""
"""representation of a tradeID, string value of an integer.
Parameters
----------
tradeID : integer or string (required)
the tradeID as a positive integer or as a string
Example
-------
>>> print TradeID(1234).value
A ValueError exception is raised in case of a negative integer value
"""

def __init__(self, v):
if int(v) < 0:
def __init__(self, tradeID):
if int(tradeID) < 0:
raise ValueError("TradeID must be a positive integer value")
self._v = "{:d}".format(int(v))
self._v = "{:d}".format(int(tradeID))


class AccountUnits(OAType):
"""representation AccountUnits, string value of a float."""

def __init__(self, v):
self._v = "{:.5f}".format(float(v))
def __init__(self, units):
self._v = "{:.5f}".format(float(units))


class PriceValue(OAType):
"""representation PriceValue, string value of a float."""

def __init__(self, v):
self._v = "{:.5f}".format(float(v))
def __init__(self, priceValue):
self._v = "{:.5f}".format(float(priceValue))


class Units(OAType):
"""representation Units, string value of an integer."""

def __init__(self, v):
self._v = "{:d}".format(int(v))
def __init__(self, units):
self._v = "{:d}".format(int(units))


class ClientID(OAType):
"""representation of ClientID, a string value of max 128 chars."""

def __init__(self, v):
length = len(v)
def __init__(self, clientID):
length = len(clientID)
if not length or length > 128:
raise ValueError("ClientID: length {}".format(length))

self._v = v
self._v = clientID


class OrderIdentifier(OAType):
Expand Down
30 changes: 15 additions & 15 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,66 @@ class TestTypes(unittest.TestCase):
@parameterized.expand([
# OrderID
(tp.OrderID,
{"v": "1234"},
{"orderID": "1234"},
"1234",
),
(tp.OrderID,
{"v": 1234},
{"orderID": 1234},
"1234",
),
(tp.OrderID,
{"v": -1234},
{"orderID": -1234},
"1234",
ValueError
),
# OrderID
# TradeID
(tp.TradeID,
{"v": "1234"},
{"tradeID": "1234"},
"1234",
),
(tp.TradeID,
{"v": 1234},
{"tradeID": 1234},
"1234",
),
(tp.TradeID,
{"v": -1234},
{"tradeID": -1234},
"1234",
ValueError
),
# AccountUnits
(tp.AccountUnits,
{"v": 1234},
{"units": 1234},
"1234.00000",
),
(tp.AccountUnits,
{"v": "1234"},
{"units": "1234"},
"1234.00000",
),
# PriceValue
(tp.PriceValue,
{"v": 1234},
{"priceValue": 1234},
"1234.00000",
),
(tp.PriceValue,
{"v": "1234"},
{"priceValue": "1234"},
"1234.00000",
),
# Units
(tp.Units,
{"v": 1234},
{"units": 1234},
"1234",
),
(tp.Units,
{"v": "-1234"},
{"units": "-1234"},
"-1234",
),
# ClientID
(tp.ClientID,
{"v": "my valid custom id"},
{"clientID": "my valid custom id"},
"my valid custom id"
),
(tp.ClientID,
{"v": "to long"+"x"*125},
{"clientID": "to long"+"x"*125},
"to long"+"x"*125,
ValueError
),
Expand Down

0 comments on commit 82b4b5d

Please sign in to comment.