예제 #1
0
    def get_count(self):
        conn = connection.Connection()
        conn.wait_until_available()

        self.stock_obj = win32com.client.gencache.EnsureDispatch('CpTrade.CpTd6033')
        self.stock_obj.SetInputValue(0, self.account_num)
        self.stock_obj.SetInputValue(1, self.account_type)
        self.stock_obj.SetInputValue(2, 50)
        self.stock_obj.BlockRequest()
        return self.stock_obj.GetHeaderValue(7)
예제 #2
0
    def get_long_codes(self):
        conn = connection.Connection()
        conn.wait_until_available()

        self.stock_obj = win32com.client.gencache.EnsureDispatch('CpTrade.CpTd6033')
        self.stock_obj.SetInputValue(0, self.account_num)
        self.stock_obj.SetInputValue(1, self.account_type)
        self.stock_obj.SetInputValue(2, 50)
        self.stock_obj.BlockRequest()

        long_codes = []
        for i in range(self.stock_obj.GetHeaderValue(7)):
            code = self.stock_obj.GetDataValue(12, i)
            long_codes.append(code)

        return long_codes
예제 #3
0
def check_investor_trend(code, start_date, end_date):
    conn = connection.Connection()
    obj = win32com.client.gencache.EnsureDispatch('CpSysDib.CpSvr7254')
    obj.SetInputValue(0, code)
    obj.SetInputValue(1, 0)
    obj.SetInputValue(2, time_converter.datetime_to_intdate(start_date))
    obj.SetInputValue(3, time_converter.datetime_to_intdate(end_date))
    obj.SetInputValue(4, ord('0'))
    obj.SetInputValue(5, 0)
    obj.SetInputValue(6, ord('1'))
    now = datetime.now()
    continue_request = True
    datas = []
    prev = None
    while continue_request:
        conn.wait_until_available()
        obj.BlockRequest()
        count = obj.GetHeaderValue(1)

        if count == 0:
            break
        for i in range(count):
            d = {}
            for j in range(19):
                d[str(j)] = obj.GetDataValue(j, i)
            
            if prev != None and prev['0'] <= d['0']:
                continue_request = False
                break
            
            if now - time_converter.intdate_to_datetime(d['0']) > timedelta(days=365*5):
                continue_request = False
            prev = d
            datas.append(d)

    datas = sorted(datas, key=lambda x: x['0'])
    return datas
예제 #4
0
def get_today_data_raw(code, period_type):
    data = []
    conn = connection.Connection()
    conn.wait_until_available()

    chart_obj = win32com.client.gencache.EnsureDispatch("CpSysDib.StockChart")
    chart_obj.SetInputValue(0, code)
    chart_obj.SetInputValue(1, ord('2'))
    chart_obj.SetInputValue(4, 10000)
    data_list = [0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 16, 17, 20, 21]
    chart_obj.SetInputValue(5, data_list)
    chart_obj.SetInputValue(6, ord(period_type))
    chart_obj.SetInputValue(9, ord('0'))
    chart_obj.SetInputValue(10, ord('1'))
    chart_obj.BlockRequest()

    data_len = chart_obj.GetHeaderValue(3)
    for i in range(data_len):
        d = {}
        for j in range(len(data_list)):
            d[str(j)] = chart_obj.GetDataValue(j, i)
        data.append(d)

    return reversed(data)
예제 #5
0
    def get_long_list(self):
        conn = connection.Connection()
        conn.wait_until_available()

        self.stock_obj = win32com.client.gencache.EnsureDispatch('CpTrade.CpTd6033')
        self.stock_obj.SetInputValue(0, self.account_num)
        self.stock_obj.SetInputValue(1, self.account_type)
        self.stock_obj.SetInputValue(2, 50)
        self.stock_obj.BlockRequest()

        long_list = []
        for i in range(self.stock_obj.GetHeaderValue(7)):
            code = self.stock_obj.GetDataValue(12, i)
            name = self.stock_obj.GetDataValue(0, i)
            quantity = self.stock_obj.GetDataValue(7, i)
            sell_available = self.stock_obj.GetDataValue(15, i)
            price = self.stock_obj.GetDataValue(17, i)
            all_price = price * quantity
            d = {'code': code, 'name': name, 'quantity': quantity,
                 'sell_available': sell_available, 'price': price,
                 'all_price': all_price}
            long_list.append(d)

        return long_list