Esempio n. 1
0
    def __init__(self, address='tcp://180.168.146.187:10011', userID='123609', password='******', brokerID='9999'):
        MdApi.__init__(self)
        ly_time.__init__(self)
        tick_sql = PostgreSQL('futures_tick')
        minu_sql = PostgreSQL('futures_min')
        self.tick_sql = tick_sql
        self.minu_sql = minu_sql
        self.ly_print('ly_ctpmd 类')
        self.reqID = 0  # 操作请求编号
        self.tick = {}
        self.tick_his = {}
        self.bar = {}
        self.address = address  # 服务器地址
        self.time_point = {} # 用来记录'rb1901'合成一分钟所需要的时点

        # path = os.getcwd() + '/md/con/'
        path = 'c:/ctp_con/md/'
        if not os.path.exists(path):
            os.makedirs(path)
        self.createFtdcMdApi(path)  # 创建C++环境中的API对象,这里传入的参数是需要用来保存.con文件的文件夹路径
        self.registerFront(self.address)
        # 注册服务器地址
        self.init()
        # 初始化连接,成功会调用onFrontConnected

        self.userID = userID  # 账号
        self.password = password  # 密码
        self.brokerID = brokerID  # 经纪商代码
 def data_test_m(self): # 获取试验数据
     class_sql = PostgreSQL('backtest')
     j_data = class_sql.minute_select('m')
     data = pd.DataFrame(j_data, columns=['时间', '开盘价', '最高价', '最低价', '收盘价', '成交量', '持仓量'])
     data.set_index(['时间'], inplace=True)
     class_pro= kline_process()
     spe = 'm'
     begindate = '2014-12-29'
     enddate = '2018-08-21'
     data = class_pro.minute_day(spe, begindate, enddate, data)
     return data
Esempio n. 3
0
def main():
    sql = PostgreSQL('backtest')
    data = sql.minute_select('j')
    data = pd.DataFrame(
        data, columns=['时间', '开盘价', '最高价', '最低价', '收盘价', '成交量', '持仓量'])
    data.set_index(['时间'], inplace=True)
    self = kline_process()
    spe = 'j'
    begindate = '2014-07-07'
    enddate = '2018-08-28'
    data = self.minute_day(spe, begindate, enddate, data)
    pass
Esempio n. 4
0
 def __init__(self):
     # 动图显示的k线根数
     self.kline_num = 100
     sql = PostgreSQL('backtest')
     data = sql.minute_select('j')
     data = pd.DataFrame(data, columns=['时间', '开盘价', '最高价', '最低价', '收盘价', '成交量', '持仓量'])
     data.set_index(['时间'], inplace=True)
     k_p = kline_process()
     spe = 'j'
     begindate = '2014-07-07'
     enddate = '2018-08-28'
     data = k_p.minute_day(spe, begindate, enddate, data)
     self.data = data
     macd = MACD_JW()
     for i in range(0, len(data)):
         macd.macd_loop(data.loc[i, '收盘价'])
     self.macd = macd
     print('数据Done')
class data_excel:
    def __init__(self):
        pass
    def database_connect(self, database, tablename):
        self.sql = PostgreSQL(database)
        self.sql.minute_create_table(tablename)

    def data_csv(self, tablename):
        filename = 'F:\BackTest\\'
        filename = filename + tablename + '.csv'
        marketdata = pd.read_csv(filename)
        for i in range(0, len(marketdata)):
            t = marketdata.iloc[i, 0]
            o = marketdata.iloc[i, 1]
            h = marketdata.iloc[i, 2]
            l = marketdata.iloc[i, 3]
            c = marketdata.iloc[i, 4]
            v = marketdata.iloc[i, 5]
            op = marketdata.iloc[i, 6]
            self.sql.minute_insert(tablename, t, o, h, l, c, v, op)
        print('Done')
 def database_connect(self, database, tablename):
     self.sql = PostgreSQL(database)
     self.sql.minute_create_table(tablename)
Esempio n. 7
0
 def __init__(self):
     PostgreSQL.__init__(self, 'backtest')
     self.connect()
     pass
Esempio n. 8
0
 def __init__(self):
     PostgreSQL.__init__(self, 'futures_tick')
     w.start()
     time.sleep(5)
Esempio n. 9
0
 def __init__(self, spe, begintime, endtime, periods):
     PostgreSQL.__init__(self, 'backtest')
     self.spe = spe
     self.begintime = begintime
     self.endtime = endtime
     self.periods = periods
Esempio n. 10
0
 def __init__(self):
     sql.__init__(self, 'tradeday')
     self.connect()
Esempio n. 11
0
 def __init__(self, data_dict):
     PostgreSQL.__init__(self, 'futures_min')
     kline_process.__init__(self)
     self.data = data_dict