Skip to content

Commit

Permalink
Merge pull request #95 from s4w3d0ff/dev
Browse files Browse the repository at this point in the history
chipping away at #16
  • Loading branch information
s4w3d0ff authored Apr 13, 2017
2 parents fc51a1a + 2bdd37d commit 917af2b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
9 changes: 6 additions & 3 deletions poloniex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ def __call__(self, command, args={}):
"""
Main Api Function
- encodes and sends <command> with optional [args] to Poloniex api
- raises 'ValueError' if an api key or secret is missing
(and the command is 'private'), or if the <command> is not valid
- raises 'poloniex.PoloniexError' if an api key or secret is missing
(and the command is 'private'), if the <command> is not valid, or
if an error is returned from poloniex.com
- returns decoded json api message
"""
global PUBLIC_COMMANDS, PRIVATE_COMMANDS
Expand Down Expand Up @@ -296,8 +297,10 @@ def returnBalances(self):
""" Returns coin balances """
return self.__call__('returnBalances')

def returnAvailableAccountBalances(self):
def returnAvailableAccountBalances(self, account=False):
""" Returns available account balances """
if account:
return self.__call__('returnAvailableAccountBalances', {'account': account})
return self.__call__('returnAvailableAccountBalances')

def returnMarginAccountSummary(self):
Expand Down
42 changes: 42 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import poloniex
import unittest


class TestPolo(unittest.TestCase):

def test_method_integrity(self):
self.polo = poloniex.Poloniex()
for command in poloniex.PUBLIC_COMMANDS:
self.assertTrue(hasattr(self.polo, command))
for command in poloniex.PRIVATE_COMMANDS:
self.assertTrue(hasattr(self.polo, command))
self.assertTrue(hasattr(self.polo, 'marketTradeHist'))

def test_coach_existance(self):
self.polo = poloniex.Poloniex()
# coach is created by default
self.assertTrue(isinstance(self.polo.coach, poloniex.Coach))
# remove coach
self.polo = poloniex.Poloniex(coach=False)
self.assertFalse(self.polo.coach)
# coach injection
myCoach = poloniex.Coach()
self.polo = poloniex.Poloniex(coach=myCoach)
self.polo2 = poloniex.Poloniex(coach=myCoach)
self.assertTrue(self.polo.coach is self.polo2.coach)

def test_PoloniexErrors(self):
self.polo = poloniex.Poloniex()
# no keys, private command
with self.assertRaises(poloniex.PoloniexError):
self.polo.returnBalances()
# invalid command
with self.assertRaises(poloniex.PoloniexError):
self.polo('foo')
# catch errors returned from poloniex.com
with self.assertRaises(poloniex.PoloniexError):
self.polo.returnOrderBook(pair='atestfoo')


if __name__ == '__main__':
unittest.main()

0 comments on commit 917af2b

Please sign in to comment.