def write_log(text=""): try: with open(log_path) as f: s = f.read() except FileNotFoundError: s = "" mm = str(from_time_stamp())[0:7] if s == "" or s.find(mm) != -1: with open(log_path, 'w') as f: f.write(text + "\n" + s) else: with open(log_path, 'a') as f: f.writelines("\n") # write old logs with open( str(from_time_stamp(int(time.time()) - 86400 * 10))[0:7] + '.txt', 'w') as old_f: with open(log_path) as f: old_f.writelines(f.readlines()[::-1]) # write count try: symbols = json.loads(config.get("trade", "symbol")) for symbol in symbols: cfg_field = symbol + "-stat" sum_count = 0 try: sum_count = sum( json.loads(config.get(cfg_field, "count"))) except Exception as err: logger.error("Error: write_log,{}".format(err)) old_f.writelines(symbol + " [" + str(sum_count) + "]") except Exception as err: logger.error("Error: write_log,{}".format(err)) with open(log_path, 'w') as f: f.write(text)
def __init__(self): self.last = "" self.volume = 0 config.read("config.ini") try: self.last = config.get("security", "last") self.volume = int(config.get("security", "count")) except Exception as e: if str(e).find("No section") > -1: config.add_section("security") self.reset() finally: logger.info(f"CURRENT CONTRACT TRADE COUNT:{self.volume}")
import configparser from module.CfEnv import config from util.MailUtil import send_email from util.TelegramUtil import send_telegram from module.Logger import logger try: notify_type = config.get("notify", "type") except (configparser.NoOptionError, configparser.NoSectionError): notify_type = "telegram" MSG_TYPE_DEAL = 1 MSG_TYPE_REPORT = 2 def send_msg(message, msg_type=MSG_TYPE_DEAL): logger.info("send statistic message") if notify_type == "telegram": return send_telegram(message, msg_type == MSG_TYPE_REPORT) else: return send_email(message)
from module.CfEnv import config, configBase import tokens.Token as Token import api.OkexClientV3 as Client import json import threading # init apikey,secretkey,passphrase api_key = configBase.get("okex-v3", "API_KEY") seceret_key = configBase.get("okex-v3", "SECRET_KEY") passphrase = configBase.get("okex-v3", "PASSPHRASE") if __name__ == '__main__': symbols = json.loads(config.get("trade", "symbol")) if len(symbols) > 1: for symbol in symbols: threading.Thread(target=Token.__main__, args=( Client.OkexClient(api_key, seceret_key, passphrase), symbol, )).start() else: Token.__main__(Client.OkexClient(api_key, seceret_key, passphrase), symbols[0])