Skip to content

Commit 07ec357

Browse files
committed
Fixed issues with Add/Remove trade.
1 parent 889116f commit 07ec357

File tree

3 files changed

+30
-39
lines changed

3 files changed

+30
-39
lines changed

Bot/Exchange/Binance/BinanceWebsocket.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import traceback
44
from threading import Thread
55
import time
6+
from time import sleep
67

78
from binance.client import Client
89

@@ -63,8 +64,8 @@ def run(self):
6364
self.mngmt_future = asyncio.ensure_future(self.management_loop())
6465
self.mngmt_future.add_done_callback(self.feature_finished)
6566

66-
if not asyncio.get_event_loop().is_running():
67-
asyncio.get_event_loop().run_forever()
67+
# if not asyncio.get_event_loop().is_running():
68+
asyncio.get_event_loop().run_forever()
6869
finally:
6970
# self.loop.close()
7071
pass
@@ -152,15 +153,15 @@ async def websocket_handler(self, url, callback):
152153
def stop_sockets(self):
153154
self.stop = True
154155

155-
if self.mngmt_future:
156-
self.mngmt_future.cancel()
157-
158156
self.stop_ticker_future()
159157
self.stop_user_future()
160158

159+
if self.mngmt_future:
160+
self.mngmt_future.cancel()
161+
161162
self.loop.call_soon_threadsafe(self.loop.stop)
162163

163164
if threading.current_thread().ident != self.ident:
164-
self.join()
165+
self.join(timeout=1)
165166

166167
self.logInfo('Stopped')

Bot/TradeHandler.py

+10
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,23 @@ def updated_trade(self, trade: Trade):
227227
# find by ID
228228
# self.strategies_dict[trade.symbol].update_trade(trade)
229229
self.tradeid_strategy_dict[trade.id].update_trade(trade)
230+
231+
if self.handle_completed_strategy(self.tradeid_strategy_dict[trade.id]):
232+
self.logInfo('Strategy is completed [{}]'.format(trade.symbol))
233+
return
234+
230235
self.balances.update_balances(self.fx.get_all_balances_dict())
231236
self.logInfo('Updating trade [{}]'.format(trade.symbol))
232237
else:
233238
self.logInfo('Adding trade [{}]'.format(trade.symbol))
234239

235240
new_strategy = TargetsAndStopLossStrategy(trade, self.fx, self.order_updated_handler,
236241
self.balances.get_balance(trade.asset))
242+
243+
if self.handle_completed_strategy(new_strategy):
244+
self.logInfo('Strategy is completed [{}]'.format(new_strategy.symbol()))
245+
return
246+
237247
try:
238248
self.stop_listening()
239249
self.add_new_strategy(new_strategy)

Trades/TRADE_TEMPLATE.TPL

+13-33
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,43 @@
11
{
22
"trade": {
3-
"id": "71717f7d-b848-4a35-9bea-33427e8e4110",
4-
"asset": "ICN",
5-
"symbol": "ICNBTC",
3+
"asset": "ADA",
4+
"symbol": "ADABTC",
65
"side": "SELL",
7-
"status": "COMPLETED",
6+
"status": "NEW",
87
"entry": {
9-
"side": "BUY",
10-
"smart": true,
11-
"threshold": "0.00000020",
128
"targets": [
139
{
14-
"status": "COMPLETED",
15-
"price": "0.00014421",
16-
"vol": "3800.00000000"
10+
"price": "0.00002950",
11+
"vol": "1300"
1712
}
1813
]
1914
},
2015
"exit": {
21-
"side": "SELL",
22-
"smart": false,
23-
"threshold": "0.30%",
16+
"threshold": "0.50%",
2417
"targets": [
2518
{
26-
"status": "COMPLETED",
27-
"id": 9672903,
28-
"date": "2018-04-20 02:21:48",
29-
"price": "0.00015601",
30-
"vol": "25%",
31-
"smart": true,
32-
"best_price": "0.00015529"
19+
"price": "0.00003250",
20+
"vol": "20%"
3321
},
3422
{
35-
"status": "COMPLETED",
36-
"id": 9871297,
37-
"date": "2018-04-21 18:28:12",
38-
"price": "0.00017600",
39-
"vol": "33%",
40-
"sl": "0.00015000"
23+
"price": "0.00003400",
24+
"vol": "33%"
4125
},
4226
{
43-
"price": "0.00018700",
27+
"price": "0.00003600",
4428
"vol": "50%"
4529
},
4630
{
47-
"price": "0.00020800",
4831
"vol": "100%",
32+
"price": "0.00004100",
4933
"smart": true
5034
}
5135
]
5236
},
5337
"stoploss": {
5438
"type": "FIXED",
55-
"last_stoploss": "0.00015000",
5639
"initial_target": {
57-
"status": "COMPLETED",
58-
"id": 10166677,
59-
"date": "2018-04-25 13:25:20",
60-
"price": "0.00013144",
40+
"price": "0.00002500",
6141
"vol": "100%"
6242
}
6343
}

0 commit comments

Comments
 (0)