def __init__(self): # Status ID self._id = Value('i', 0) self._activeStatus = Manager().list() self._doneStatus = Manager().list() self._cachesize = Config()._Engine_cacheSize # logger self._logger = Logger()
def __init__(self): # Config init self.__epoch = Config()._Engine_epoch self.__maxProcess = Config()._Engine_maxProcess # 保存事件列表 按优先级不同分别保存 self.__lowEnventQueue = Queue() self.__mediumEventQueue = Queue() self.__highEventQueue = Queue() # 引擎开关 self.__active = Value('b', False) # 事件处理字典{'event1': [handler1,handler2] , 'event2':[handler3, ...,handler4]} self.__handlers = {} # 保存事件处理进程池 控制最大进程数量 以及关闭引擎时处理已启动进程 self.__processPool = Manager().list() # 保存已执行事件处理状态 self.__status = Status() # 事件引擎主进程 self.__mainProcess = Process(target=self.__run) # logger self.__logger = Logger()
class Logger(object): # debug __debug = Config()._Debug_debug __debug_level = Config()._Debug_level # log __log_type = Config()._Log_type __log_url = Config()._Log_url __log_level = Config()._Log_level __file_formatter = logging.Formatter( '%(asctime)s pid=%(process)d %(levelname)-4s: %(message)s') __console_formatter = colorlog.ColoredFormatter( "%(log_color)s%(asctime)s pid=%(process)d %(levelname)-4s: %(reset)s%(blue)s%(message)s", datefmt=None, reset=True, log_colors={ 'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red,bg_white' }, secondary_log_colors={}, style='%') # logging __level = { 'DEBUG': logging.DEBUG, 'INFO': logging.INFO, 'WARNING': logging.WARNING, 'ERROR': logging.ERROR, 'CRITICAL': logging.CRITICAL } def __init__(self): # Config init # 设置文件日志的格式 # 定义日志处理器将INFO或者以上级别的日志发送到 sys.stderr # handler = logging.FileHandler(Logger.__log_url, mode="a+") handler = logging.handlers.TimedRotatingFileHandler(Logger.__log_url, when="d", interval=1, backupCount=7) handler.setFormatter(Logger.__file_formatter) handler.setLevel(Logger.__level[Logger.__log_level]) # 设置控制台日志的格式 # 定义日志处理器将WARNING或者以上级别的日志发送到 console console = logging.StreamHandler() console.setFormatter(Logger.__console_formatter) console.setLevel(Logger.__level[Logger.__debug_level]) # 设置logger self._logger = logging.getLogger(Logger.__log_type) # 添加至logger self._logger.handlers = [] self._logger.addHandler(handler) if Logger.__debug: self._logger.addHandler(console) self._logger.setLevel(logging.DEBUG) def debug(self, msg): try: self._logger.debug(msg) except Exception as err: raise LogException(err) def info(self, msg): try: self._logger.info(msg) except Exception as err: raise LogException(err) def warn(self, msg): try: self._logger.warn(msg) except Exception as err: raise LogException(err) def error(self, msg): try: self._logger.error(msg) except Exception as err: raise LogException(err) def critical(self, msg): try: self._logger.critical(msg) except Exception as err: raise LogException(err)
# -*- coding: utf-8 -*- import os import sys import unittest sys.path.append(os.getcwd()) from src.core.coin.huobi import Huobi from src.core.config import Config from src.core.util.log import Logger # proxies _proxies = Config()._Proxies_url if Config()._Proxies_proxies else None # Huobi _Huobi_exchange = Config()._Huobi_exchange _Huobi_api_key = Config()._Huobi_api_key _Huobi_api_secret = Config()._Huobi_api_secret _Huobi_acct_id = Config()._Huobi_acct_id huobi = Huobi(_Huobi_exchange, _Huobi_api_key, _Huobi_api_secret, _Huobi_acct_id, _proxies) logger = Logger() class TestHuobi(unittest.TestCase): def test_getConfig(self): res = huobi.getConfig() logger.debug(res) self.assertEqual(res["exchange"], _Huobi_exchange)
# -*- coding: utf-8 -*- import os import sys import unittest sys.path.append(os.getcwd()) from src.core.coin.binance import Binance from src.core.config import Config from src.core.util.log import Logger # proxies _proxies = Config()._Proxies_url if Config()._Proxies_proxies else None # Binance _Binance_exchange = Config()._Binance_exchange _Binance_api_key = Config()._Binance_api_key _Binance_api_secret = Config()._Binance_api_secret binance = Binance(_Binance_exchange, _Binance_api_key, _Binance_api_secret, _proxies) logger = Logger() class TestBinance(unittest.TestCase): def test_getConfig(self): res = binance.getConfig() logger.debug(res) self.assertEqual(res["exchange"], _Binance_exchange) def test_setProxy(self):
# -*- coding: utf-8 -*- from src.core.config import Config # CCAT signal SIGNAL_AUTO = Config()._Signal_auto SIGNAL_BASECOIN = Config()._Main_baseCoin SIGNAL_SIGNALS = Config()._Signal_signals SIGNAL_MAX_NUM = 10 # CCAT calc CALC_ZERO_NUMBER = 0.00000001
""" Get the Heimdall settings, updates and pass it on to the Strings class. """ String = Strings() """ Print the banner along with Heimdall specifications. """ if not args.no_logo: String.banner() String.banner_description() """ Check for available updates. """ conf = Config() update = Update() if args.update and update.verify(args.update): update.upgrade() if conf.get_automatic_verify_upgrades and not args.update: update.verify(args.update) """ Activates the "helper()" method if no targets are passed in the arguments. """ if not args.url: String.helper() exit() else:
# -*- coding: utf-8 -*- import os import sys import unittest sys.path.append(os.getcwd()) from src.core.coin.okex import Okex from src.core.config import Config from src.core.util.log import Logger # proxies _proxies = Config()._Proxies_url if Config()._Proxies_proxies else None # Okex _Okex_exchange = Config()._Okex_exchange _Okex_api_key = Config()._Okex_api_key _Okex_api_secret = Config()._Okex_api_secret _Okex_passphrase = Config()._Okex_passphrase okex = Okex(_Okex_exchange, _Okex_api_key, _Okex_api_secret, _Okex_passphrase, _proxies) logger = Logger() class TestOkex(unittest.TestCase): def test_getConfig(self): res = okex.getConfig() logger.debug(res) self.assertEqual(res["exchange"], _Okex_exchange)
def __init__(self): # config param self._epoch = Config()._Router_epoch self._timeout = Config()._Router_timeout self._marketKlineInterval = Config()._Main_marketKlineInterval self._marketTickerInterval = Config()._Main_marketTickerInterval self._statisticJudgeMarketTickerInterval = Config()._Main_statisticJudgeMarketTickerInterval self._asyncAccount = Config()._Main_asyncAccount self._syncAccountTimeout = Config()._Main_syncAccountTimeout self._asyncMarketKline = Config()._Main_asyncMarketKline self._syncMarketKlineTimeout = Config()._Main_syncMarketKlineTimeout self._asyncMarketDepth = Config()._Main_asyncMarketDepth self._syncMarketDepthTimeout = Config()._Main_syncMarketDepthTimeout self._asyncMarketTicker = Config()._Main_asyncMarketTicker self._syncMarketTickerTimeout = Config()._Main_syncMarketTickerTimeout self._asyncJudge = Config()._Main_asyncJudge self._syncJudgeTimeout = Config()._Main_syncJudgeTimeout self._asyncBacktest = Config()._Main_asyncBacktest self._syncBacktestTimeout = Config()._Main_syncBacktestTimeout self._asyncOrder = Config()._Main_asyncOrder self._syncOrderTimeout = Config()._Main_syncOrderTimeout self._asyncStatistic = Config()._Main_asyncStatistic self._syncStatisticTimeout = Config()._Main_syncStatisticTimeout # class instance self._eventEngine = EventEngine() self._sender = Sender(self._eventEngine) self._handler = Handler(self._eventEngine) self._register = Register(self._eventEngine, self._handler) self._util = Util(self._eventEngine, self._sender) # logger self._logger = Logger() # router param self._start = False self._startTime = time.time() self._marketKlineUpdateTime = time.time() # self._marketKlineUpdateTime = time.time() - self._marketKlineInterval self._marketTickerUpdateTime = time.time() - self._marketTickerInterval self._statisticJudgeMarketTickerUpdateTime = time.time( ) - self._statisticJudgeMarketTickerInterval
# -*- coding: utf-8 -*- from src.core.config import Config from src.core.util.helper import MyTemplate # CCAT signals SIGNAL_BACKTEST = 'backtest' SIGNAL_ORDER = 'order' # CCAT types timeWindow TYPE_DIS_TIMEWINDOW = Config()._Main_typeDisTimeWindow * 1000 TYPE_TRA_TIMEWINDOW = Config()._Main_typeTraTimeWindow * 1000 TYPE_PAIR_TIMEWINDOW = Config()._Main_typePairTimeWindow * 1000 # CCAT types Threshold TYPE_DIS_THRESHOLD = Config()._Main_typeDisThreshold TYPE_TRA_THRESHOLD = Config()._Main_typeTraThreshold TYPE_PAIR_THRESHOLD = Config()._Main_typePairThreshold # CCAT types TYPE_DIS = 'dis' TYPE_TRA = 'tra' TYPE_PAIR = 'pair' # event status QUEUE_STATUS_EVENT = "queue" ACTIVE_STATUS_EVENT = "active" DONE_STATUS_EVENT = "done" # event priority LOW_PRIORITY_EVENT = "low" # p.start()