-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (53 loc) · 1.54 KB
/
main.py
File metadata and controls
69 lines (53 loc) · 1.54 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
69
import logging.config
import logging
import asyncio
import yaml
import json
import trading_bot
from ccxt import bitmex
BOT_CONFIG = "config.json"
LOG_CONFIG = "log_conf.yaml"
def get_config(file: str) -> dict:
with open(file, "r") as f:
return json.load(f)
def setup_logging(file: str, config: dict) -> None:
with open(LOG_CONFIG, "r") as f:
log_config = yaml.load(f)
logging.config.dictConfig(log_config)
level = logging.INFO if not config["debug"] else logging.DEBUG
console_logger = logging.getLogger("main")
console_logger.setLevel(level)
bot_logger = logging.getLogger("bot")
bot_logger.setLevel(level)
console_logger.debug("Set up logging")
def main():
config = get_config(BOT_CONFIG)
setup_logging(LOG_CONFIG, config)
logger = logging.getLogger("main")
logger.info("Starting System...")
if config["test"]:
client = bitmex({
"urls": {
"api": "https://testnet.bitmex.com",
"test": "https://www.bitmex.com"
},
"apiKey": config["key"],
"secret": config["secret"]
})
else:
client = bitmex({
"apiKey": config["key"],
"secret": config["secret"]
})
logger.info("Connected To Servers!!!")
# client.create_market_sell_order(symbol="BTC/USD", amount=100)
# client.create_market_buy_order(symbol="BTC/USD", amount=50)
bot = trading_bot.Bot(config=config, logger=logging.getLogger("bot"),
client=client)
logger.info("Starting")
loop = asyncio.get_event_loop()
future = asyncio.ensure_future(bot.start())
loop.run_until_complete(future)
loop.close()
if __name__ == "__main__":
main()