forked from Gab0/japonicus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjlivetrader.py
executable file
·102 lines (76 loc) · 3.15 KB
/
jlivetrader.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/python
import os
import optparse
import json
import livetrader.exchangeMonitor
import livetrader.gekkoTrigger
import livetrader.gekkoChecker
try:
import livetrader.strategyRanker
except Exception:
pass
parser = optparse.OptionParser()
parser.add_option('-b', '--balance',
dest='balanceChecker', action='store_true', default=False)
parser.add_option('-t', '--trigger <strategy>',
dest='botTrigger', type='str', default='')
parser.add_option('-c', dest='runningBotChecker',
action='store_true', default=False)
parser.add_option('-l', dest='tradingBot', action='store_true',
default=False)
parser.add_option('--candleSize <cs>',
dest='candleSize', type='int', default=5)
parser.add_option('--strat <strategy>', dest='strategy',
type='str', default='')
parser.add_option('--param <parameters>', dest='alternativeParameters',
type='str', default=None)
parser.add_option('-k', dest='killGekkoBots', action='store_true',
default=False,
help='Destroy all running gekko bot instances.')
parser.add_option('-s', dest='viewLastTrades', action='store_true',
default=False,
help='Show last trades done by bots.')
options, args = parser.parse_args()
if __name__ == '__main__':
os.chdir(os.path.dirname(os.path.realpath(__file__)))
exchange = livetrader.exchangeMonitor.Exchange('binance')
if options.balanceChecker:
totalUSD = exchange.getUserBalance()
print("net weight at %s: US$T%.2f" % (
exchange.name,
totalUSD)
)
if options.botTrigger:
allPairs = exchange.getAssets()
assetCurrencyPairs = exchange.parseAssets(allPairs)
Stratlist = [options.botTrigger]
exchangeConfPath =\
exchange.conf.binanceAssetCurrencyTargetFilePath
if exchangeConfPath:
exchangeMarketData = exchange.generateMarketsJson(
assetCurrencyPairs)
exchangeConfPath = os.path.join(exchangeConfPath,
'binance-markets.json')
with open(exchangeConfPath, 'w') as F:
json.dump(exchangeMarketData, F, indent=2)
livetrader.gekkoTrigger.launchBatchTradingBots(
assetCurrencyPairs,
Stratlist,
options
)
if options.runningBotChecker:
ranker = livetrader.strategyRanker.strategyRanker()
ranker.loadStrategyRankings()
userOrderHistory = exchange.getRecentOrders()
for M in userOrderHistory.keys():
marketOrderHistory = userOrderHistory[M]
if marketOrderHistory:
information = json.dumps(marketOrderHistory, indent=2)
print(information)
livetrader.gekkoChecker.checkGekkoRunningBots(exchange,
ranker, options)
if options.killGekkoBots:
livetrader.gekkoChecker.stopGekkoBots()
if options.viewLastTrades:
Orders = exchange.getRecentOrders()
print(json.dumps(Orders, indent=2))