-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrecreate_trades.py
More file actions
68 lines (53 loc) · 2.45 KB
/
recreate_trades.py
File metadata and controls
68 lines (53 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'''Astronomy here'''
from test_up_repl import celebro_instance
from datetime import datetime
import time
import asyncio
async def recreate_trades():
'''We lost trades when we sheepishily took down the database, lets recreate them'''
print("Recreating the lost trades")
for trader in celebro_instance.exchange_traders:
if not trader._exchange == "BINANCE":
continue
account = trader.account
start_time = time.time()
open_orders = account.open_orders()
for order in open_orders:
print(f"Adding #{order['symbol']} into trades")
symbol_info = trader.get_symbol_info(order['symbol'])
market_price_resp = await trader.get_avg_price(order['symbol'])
if market_price_resp['error']:
print(market_price_resp['message'])
continue
market_price = float(market_price_resp['result'])
buy_order_id = order['clientOrderId'].split("_")[1] if len(order['clientOrderId'].split("_")) == 2 else ""
if not buy_order_id:
print(f"no buy order id, cloid {order['clientOrderId']}")
continue
trade_params = {
'exchange': "BINANCE",
'exchange_account_id' : trader.account_model_id,
'symbol': order['symbol'],
'sell_order_id': order['orderId'],
'buy_time': datetime.utcfromtimestamp(int(order['updateTime']) / 1000),
'sell_time': datetime.utcfromtimestamp(int(order['updateTime'])/1000),
'sell_price': order['price'],
'sell_quantity': order['origQty'],
'buy_quantity': order['origQty'],
'buy_quantity_executed': order['origQty'],
'quote_asset': symbol_info.quote_asset,
'base_asset': symbol_info.base_asset,
'sell_status': order['status'],
'buy_status': 'FILLED',
'side': 'BUY',
'buy_order_id': buy_order_id,
'buy_price' : market_price,
'executed_buy_price' : market_price,
'signal_id' : 5
}
await trader.update_trade(**trade_params)
if time.time() - start_time < 60:
print(f"sleeping for {60 - (time.time() - start_time)}")
await asyncio.sleep(60 - (time.time() - start_time))
if __name__ == "__main__":
asyncio.run(recreate_trades())