def __init__(self, **kwargs): super(SimulateTrader, self).__init__() self.host = kwargs.get("host", "0.0.0.0") self.port = kwargs.get("port", 0) self.user = kwargs.get("user", "user") self.passwd = kwargs.get("passwd", "123456") self.db_clearx = "clearx" self.db_financial = "financial" self.charset = "utf8" self.tb_security_info = "security_info" self.tb_pre_quote_stk = "pre_quote_stk" self.tb_account_trade = "account_trade" self.security = {} self.quote_data = {} self.stock_list = [] self.trans_id = 0 self.account_id = "test_account" self.dbm_clearx = dbm_mysql.DBM_MySQL( host=self.host, port=self.port, user=self.user, passwd=self.passwd, db=self.db_clearx, charset=self.charset) # db_clearx self.dbm_financial = dbm_mysql.DBM_MySQL( host=self.host, port=self.port, user=self.user, passwd=self.passwd, db=self.db_financial, charset=self.charset) # db_financial if self.dbm_clearx.Connect() == True and self.dbm_financial.Connect( ) == True: print("数据库连接成功。") self.GetSecurityInfo() else: print("数据库连接失败!") self.InitUserInterface() self.MakeSimulateTrade() #
def InitAssess(self, **kwargs): self.host = kwargs.get("host", "0.0.0.0") self.port = kwargs.get("port", 0) self.user = kwargs.get("user", "user") self.passwd = kwargs.get("passwd", "123456") self.charset = "utf8" self.data_folder = kwargs.get("data_folder", "") # 数据文件夹 self.temp_folder = kwargs.get("temp_folder", "") # 模板文件夹 self.rets_folder = kwargs.get("rets_folder", "") # 结果文件夹 self.db_clearx = "clearx" self.tb_daily_report = "daily_report" self.sheet_daily_report = "daily_report" self.flag_use_database = True if self.host == "0.0.0.0": # 不使用数据库 self.flag_use_database = False self.folder_clearx = "" if self.data_folder != "": self.folder_clearx = self.data_folder + "/clearx" if not os.path.exists(self.folder_clearx): os.makedirs(self.folder_clearx) self.dbm_clearx = None if self.flag_use_database == True: self.dbm_clearx = dbm_mysql.DBM_MySQL( host=self.host, port=self.port, user=self.user, passwd=self.passwd, db=self.db_clearx, charset=self.charset) # db_clearx if self.dbm_clearx.Connect() == True: self.SendMessage("I", self.log_cate, "清算数据库连接完成。") return True else: self.SendMessage("E", self.log_cate, "清算数据库连接失败!") return False return True
def ConnectDB(self): self.DisconnectDB() # try: if self.flag_use_database == True: self.dbm_quotedata = dbm_mysql.DBM_MySQL( host=self.mysql_host, port=self.mysql_port, user=self.mysql_user, passwd=self.mysql_passwd, db=self.mysql_db, charset=self.mysql_charset) if self.dbm_quotedata.Connect() == True: self.SendMessage("数据库 quotedata 连接完成。") return True else: self.dbm_quotedata = None self.SendMessage("数据库 quotedata 连接失败!") else: self.SendMessage("不使用数据库 quotedata 保存行情数据。") return True except Exception as e: self.dbm_quotedata = None self.SendMessage("建立数据库连接发生异常!%s" % e) return False