|
1
|
|
|
"""Test the creation of OperationContainer objects.""" |
|
2
|
|
|
|
|
3
|
|
|
from __future__ import absolute_import |
|
4
|
|
|
import unittest |
|
5
|
|
|
import copy |
|
6
|
|
|
|
|
7
|
|
|
from trade import trade |
|
8
|
|
|
from trade.container_tasks import ( |
|
9
|
|
|
fetch_daytrades, |
|
10
|
|
|
add_to_position_group, find_volume, |
|
11
|
|
|
) |
|
12
|
|
|
from .container_test_base import TestFetchPositions |
|
13
|
|
|
from tests.fixtures.operations import OPERATION24, OPERATION45 |
|
14
|
|
|
from tests.fixtures.commissions import COMMISSIONS12 |
|
15
|
|
|
from tests.fixtures.assets import ASSET |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
class TestContainerCreationCase00(unittest.TestCase): |
|
19
|
|
|
"""Test the creation of a OperationContainer.""" |
|
20
|
|
|
|
|
21
|
|
|
def setUp(self): |
|
22
|
|
|
self.container = trade.OperationContainer( |
|
23
|
|
|
operations=[], |
|
24
|
|
|
tasks=[find_volume] |
|
25
|
|
|
) |
|
26
|
|
|
|
|
27
|
|
|
def test_container_exists(self): |
|
28
|
|
|
self.assertTrue(self.container) |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
class TestContainerCreationCase01(unittest.TestCase): |
|
32
|
|
|
"""Test the creation of a OperationContainer.""" |
|
33
|
|
|
|
|
34
|
|
|
def setUp(self): |
|
35
|
|
|
self.container = trade.OperationContainer( |
|
36
|
|
|
operations=[], |
|
37
|
|
|
tasks=[find_volume] |
|
38
|
|
|
) |
|
39
|
|
|
self.container.commissions = COMMISSIONS12 |
|
40
|
|
|
self.container.fetch_positions_tasks = [fetch_daytrades] |
|
41
|
|
|
self.container.fetch_positions() |
|
42
|
|
|
|
|
43
|
|
|
def test_container_exists(self): |
|
44
|
|
|
self.assertTrue(self.container) |
|
45
|
|
|
|
|
46
|
|
|
def test_container_commissions(self): |
|
47
|
|
|
self.assertEqual(self.container.commissions, COMMISSIONS12) |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
class TestContainerAddToPositions(TestFetchPositions): |
|
51
|
|
|
"""Test add_to_position_operations method.""" |
|
52
|
|
|
|
|
53
|
|
|
#volume = 20 |
|
54
|
|
|
operations = [OPERATION24] |
|
55
|
|
|
positions = { |
|
56
|
|
|
ASSET.symbol: { |
|
57
|
|
|
'quantity': 20, |
|
58
|
|
|
'price': 3, |
|
59
|
|
|
'volume': 60, |
|
60
|
|
|
'commissions': {} |
|
61
|
|
|
}, |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
def setUp(self): |
|
65
|
|
|
super(TestContainerAddToPositions, self).setUp() |
|
66
|
|
|
add_to_position_group(self.container, copy.deepcopy(OPERATION45)) |
|
67
|
|
|
|