|
1
|
|
|
"""Tests for the fetch_positions() method of OperationContainer.""" |
|
2
|
|
|
|
|
3
|
|
|
from __future__ import absolute_import |
|
4
|
|
|
from abc import ABCMeta |
|
5
|
|
|
|
|
6
|
|
|
from .container_test_base import TestFetchPositions |
|
7
|
|
|
from .fixture_positions import ( |
|
8
|
|
|
DT_POSITION0, DT_POSITION1, DT_POSITION2, POSITION4, POSITION2, |
|
9
|
|
|
DT_POSITION6, DT_POSITION9, |
|
10
|
|
|
) |
|
11
|
|
|
from .fixture_tasks import find_trading_fees_for_positions |
|
12
|
|
|
|
|
13
|
|
|
from tests.fixtures.assets import ( |
|
14
|
|
|
ASSET, ASSET2, ASSET3, |
|
15
|
|
|
) |
|
16
|
|
|
from tests.fixtures.commissions import ( |
|
17
|
|
|
COMMISSIONS13, COMMISSIONS8 |
|
18
|
|
|
) |
|
19
|
|
|
from tests.fixtures.operation_sequences import ( |
|
20
|
|
|
OPERATION_SEQUENCE2, OPERATION_SEQUENCE8, OPERATION_SEQUENCE24 |
|
21
|
|
|
) |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
class TaxManagerForTests(object): |
|
25
|
|
|
"""A TradingFees class for the tests.""" |
|
26
|
|
|
|
|
27
|
|
|
__metaclass__ = ABCMeta |
|
28
|
|
|
|
|
29
|
|
|
@classmethod |
|
30
|
|
|
def get_fees(cls, operation=None, operation_type=None): |
|
31
|
|
|
"""A sample implementation of get_fees().""" |
|
32
|
|
|
if operation_type == 'daytrades': |
|
33
|
|
|
return cls.get_fees_for_daytrades(operation) |
|
34
|
|
|
return {} |
|
35
|
|
|
|
|
36
|
|
|
@classmethod |
|
37
|
|
|
def get_fees_for_daytrades(cls, operation): |
|
38
|
|
|
"""Get the fees for a daytrade operation.""" |
|
39
|
|
|
return { |
|
40
|
|
|
'emoluments': operation.volume * 0.005 / 100, |
|
41
|
|
|
'liquidation': operation.volume * 0.02 / 100, |
|
42
|
|
|
'registry': 0, |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
class TestContainerFetchPositionsCase00(TestFetchPositions): |
|
46
|
|
|
"""Test the fetch_positions() method of Accumulator.""" |
|
47
|
|
|
|
|
48
|
|
|
commissions = COMMISSIONS13 |
|
49
|
|
|
operations = OPERATION_SEQUENCE2 |
|
50
|
|
|
positions = POSITION4 |
|
51
|
|
|
daytrades = { |
|
52
|
|
|
ASSET.symbol: DT_POSITION6 |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
class TestContainerFetchPositionsCase01(TestFetchPositions): |
|
57
|
|
|
"""Test the fetch_positions() method of Accumulator.""" |
|
58
|
|
|
|
|
59
|
|
|
operations = OPERATION_SEQUENCE8 |
|
60
|
|
|
positions = POSITION2 |
|
61
|
|
|
daytrades = { |
|
62
|
|
|
ASSET.symbol: DT_POSITION0, |
|
63
|
|
|
ASSET2.symbol: DT_POSITION1, |
|
64
|
|
|
ASSET3.symbol: DT_POSITION2 |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
class TestContainerFetchPositionsCase02(TestFetchPositions): |
|
69
|
|
|
"""Daytrades, commissions and taxes.""" |
|
70
|
|
|
|
|
71
|
|
|
commissions = COMMISSIONS8 |
|
72
|
|
|
operations = OPERATION_SEQUENCE24 |
|
73
|
|
|
daytrades = { |
|
74
|
|
|
ASSET.symbol: DT_POSITION9, |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
def setUp(self): |
|
78
|
|
|
super(TestContainerFetchPositionsCase02, self).setUp() |
|
79
|
|
|
self.container.trading_fees = TaxManagerForTests |
|
80
|
|
|
find_trading_fees_for_positions(self.container) |
|
81
|
|
|
|