diff options
Diffstat (limited to 'test.py')
-rw-r--r-- | test.py | 81 |
1 files changed, 81 insertions, 0 deletions
@@ -46,6 +46,87 @@ class WebMockTestCase(unittest.TestCase): | |||
46 | super(WebMockTestCase, self).tearDown() | 46 | super(WebMockTestCase, self).tearDown() |
47 | 47 | ||
48 | @unittest.skipUnless("unit" in limits, "Unit skipped") | 48 | @unittest.skipUnless("unit" in limits, "Unit skipped") |
49 | class poloniexETest(unittest.TestCase): | ||
50 | def setUp(self): | ||
51 | super(poloniexETest, self).setUp() | ||
52 | self.wm = requests_mock.Mocker() | ||
53 | self.wm.start() | ||
54 | |||
55 | self.s = market.ccxt.poloniexE() | ||
56 | |||
57 | def tearDown(self): | ||
58 | self.wm.stop() | ||
59 | super(poloniexETest, self).tearDown() | ||
60 | |||
61 | def test_nanoseconds(self): | ||
62 | with mock.patch.object(market.ccxt.time, "time") as time: | ||
63 | time.return_value = 123456.7890123456 | ||
64 | self.assertEqual(123456789012345, self.s.nanoseconds()) | ||
65 | |||
66 | def test_nonce(self): | ||
67 | with mock.patch.object(market.ccxt.time, "time") as time: | ||
68 | time.return_value = 123456.7890123456 | ||
69 | self.assertEqual(123456789012345, self.s.nonce()) | ||
70 | |||
71 | def test_order_precision(self): | ||
72 | self.assertEqual(8, self.s.order_precision("FOO")) | ||
73 | |||
74 | def test_transfer_balance(self): | ||
75 | with self.subTest(success=True),\ | ||
76 | mock.patch.object(self.s, "privatePostTransferBalance") as t: | ||
77 | t.return_value = { "success": 1 } | ||
78 | result = self.s.transfer_balance("FOO", 12, "exchange", "margin") | ||
79 | t.assert_called_once_with({ | ||
80 | "currency": "FOO", | ||
81 | "amount": 12, | ||
82 | "fromAccount": "exchange", | ||
83 | "toAccount": "margin", | ||
84 | "confirmed": 1 | ||
85 | }) | ||
86 | self.assertTrue(result) | ||
87 | |||
88 | with self.subTest(success=False),\ | ||
89 | mock.patch.object(self.s, "privatePostTransferBalance") as t: | ||
90 | t.return_value = { "success": 0 } | ||
91 | self.assertFalse(self.s.transfer_balance("FOO", 12, "exchange", "margin")) | ||
92 | |||
93 | def test_close_margin_position(self): | ||
94 | with mock.patch.object(self.s, "privatePostCloseMarginPosition") as c: | ||
95 | self.s.close_margin_position("FOO", "BAR") | ||
96 | c.assert_called_with({"currencyPair": "BAR_FOO"}) | ||
97 | |||
98 | def test_tradable_balances(self): | ||
99 | with mock.patch.object(self.s, "privatePostReturnTradableBalances") as r: | ||
100 | r.return_value = { | ||
101 | "FOO": { "exchange": "12.1234", "margin": "0.0123" }, | ||
102 | "BAR": { "exchange": "1", "margin": "0" }, | ||
103 | } | ||
104 | balances = self.s.tradable_balances() | ||
105 | self.assertEqual(["FOO", "BAR"], list(balances.keys())) | ||
106 | self.assertEqual(["exchange", "margin"], list(balances["FOO"].keys())) | ||
107 | self.assertEqual(D("12.1234"), balances["FOO"]["exchange"]) | ||
108 | self.assertEqual(["exchange", "margin"], list(balances["BAR"].keys())) | ||
109 | |||
110 | def test_margin_summary(self): | ||
111 | with mock.patch.object(self.s, "privatePostReturnMarginAccountSummary") as r: | ||
112 | r.return_value = { | ||
113 | "currentMargin": "1.49680968", | ||
114 | "lendingFees": "0.0000001", | ||
115 | "pl": "0.00008254", | ||
116 | "totalBorrowedValue": "0.00673602", | ||
117 | "totalValue": "0.01000000", | ||
118 | "netValue": "0.01008254", | ||
119 | } | ||
120 | expected = { | ||
121 | 'current_margin': D('1.49680968'), | ||
122 | 'gains': D('0.00008254'), | ||
123 | 'lending_fees': D('0.0000001'), | ||
124 | 'total': D('0.01000000'), | ||
125 | 'total_borrowed': D('0.00673602') | ||
126 | } | ||
127 | self.assertEqual(expected, self.s.margin_summary()) | ||
128 | |||
129 | @unittest.skipUnless("unit" in limits, "Unit skipped") | ||
49 | class PortfolioTest(WebMockTestCase): | 130 | class PortfolioTest(WebMockTestCase): |
50 | def fill_data(self): | 131 | def fill_data(self): |
51 | if self.json_response is not None: | 132 | if self.json_response is not None: |