]>
Commit | Line | Data |
---|---|---|
dd359bc0 IB |
1 | import portfolio |
2 | import unittest | |
5ab23e1c | 3 | from decimal import Decimal as D |
dd359bc0 IB |
4 | from unittest import mock |
5 | ||
6 | class AmountTest(unittest.TestCase): | |
dd359bc0 | 7 | def test_values(self): |
5ab23e1c IB |
8 | amount = portfolio.Amount("BTC", "0.65") |
9 | self.assertEqual(D("0.65"), amount.value) | |
dd359bc0 IB |
10 | self.assertEqual("BTC", amount.currency) |
11 | ||
dd359bc0 IB |
12 | def test_in_currency(self): |
13 | amount = portfolio.Amount("ETC", 10) | |
14 | ||
15 | self.assertEqual(amount, amount.in_currency("ETC", None)) | |
16 | ||
17 | ticker_mock = unittest.mock.Mock() | |
cfab619d | 18 | with mock.patch.object(portfolio.Trade, 'get_ticker', new=ticker_mock): |
dd359bc0 | 19 | ticker_mock.return_value = None |
dd359bc0 IB |
20 | |
21 | self.assertRaises(Exception, amount.in_currency, "ETH", None) | |
22 | ||
cfab619d | 23 | with mock.patch.object(portfolio.Trade, 'get_ticker', new=ticker_mock): |
dd359bc0 | 24 | ticker_mock.return_value = { |
deb8924c IB |
25 | "bid": D("0.2"), |
26 | "ask": D("0.4"), | |
5ab23e1c | 27 | "average": D("0.3"), |
dd359bc0 IB |
28 | "foo": "bar", |
29 | } | |
30 | converted_amount = amount.in_currency("ETH", None) | |
31 | ||
5ab23e1c | 32 | self.assertEqual(D("3.0"), converted_amount.value) |
dd359bc0 IB |
33 | self.assertEqual("ETH", converted_amount.currency) |
34 | self.assertEqual(amount, converted_amount.linked_to) | |
35 | self.assertEqual("bar", converted_amount.ticker["foo"]) | |
36 | ||
deb8924c IB |
37 | converted_amount = amount.in_currency("ETH", None, action="bid", compute_value="default") |
38 | self.assertEqual(D("2"), converted_amount.value) | |
39 | ||
40 | converted_amount = amount.in_currency("ETH", None, compute_value="ask") | |
41 | self.assertEqual(D("4"), converted_amount.value) | |
42 | ||
c2644ba8 IB |
43 | converted_amount = amount.in_currency("ETH", None, rate=D("0.02")) |
44 | self.assertEqual(D("0.2"), converted_amount.value) | |
45 | ||
dd359bc0 IB |
46 | def test__abs(self): |
47 | amount = portfolio.Amount("SC", -120) | |
48 | self.assertEqual(120, abs(amount).value) | |
49 | self.assertEqual("SC", abs(amount).currency) | |
50 | ||
51 | amount = portfolio.Amount("SC", 10) | |
52 | self.assertEqual(10, abs(amount).value) | |
53 | self.assertEqual("SC", abs(amount).currency) | |
54 | ||
55 | def test__add(self): | |
5ab23e1c IB |
56 | amount1 = portfolio.Amount("XVG", "12.9") |
57 | amount2 = portfolio.Amount("XVG", "13.1") | |
dd359bc0 IB |
58 | |
59 | self.assertEqual(26, (amount1 + amount2).value) | |
60 | self.assertEqual("XVG", (amount1 + amount2).currency) | |
61 | ||
5ab23e1c | 62 | amount3 = portfolio.Amount("ETH", "1.6") |
dd359bc0 IB |
63 | with self.assertRaises(Exception): |
64 | amount1 + amount3 | |
65 | ||
66 | amount4 = portfolio.Amount("ETH", 0.0) | |
67 | self.assertEqual(amount1, amount1 + amount4) | |
68 | ||
69 | def test__radd(self): | |
5ab23e1c | 70 | amount = portfolio.Amount("XVG", "12.9") |
dd359bc0 IB |
71 | |
72 | self.assertEqual(amount, 0 + amount) | |
73 | with self.assertRaises(Exception): | |
74 | 4 + amount | |
75 | ||
76 | def test__sub(self): | |
5ab23e1c IB |
77 | amount1 = portfolio.Amount("XVG", "13.3") |
78 | amount2 = portfolio.Amount("XVG", "13.1") | |
dd359bc0 | 79 | |
5ab23e1c | 80 | self.assertEqual(D("0.2"), (amount1 - amount2).value) |
dd359bc0 IB |
81 | self.assertEqual("XVG", (amount1 - amount2).currency) |
82 | ||
5ab23e1c | 83 | amount3 = portfolio.Amount("ETH", "1.6") |
dd359bc0 IB |
84 | with self.assertRaises(Exception): |
85 | amount1 - amount3 | |
86 | ||
87 | amount4 = portfolio.Amount("ETH", 0.0) | |
88 | self.assertEqual(amount1, amount1 - amount4) | |
89 | ||
dd359bc0 IB |
90 | def test__mul(self): |
91 | amount = portfolio.Amount("XEM", 11) | |
92 | ||
5ab23e1c IB |
93 | self.assertEqual(D("38.5"), (amount * D("3.5")).value) |
94 | self.assertEqual(D("33"), (amount * 3).value) | |
dd359bc0 IB |
95 | |
96 | with self.assertRaises(Exception): | |
97 | amount * amount | |
98 | ||
99 | def test__rmul(self): | |
100 | amount = portfolio.Amount("XEM", 11) | |
101 | ||
5ab23e1c IB |
102 | self.assertEqual(D("38.5"), (D("3.5") * amount).value) |
103 | self.assertEqual(D("33"), (3 * amount).value) | |
dd359bc0 IB |
104 | |
105 | def test__floordiv(self): | |
106 | amount = portfolio.Amount("XEM", 11) | |
107 | ||
5ab23e1c IB |
108 | self.assertEqual(D("5.5"), (amount / 2).value) |
109 | self.assertEqual(D("4.4"), (amount / D("2.5")).value) | |
dd359bc0 IB |
110 | |
111 | def test__div(self): | |
112 | amount = portfolio.Amount("XEM", 11) | |
113 | ||
5ab23e1c IB |
114 | self.assertEqual(D("5.5"), (amount / 2).value) |
115 | self.assertEqual(D("4.4"), (amount / D("2.5")).value) | |
dd359bc0 IB |
116 | |
117 | def test__lt(self): | |
118 | amount1 = portfolio.Amount("BTD", 11.3) | |
119 | amount2 = portfolio.Amount("BTD", 13.1) | |
120 | ||
121 | self.assertTrue(amount1 < amount2) | |
122 | self.assertFalse(amount2 < amount1) | |
123 | self.assertFalse(amount1 < amount1) | |
124 | ||
125 | amount3 = portfolio.Amount("BTC", 1.6) | |
126 | with self.assertRaises(Exception): | |
127 | amount1 < amount3 | |
128 | ||
129 | def test__eq(self): | |
130 | amount1 = portfolio.Amount("BTD", 11.3) | |
131 | amount2 = portfolio.Amount("BTD", 13.1) | |
132 | amount3 = portfolio.Amount("BTD", 11.3) | |
133 | ||
134 | self.assertFalse(amount1 == amount2) | |
135 | self.assertFalse(amount2 == amount1) | |
136 | self.assertTrue(amount1 == amount3) | |
137 | self.assertFalse(amount2 == 0) | |
138 | ||
139 | amount4 = portfolio.Amount("BTC", 1.6) | |
140 | with self.assertRaises(Exception): | |
141 | amount1 == amount4 | |
142 | ||
143 | amount5 = portfolio.Amount("BTD", 0) | |
144 | self.assertTrue(amount5 == 0) | |
145 | ||
146 | def test__str(self): | |
147 | amount1 = portfolio.Amount("BTX", 32) | |
148 | self.assertEqual("32.00000000 BTX", str(amount1)) | |
149 | ||
150 | amount2 = portfolio.Amount("USDT", 12000) | |
151 | amount1.linked_to = amount2 | |
152 | self.assertEqual("32.00000000 BTX [12000.00000000 USDT]", str(amount1)) | |
153 | ||
154 | def test__repr(self): | |
155 | amount1 = portfolio.Amount("BTX", 32) | |
156 | self.assertEqual("Amount(32.00000000 BTX)", repr(amount1)) | |
157 | ||
158 | amount2 = portfolio.Amount("USDT", 12000) | |
159 | amount1.linked_to = amount2 | |
160 | self.assertEqual("Amount(32.00000000 BTX -> Amount(12000.00000000 USDT))", repr(amount1)) | |
161 | ||
162 | amount3 = portfolio.Amount("BTC", 0.1) | |
163 | amount2.linked_to = amount3 | |
164 | self.assertEqual("Amount(32.00000000 BTX -> Amount(12000.00000000 USDT -> Amount(0.10000000 BTC)))", repr(amount1)) | |
165 | ||
183a53e3 IB |
166 | class PortfolioTest(unittest.TestCase): |
167 | import urllib3 | |
168 | def fill_data(self): | |
169 | if self.json_response is not None: | |
170 | portfolio.Portfolio.data = self.json_response | |
171 | ||
172 | def setUp(self): | |
173 | super(PortfolioTest, self).setUp() | |
174 | ||
175 | with open("test_portfolio.json") as example: | |
176 | import json | |
177 | self.json_response = json.load(example) | |
178 | ||
179 | self.patcher = mock.patch.multiple(portfolio.Portfolio, data=None, liquidities={}) | |
180 | self.patcher.start() | |
181 | ||
182 | @mock.patch.object(urllib3, "disable_warnings") | |
183 | @mock.patch.object(urllib3.poolmanager.PoolManager, "request") | |
184 | @mock.patch.object(portfolio.Portfolio, "URL", new="foo://bar") | |
185 | def test_get_cryptoportfolio(self, request, disable_warnings): | |
186 | request.side_effect = [ | |
187 | type('', (), { "data": '{ "foo": "bar" }' }), | |
188 | type('', (), { "data": 'System Error' }), | |
189 | Exception("Connection error"), | |
190 | ] | |
191 | ||
192 | portfolio.Portfolio.get_cryptoportfolio() | |
193 | self.assertIn("foo", portfolio.Portfolio.data) | |
194 | self.assertEqual("bar", portfolio.Portfolio.data["foo"]) | |
195 | request.assert_called_with("GET", "foo://bar") | |
196 | ||
197 | request.reset_mock() | |
198 | portfolio.Portfolio.get_cryptoportfolio() | |
199 | self.assertIsNone(portfolio.Portfolio.data) | |
200 | request.assert_called_with("GET", "foo://bar") | |
201 | ||
202 | request.reset_mock() | |
203 | portfolio.Portfolio.data = "foo" | |
204 | portfolio.Portfolio.get_cryptoportfolio() | |
205 | request.assert_called_with("GET", "foo://bar") | |
206 | self.assertEqual("foo", portfolio.Portfolio.data) | |
207 | disable_warnings.assert_called_with() | |
208 | ||
209 | @mock.patch.object(portfolio.Portfolio, "get_cryptoportfolio") | |
210 | def test_parse_cryptoportfolio(self, mock_get): | |
211 | mock_get.side_effect = self.fill_data | |
212 | ||
213 | portfolio.Portfolio.parse_cryptoportfolio() | |
214 | ||
215 | self.assertListEqual( | |
216 | ["medium", "high"], | |
217 | list(portfolio.Portfolio.liquidities.keys())) | |
218 | ||
219 | liquidities = portfolio.Portfolio.liquidities | |
220 | self.assertEqual(10, len(liquidities["medium"].keys())) | |
221 | self.assertEqual(10, len(liquidities["high"].keys())) | |
222 | ||
223 | expected = {'BTC': 2857, 'DGB': 1015, 'DOGE': 1805, 'SC': 623, 'ZEC': 3701} | |
224 | self.assertDictEqual(expected, liquidities["high"]['2018-01-08']) | |
225 | ||
226 | expected = {'ETC': 1000, 'FCT': 1000, 'GAS': 1000, 'NAV': 1000, 'OMG': 1000, 'OMNI': 1000, 'PPC': 1000, 'RIC': 1000, 'VIA': 1000, 'XCP': 1000} | |
227 | self.assertDictEqual(expected, liquidities["medium"]['2018-01-08']) | |
228 | ||
229 | # It doesn't refetch the data when available | |
230 | portfolio.Portfolio.parse_cryptoportfolio() | |
231 | mock_get.assert_called_once_with() | |
232 | ||
233 | portfolio.Portfolio.data["portfolio_1"]["holding"]["direction"][3] = "short" | |
234 | self.assertRaises(AssertionError, portfolio.Portfolio.parse_cryptoportfolio) | |
235 | ||
236 | @mock.patch.object(portfolio.Portfolio, "get_cryptoportfolio") | |
237 | def test_repartition_pertenthousand(self, mock_get): | |
238 | mock_get.side_effect = self.fill_data | |
239 | ||
240 | expected_medium = {'USDT': 1000, 'ETC': 1000, 'FCT': 1000, 'OMG': 1000, 'STEEM': 1000, 'STRAT': 1000, 'XEM': 1000, 'XMR': 1000, 'XVC': 1000, 'ZRX': 1000} | |
241 | expected_high = {'USDT': 1226, 'BTC': 1429, 'ETC': 1127, 'ETH': 1569, 'FCT': 3341, 'GAS': 1308} | |
242 | ||
243 | self.assertEqual(expected_medium, portfolio.Portfolio.repartition_pertenthousand()) | |
244 | self.assertEqual(expected_medium, portfolio.Portfolio.repartition_pertenthousand(liquidity="medium")) | |
245 | self.assertEqual(expected_high, portfolio.Portfolio.repartition_pertenthousand(liquidity="high")) | |
246 | ||
247 | def tearDown(self): | |
248 | self.patcher.stop() | |
249 | ||
f2da6589 IB |
250 | class BalanceTest(unittest.TestCase): |
251 | def setUp(self): | |
252 | super(BalanceTest, self).setUp() | |
253 | ||
254 | self.fetch_balance = { | |
255 | "free": "foo", | |
256 | "info": "bar", | |
257 | "used": "baz", | |
258 | "total": "bazz", | |
259 | "USDT": { | |
260 | "free": 6.0, | |
261 | "used": 1.2, | |
262 | "total": 7.2 | |
263 | }, | |
264 | "XVG": { | |
265 | "free": 16, | |
266 | "used": 0.0, | |
267 | "total": 16 | |
268 | }, | |
269 | "XMR": { | |
270 | "free": 0.0, | |
271 | "used": 0.0, | |
272 | "total": 0.0 | |
273 | }, | |
274 | } | |
cfab619d | 275 | self.patcher = mock.patch.multiple(portfolio.Balance, known_balances={}) |
f2da6589 IB |
276 | self.patcher.start() |
277 | ||
278 | def test_values(self): | |
279 | balance = portfolio.Balance("BTC", 0.65, 0.35, 0.30) | |
280 | self.assertEqual(0.65, balance.total.value) | |
281 | self.assertEqual(0.35, balance.free.value) | |
282 | self.assertEqual(0.30, balance.used.value) | |
283 | self.assertEqual("BTC", balance.currency) | |
284 | ||
285 | balance = portfolio.Balance.from_hash("BTC", { "total": 0.65, "free": 0.35, "used": 0.30}) | |
286 | self.assertEqual(0.65, balance.total.value) | |
287 | self.assertEqual(0.35, balance.free.value) | |
288 | self.assertEqual(0.30, balance.used.value) | |
289 | self.assertEqual("BTC", balance.currency) | |
290 | ||
cfab619d | 291 | @mock.patch.object(portfolio.Trade, "get_ticker") |
f2da6589 IB |
292 | def test_in_currency(self, get_ticker): |
293 | portfolio.Balance.known_balances = { | |
5ab23e1c | 294 | "BTC": portfolio.Balance("BTC", "0.65", "0.35", "0.30"), |
f2da6589 IB |
295 | "ETH": portfolio.Balance("ETH", 3, 3, 0), |
296 | } | |
297 | market = mock.Mock() | |
298 | get_ticker.return_value = { | |
5ab23e1c IB |
299 | "bid": D("0.09"), |
300 | "ask": D("0.11"), | |
301 | "average": D("0.1"), | |
f2da6589 IB |
302 | } |
303 | ||
304 | amounts = portfolio.Balance.in_currency("BTC", market) | |
305 | self.assertEqual("BTC", amounts["ETH"].currency) | |
5ab23e1c IB |
306 | self.assertEqual(D("0.65"), amounts["BTC"].value) |
307 | self.assertEqual(D("0.30"), amounts["ETH"].value) | |
f2da6589 | 308 | |
deb8924c | 309 | amounts = portfolio.Balance.in_currency("BTC", market, compute_value="bid") |
5ab23e1c IB |
310 | self.assertEqual(D("0.65"), amounts["BTC"].value) |
311 | self.assertEqual(D("0.27"), amounts["ETH"].value) | |
f2da6589 | 312 | |
deb8924c | 313 | amounts = portfolio.Balance.in_currency("BTC", market, compute_value="bid", type="used") |
5ab23e1c | 314 | self.assertEqual(D("0.30"), amounts["BTC"].value) |
f2da6589 IB |
315 | self.assertEqual(0, amounts["ETH"].value) |
316 | ||
317 | def test_currencies(self): | |
318 | portfolio.Balance.known_balances = { | |
5ab23e1c | 319 | "BTC": portfolio.Balance("BTC", "0.65", "0.35", "0.30"), |
f2da6589 IB |
320 | "ETH": portfolio.Balance("ETH", 3, 3, 0), |
321 | } | |
322 | self.assertListEqual(["BTC", "ETH"], list(portfolio.Balance.currencies())) | |
323 | ||
324 | @mock.patch.object(portfolio.market, "fetch_balance") | |
325 | def test_fetch_balances(self, fetch_balance): | |
326 | fetch_balance.return_value = self.fetch_balance | |
327 | ||
328 | portfolio.Balance.fetch_balances(portfolio.market) | |
329 | self.assertNotIn("XMR", portfolio.Balance.currencies()) | |
330 | self.assertEqual(["USDT", "XVG"], list(portfolio.Balance.currencies())) | |
331 | ||
332 | @mock.patch.object(portfolio.Portfolio, "repartition_pertenthousand") | |
333 | @mock.patch.object(portfolio.market, "fetch_balance") | |
334 | def test_dispatch_assets(self, fetch_balance, repartition): | |
335 | fetch_balance.return_value = self.fetch_balance | |
336 | portfolio.Balance.fetch_balances(portfolio.market) | |
337 | ||
338 | self.assertNotIn("XEM", portfolio.Balance.currencies()) | |
339 | ||
340 | repartition.return_value = { | |
341 | "XEM": 7500, | |
342 | "BTC": 2600, | |
343 | } | |
344 | ||
5ab23e1c | 345 | amounts = portfolio.Balance.dispatch_assets(portfolio.Amount("BTC", "10.1")) |
f2da6589 | 346 | self.assertIn("XEM", portfolio.Balance.currencies()) |
5ab23e1c IB |
347 | self.assertEqual(D("2.6"), amounts["BTC"].value) |
348 | self.assertEqual(D("7.5"), amounts["XEM"].value) | |
f2da6589 IB |
349 | |
350 | @mock.patch.object(portfolio.Portfolio, "repartition_pertenthousand") | |
cfab619d | 351 | @mock.patch.object(portfolio.Trade, "get_ticker") |
f2da6589 IB |
352 | @mock.patch.object(portfolio.Trade, "compute_trades") |
353 | def test_prepare_trades(self, compute_trades, get_ticker, repartition): | |
354 | repartition.return_value = { | |
355 | "XEM": 7500, | |
356 | "BTC": 2500, | |
357 | } | |
deb8924c IB |
358 | def _get_ticker(c1, c2, market): |
359 | if c1 == "USDT" and c2 == "BTC": | |
360 | return { "average": D("0.0001") } | |
361 | if c1 == "XVG" and c2 == "BTC": | |
362 | return { "average": D("0.000001") } | |
363 | if c1 == "XEM" and c2 == "BTC": | |
364 | return { "average": D("0.001") } | |
365 | raise Exception("Should be called with {}, {}".format(c1, c2)) | |
366 | get_ticker.side_effect = _get_ticker | |
367 | ||
f2da6589 IB |
368 | market = mock.Mock() |
369 | market.fetch_balance.return_value = { | |
370 | "USDT": { | |
5ab23e1c IB |
371 | "free": D("10000.0"), |
372 | "used": D("0.0"), | |
373 | "total": D("10000.0") | |
f2da6589 IB |
374 | }, |
375 | "XVG": { | |
5ab23e1c IB |
376 | "free": D("10000.0"), |
377 | "used": D("0.0"), | |
378 | "total": D("10000.0") | |
f2da6589 IB |
379 | }, |
380 | } | |
381 | portfolio.Balance.prepare_trades(market) | |
382 | compute_trades.assert_called() | |
383 | ||
384 | call = compute_trades.call_args | |
385 | self.assertEqual(market, call[1]["market"]) | |
386 | self.assertEqual(1, call[0][0]["USDT"].value) | |
5ab23e1c IB |
387 | self.assertEqual(D("0.01"), call[0][0]["XVG"].value) |
388 | self.assertEqual(D("0.2525"), call[0][1]["BTC"].value) | |
389 | self.assertEqual(D("0.7575"), call[0][1]["XEM"].value) | |
f2da6589 IB |
390 | |
391 | def test__repr(self): | |
392 | balance = portfolio.Balance("BTX", 3, 1, 2) | |
393 | self.assertEqual("Balance(BTX [1.00000000 BTX/2.00000000 BTX/3.00000000 BTX])", repr(balance)) | |
394 | ||
395 | def tearDown(self): | |
396 | self.patcher.stop() | |
397 | ||
cfab619d IB |
398 | class TradeTest(unittest.TestCase): |
399 | import time | |
400 | ||
401 | def setUp(self): | |
402 | super(TradeTest, self).setUp() | |
403 | ||
404 | self.patcher = mock.patch.multiple(portfolio.Trade, | |
405 | ticker_cache={}, | |
406 | ticker_cache_timestamp=self.time.time(), | |
407 | fees_cache={}, | |
408 | trades={}) | |
409 | self.patcher.start() | |
410 | ||
411 | def test_get_ticker(self): | |
412 | market = mock.Mock() | |
413 | market.fetch_ticker.side_effect = [ | |
414 | { "bid": 1, "ask": 3 }, | |
415 | portfolio.ccxt.ExchangeError("foo"), | |
416 | { "bid": 10, "ask": 40 }, | |
417 | portfolio.ccxt.ExchangeError("foo"), | |
418 | portfolio.ccxt.ExchangeError("foo"), | |
419 | ] | |
420 | ||
421 | ticker = portfolio.Trade.get_ticker("ETH", "ETC", market) | |
422 | market.fetch_ticker.assert_called_with("ETH/ETC") | |
423 | self.assertEqual(1, ticker["bid"]) | |
424 | self.assertEqual(3, ticker["ask"]) | |
425 | self.assertEqual(2, ticker["average"]) | |
426 | self.assertFalse(ticker["inverted"]) | |
427 | ||
428 | ticker = portfolio.Trade.get_ticker("ETH", "XVG", market) | |
429 | self.assertEqual(0.0625, ticker["average"]) | |
430 | self.assertTrue(ticker["inverted"]) | |
431 | self.assertIn("original", ticker) | |
432 | self.assertEqual(10, ticker["original"]["bid"]) | |
433 | ||
434 | ticker = portfolio.Trade.get_ticker("XVG", "XMR", market) | |
435 | self.assertIsNone(ticker) | |
436 | ||
437 | market.fetch_ticker.assert_has_calls([ | |
438 | mock.call("ETH/ETC"), | |
439 | mock.call("ETH/XVG"), | |
440 | mock.call("XVG/ETH"), | |
441 | mock.call("XVG/XMR"), | |
442 | mock.call("XMR/XVG"), | |
443 | ]) | |
444 | ||
445 | market2 = mock.Mock() | |
446 | market2.fetch_ticker.side_effect = [ | |
447 | { "bid": 1, "ask": 3 }, | |
448 | { "bid": 1.2, "ask": 3.5 }, | |
449 | ] | |
450 | ticker1 = portfolio.Trade.get_ticker("ETH", "ETC", market2) | |
451 | ticker2 = portfolio.Trade.get_ticker("ETH", "ETC", market2) | |
452 | ticker3 = portfolio.Trade.get_ticker("ETC", "ETH", market2) | |
453 | market2.fetch_ticker.assert_called_once_with("ETH/ETC") | |
454 | self.assertEqual(1, ticker1["bid"]) | |
455 | self.assertDictEqual(ticker1, ticker2) | |
456 | self.assertDictEqual(ticker1, ticker3["original"]) | |
457 | ||
458 | ticker4 = portfolio.Trade.get_ticker("ETH", "ETC", market2, refresh=True) | |
459 | ticker5 = portfolio.Trade.get_ticker("ETH", "ETC", market2) | |
460 | self.assertEqual(1.2, ticker4["bid"]) | |
461 | self.assertDictEqual(ticker4, ticker5) | |
462 | ||
463 | market3 = mock.Mock() | |
464 | market3.fetch_ticker.side_effect = [ | |
465 | { "bid": 1, "ask": 3 }, | |
466 | { "bid": 1.2, "ask": 3.5 }, | |
467 | ] | |
468 | ticker6 = portfolio.Trade.get_ticker("ETH", "ETC", market3) | |
469 | portfolio.Trade.ticker_cache_timestamp -= 4 | |
470 | ticker7 = portfolio.Trade.get_ticker("ETH", "ETC", market3) | |
471 | portfolio.Trade.ticker_cache_timestamp -= 2 | |
472 | ticker8 = portfolio.Trade.get_ticker("ETH", "ETC", market3) | |
473 | self.assertDictEqual(ticker6, ticker7) | |
474 | self.assertEqual(1.2, ticker8["bid"]) | |
475 | ||
476 | @unittest.skip("TODO") | |
477 | def test_values_assertion(self): | |
478 | pass | |
479 | ||
480 | @unittest.skip("TODO") | |
481 | def test_fetch_fees(self): | |
482 | pass | |
483 | ||
484 | @unittest.skip("TODO") | |
485 | def test_compute_trades(self): | |
486 | pass | |
487 | ||
488 | @unittest.skip("TODO") | |
489 | def test_action(self): | |
490 | pass | |
491 | ||
492 | @unittest.skip("TODO") | |
493 | def test_action(self): | |
494 | pass | |
495 | ||
496 | @unittest.skip("TODO") | |
497 | def test_order_action(self): | |
498 | pass | |
499 | ||
500 | @unittest.skip("TODO") | |
501 | def test_prepare_order(self): | |
502 | pass | |
503 | ||
504 | @unittest.skip("TODO") | |
505 | def test_all_orders(self): | |
506 | pass | |
507 | ||
508 | @unittest.skip("TODO") | |
509 | def test_follow_orders(self): | |
510 | pass | |
511 | ||
deb8924c IB |
512 | @unittest.skip("TODO") |
513 | def test_compute_value(self): | |
514 | pass | |
515 | ||
cfab619d IB |
516 | @unittest.skip("TODO") |
517 | def test__repr(self): | |
518 | pass | |
519 | ||
520 | def tearDown(self): | |
521 | self.patcher.stop() | |
522 | ||
dd359bc0 IB |
523 | if __name__ == '__main__': |
524 | unittest.main() |