コード例 #1
0
def get_period_data_raw(code, start_date, end_date=0, period_type='m'):
    #print("Get Period data ", start_date, end_date, time_converter.datetime_to_intdate(start_date), time_converter.datetime_to_intdate(end_date))
    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('1'))
    if end_date == 0:
        chart_obj.SetInputValue(2, 0)
    else:
        chart_obj.SetInputValue(2,
                                time_converter.datetime_to_intdate(end_date))
    chart_obj.SetInputValue(3, time_converter.datetime_to_intdate(start_date))
    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('1'))
    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 len(data), reversed(data)
コード例 #2
0
 def __init__(self, account_num, account_type, callback):
     self.started = False
     self.conn = connection.Connection()
     self.realtime_order = win32com.client.gencache.EnsureDispatch(
         'DsCbo1.CpConclusion')
     self.handler = win32com.client.WithEvents(self.realtime_order,
                                               _OrderRealtime)
     self.handler.set_params(self.realtime_order, callback)
     print('START Listening CpConclusion')
コード例 #3
0
ファイル: stock_uni_chart.py プロジェクト: wingsof/trader
def get_uni_data(code):
    conn = connection.Connection()
    conn.wait_until_available()

    chart_obj= win32com.client.gencache.EnsureDispatch("CpSysDib.StockUniMst")
    chart_obj.SetInputValue(0, code)
    chart_obj.BlockRequest()

    d = {}
    for i in range(139):
        d[str(i)] = chart_obj.GetHeaderValue(i)

    return [d]
コード例 #4
0
ファイル: stock_uni_chart.py プロジェクト: wingsof/trader
def get_uni_week_data(code):
    conn = connection.Connection()
    conn.wait_until_available()

    data = []
    chart_obj= win32com.client.gencache.EnsureDispatch("CpSysDib.StockUniWeek")
    chart_obj.SetInputValue(0, code)
    chart_obj.BlockRequest()

    data_len = chart_obj.GetHeaderValue(1)
    for i in range(data_len):
        d = {}
        for j in range(9):
            d[str(j)] = chart_obj.GetDataValue(j, i)
        data.append(d)
    return list(reversed(data))
コード例 #5
0
ファイル: abroad_chart.py プロジェクト: wingsof/trader
def get_period_data(code, period_type, count):
    data = []
    conn = connection.Connection()
    while conn.request_left_count() <= 0:
        print('Request Limit is reached')
        time.sleep(1)

    chart_obj = win32com.client.gencache.EnsureDispatch("Dscbo1.CpSvr8300")
    chart_obj.SetInputValue(0, code)
    chart_obj.SetInputValue(1, ord(period_type))

    chart_obj.SetInputValue(3, count)
    chart_obj.BlockRequest()
    print('Abroad data len', code, chart_obj.GetHeaderValue(3))

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

    data = sorted(data, key=lambda x: x['0'])
    return len(data), data
コード例 #6
0
 def __init__(self, account_num, account_type):
     self.account_num = account_num
     self.account_type = account_type
     self.obj = win32com.client.gencache.EnsureDispatch('CpTrade.CpTd0314')
     self.conn = connection.Connection()
コード例 #7
0
ファイル: request_client.py プロジェクト: wingsof/trader
def run(client_name, client_type, client_index, client_count_info):
    global account, _sock, _client_name

    app = QCoreApplication([])
    conn = connection.Connection()
    while True:
        try:
            if conn.is_connected():
                break
            else:
                print('Retry connecting to CP Server')
                time.sleep(5)
        except:
            print('Error while trying to server')

    print('Connected to CP Server')

    while True:
        try:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            server_address = (message.SERVER_IP, message.CLIENT_SOCKET_PORT)
            sock.connect(server_address)
            sock.settimeout(None)
            print('Connected to apiserver')
            break
        except socket.error:
            print('Retrying connect to apiserver')
            time.sleep(1)

    _sock = sock
    socket_notifier = QtCore.QSocketNotifier(sock.fileno(),
                                             QtCore.QSocketNotifier.Read)
    socket_notifier.activated.connect(dispatch_message)

    header = stream_readwriter.create_header(message.COLLECTOR,
                                             message.MARKET_STOCK,
                                             message.COLLECTOR_DATA)

    body = {'client_count_info': client_count_info}
    if client_type == message.CAPABILITY_TRADE:
        body['capability'] = message.CAPABILITY_TRADE
        body['name'] = client_name + '_TR' + str(client_index)
    elif client_type == message.CAPABILITY_REQUEST_RESPONSE:
        body['capability'] = message.CAPABILITY_REQUEST_RESPONSE
        body['name'] = client_name + '_REQ' + str(client_index)
    elif client_type == message.CAPABILITY_COLLECT_SUBSCRIBE:
        body['capability'] = message.CAPABILITY_COLLECT_SUBSCRIBE
        body['name'] = client_name + '_COL' + str(client_index)
    elif client_type == message.CAPABILITY_TRADE_SUBSCRIBE:
        body['capability'] = message.CAPABILITY_TRADE_SUBSCRIBE
        body['name'] = client_name + '_TRCOL' + str(client_index)

    if 'name' in body:
        _client_name = body['name']
        stream_readwriter.CLIENT_NAME = _client_name

    stream_readwriter.write(sock, header, body)

    if body['capability'] & message.CAPABILITY_TRADE or body[
            'capability'] & message.CAPABILITY_TRADE_SUBSCRIBE:
        account = trade_util.TradeUtil()
        print('HAS TRADE CAPABILITY')

    app.exec_()