3
3
from loguru import logger
4
4
from shioaji .constant import TFTStockPriceType
5
5
6
- from .io .file import read_csv_position , read_position
7
- from .utils import price_move , price_round , quantity_num_split
6
+ from .io .file import read_position
7
+ from .utils import price_round , price_limit
8
8
from .position import Position , PriceSet
9
9
from .data import Snapshot
10
10
@@ -31,7 +31,7 @@ def cover_price_set_onclose(self, position: Position):
31
31
price = position .contract .limit_down
32
32
if position .status .open_quantity > 0
33
33
else position .contract .limit_up ,
34
- quantity = position .status .open_quantity * - 1 ,
34
+ quantity = position .status .open_quantity * - 1 ,
35
35
price_type = TFTStockPriceType .LMT ,
36
36
)
37
37
]
@@ -70,33 +70,45 @@ def entry_positions(self):
70
70
stop_loss_price = contract .reference * (
71
71
1 + (- 1 if pos > 0 else 1 ) * (self .stop_loss_pct )
72
72
)
73
+ stop_loss_price = price_round (stop_loss_price , pos > 0 )
74
+ stop_loss_price = price_limit (
75
+ stop_loss_price , contract .limit_up , contract .limit_down
76
+ )
73
77
stop_profit_price = contract .reference * (
74
78
1 + (1 if pos > 0 else - 1 ) * (self .stop_profit_pct )
75
79
)
80
+ stop_profit_price = price_round (stop_profit_price , pos < 0 )
81
+ stop_profit_price = price_limit (
82
+ stop_profit_price , contract .limit_up , contract .limit_down
83
+ )
76
84
entry_price = contract .reference * (
77
85
1 + (- 1 if pos > 0 else 1 ) * self .entry_pct
78
86
)
87
+ entry_price = price_round (entry_price , pos > 0 )
88
+ entry_price = price_limit (
89
+ entry_price , contract .limit_up , contract .limit_down
90
+ )
79
91
entry_args .append (
80
92
{
81
93
"code" : code ,
82
94
"pos" : pos ,
83
95
"entry_price" : [
84
96
PriceSet (
85
- price = price_round ( entry_price , pos > 0 ) ,
97
+ price = entry_price ,
86
98
quantity = pos ,
87
99
price_type = TFTStockPriceType .LMT ,
88
100
)
89
101
],
90
102
"stop_profit_price" : [
91
103
PriceSet (
92
- price = price_round ( stop_profit_price , pos < 0 ) ,
104
+ price = stop_profit_price ,
93
105
quantity = pos ,
94
106
price_type = TFTStockPriceType .MKT ,
95
107
)
96
108
],
97
109
"stop_loss_price" : [
98
110
PriceSet (
99
- price = price_round ( stop_loss_price , pos > 0 ) ,
111
+ price = stop_loss_price ,
100
112
quantity = pos ,
101
113
price_type = TFTStockPriceType .MKT ,
102
114
)
@@ -112,4 +124,3 @@ def cover_positions(
112
124
self , positions : Dict [str , Position ], snapshots : Dict [str , Snapshot ] = dict ()
113
125
):
114
126
return self .cover_positions_onclose ()
115
-
0 commit comments