This repository has been archived by the owner on Oct 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
trade_trailing.py
57 lines (47 loc) 路 2.41 KB
/
trade_trailing.py
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
import config
import strategy
import api_binance
from pytz import utc
from datetime import datetime
from termcolor import colored
from apscheduler.schedulers.blocking import BlockingScheduler
def lets_make_some_money():
for i in range(len(config.pair)):
pair = config.pair[i]
leverage = config.leverage[i]
quantity = config.quantity[i]
trailing = config.use_trailing
print(pair)
response = api_binance.position_information(pair)
long_term_low_leverage = strategy.long_term_low_leverage(pair)
# print(long_term_low_leverage)
if response[0].get('marginType') != "isolated": api_binance.change_margin_to_ISOLATED(pair)
if int(response[0].get("leverage")) != leverage: api_binance.change_leverage(pair, leverage)
if api_binance.LONG_SIDE(response) == "NO_POSITION":
if long_term_low_leverage["BUY"].iloc[-1]:
if trailing: api_binance.trailing_open_long(pair, quantity)
else: api_binance.market_open_long(pair, quantity)
else: print("_LONG_SIDE : 馃惡 WAIT 馃惡")
if api_binance.LONG_SIDE(response) == "LONGING":
if long_term_low_leverage["SELL"].iloc[-1]:
api_binance.market_close_long(pair, response)
api_binance.cancel_all_open_orders(pair)
else: print(colored("_LONG_SIDE : HOLDING_LONG", "green"))
if api_binance.SHORT_SIDE(response) == "NO_POSITION":
if long_term_low_leverage["SELL"].iloc[-1]:
if trailing: api_binance.trailing_open_short(pair, quantity)
else: api_binance.market_open_short(pair, quantity)
else: print("SHORT_SIDE : 馃惡 WAIT 馃惡")
if api_binance.SHORT_SIDE(response) == "SHORTING":
if long_term_low_leverage["BUY"].iloc[-1]:
api_binance.market_close_short(pair, response)
api_binance.cancel_all_open_orders(pair)
else: print(colored("SHORT_SIDE : HOLDING_SHORT", "red"))
print("Last action executed @ " + datetime.now().strftime("%H:%M:%S") + "\n")
print(colored("LIVE TRADE IS ENABLED\n", "green")) if config.live_trade else print(colored("THIS IS A SHOWCASE\n", "red"))
if config.live_trade and config.enable_scheduler:
scheduler = BlockingScheduler()
scheduler.add_job(lets_make_some_money, 'cron', hour='0', timezone=utc)
scheduler.start()
else:
lets_make_some_money()