@@ -76,10 +76,16 @@ def cancel(self, myid):
76
76
self .exchange .cancel (myid )
77
77
78
78
def cancel_order_all (self , symbol = None ):
79
- """すべての注文をキャンセルする """
79
+ """すべての注文をキャンセル """
80
80
self .exchange .cancel_order_all (symbol or self .settings .symbol )
81
81
82
82
def close_position (self , symbol = None ):
83
+ """ポジションクローズ"""
84
+ if self .exchange .order_is_not_accepted is not None :
85
+ if not self .hft :
86
+ self .logger .info ("REJECT: {0} order is not accepted..." .format (myid ))
87
+ return
88
+ # 最小注文サイズ取得
83
89
symbol = symbol or self .settings .symbol
84
90
if symbol == 'FX_BTC_JPY' :
85
91
min_qty = 0.01
@@ -98,10 +104,21 @@ def close_position(self, symbol = None):
98
104
if buysize < min_qty :
99
105
buysize = fsum ([buysize ,min_qty ])
100
106
sellsize = min_qty
107
+ # 注文作成
108
+ close_orders = []
101
109
if sellsize :
102
- self . exchange . create_order ( 'L close ' , 'sell' , sellsize , None , None , None , None , symbol )
110
+ close_orders . append (( '__Lc__ ' , 'sell' , sellsize ) )
103
111
if buysize :
104
- self .exchange .create_order ('S close' , 'buy' , buysize , None , None , None , None , symbol )
112
+ close_orders .append (('__Sc__' , 'buy' , buysize ))
113
+ for order in close_orders :
114
+ myid , side , size = order
115
+ # 約定するまで次の注文は受け付けない
116
+ o = self .exchange .get_order (myid )
117
+ if o .status == 'open' or o .status == 'accepted' :
118
+ delta = datetime .utcnow () - o .accepted_at
119
+ if delta < timedelta (seconds = 60 ):
120
+ continue
121
+ self .exchange .create_order (myid , side , size , None , None , None , None , symbol )
105
122
106
123
def order (self , myid , side , qty , limit = None , stop = None , time_in_force = None , minute_to_expire = None , symbol = None , limit_mask = 0 , seconds_to_keep_order = None ):
107
124
"""注文"""
@@ -296,11 +313,7 @@ def wrapper(*args, **kargs):
296
313
297
314
def async_result (f_result , last ):
298
315
if f_result is not None and f_result .done ():
299
- try :
300
- return None , f_result .result ()
301
- except Exception as e :
302
- self .logger .warning (e )
303
- f_result = None
316
+ return None , f_result .result ()
304
317
return f_result , last
305
318
306
319
self .hft = self .settings .interval < 3
0 commit comments