コード例 #1
0
ファイル: dtcstatic.py プロジェクト: cloudostrich/dtcpy
def conn1(addr, encoding=Dtc.PROTOCOL_BUFFERS, heartbeat_interval=10):
    """ Primary function to connect and logon to DTC server"""
    sock = socket.create_connection(addr)
    # encoding request, construct and send
    enc_req = Dtc.EncodingRequest()
    enc_req.Encoding = encoding
    enc_req.ProtocolType = "DTC"
    enc_req.ProtocolVersion = Dtc.CURRENT_VERSION
    send_message(enc_req, Dtc.ENCODING_REQUEST,
                 sock)  # send the encoding request
    # receive encoding response
    m_type, m_resp = get_message(sock)
    logMsg.debug("%s, %s", m_type[0], m_resp)
    logStdout.debug("%s, %s", m_type[0], m_resp)

    # Logon request, construct and send
    logon_req = Dtc.LogonRequest()
    logon_req.ProtocolVersion = Dtc.CURRENT_VERSION
    # logon_req.Username = "******"
    # logon_req.Password = "******"
    logon_req.GeneralTextData = "John's Test"
    logon_req.HeartbeatIntervalInSeconds = heartbeat_interval
    logon_req.ClientName = "John_Tester"
    send_message(logon_req, Dtc.LOGON_REQUEST, sock)
    # receive logon response
    m_type, m_resp = get_message(sock)
    logMsg.debug("%s, %s", m_type[0], m_resp)
    logStdout.debug("%s, %s", m_type[0], m_resp)

    return sock
コード例 #2
0
ファイル: raw_test.py プロジェクト: cloudostrich/dtcpp
def create_secdef_req(requestID, symbol, exchange):
    data_req = Dtc.SecurityDefinitionForSymbolRequest()
    # data_req.RequestAction = Dtc.SUBSCRIBE
    data_req.RequestID = requestID  # Note: Make sure this is unique when requesting multiple symbols
    data_req.Symbol = symbol
    data_req.Exchange = exchange
    return data_req
コード例 #3
0
ファイル: raw_test.py プロジェクト: cloudostrich/dtcpp
def create_mktdat_req(symbolID, symbol, exchange):
    data_req = Dtc.MarketDataRequest()
    data_req.RequestAction = Dtc.SUBSCRIBE
    data_req.SymbolID = symbolID  # Note: Make sure this is unique when requesting multiple symbols
    data_req.Symbol = symbol
    data_req.Exchange = exchange
    return data_req
コード例 #4
0
ファイル: raw_test.py プロジェクト: cloudostrich/dtcpp
def create_logon_req(heartbeat_interval):
    logon_req = Dtc.LogonRequest()
    logon_req.ProtocolVersion = Dtc.CURRENT_VERSION
    # logon_req.Username = "******"
    # logon_req.Password = "******"
    logon_req.GeneralTextData = "John's Test"
    logon_req.HeartbeatIntervalInSeconds = heartbeat_interval
    logon_req.ClientName = "John_Tester"
    return logon_req
コード例 #5
0
ファイル: dtcstatic.py プロジェクト: cloudostrich/dtcpy
def quit(sock):
    """ Gracefully logoff and close the connection """
    logStdout.debug("Disconnecting from DTC server")
    logMsg.debug("Disconnecting from DTC server")
    # receiver.stop()
    # heartbeat.stop()
    logoff = Dtc.Logoff()
    logoff.Reason = "Client terminating"
    send_message(logoff, Dtc.LOGOFF, sock)
    # Gracefully close the socket
    sock.close()
コード例 #6
0
ファイル: raw_test.py プロジェクト: cloudostrich/dtcpp
def create_histprcdat_req(requestID,
                          symbol,
                          exchange,
                          record_interval,
                          start=0,
                          end=0,
                          max=0):
    data_req = Dtc.HistoricalPriceDataRequest()
    data_req.RequestID = requestID  # Note: Make sure this is unique when requesting multiple symbols
    data_req.Symbol = symbol
    data_req.Exchange = exchange
    data_req.RecordInterval = record_interval
    data_req.StartDateTime = start
    data_req.EndDateTime = end
    data_req.MaxDaysToReturn = max
    return data_req
コード例 #7
0
ファイル: dtcstatic.py プロジェクト: cloudostrich/dtcpy
def secdef(requestID, symbol, exchange, sock, logfile):
    """ Retrieve Security Definition for each symbol. 
    Uses the Market port"""
    # custom logger with own txt file
    logRec = create_logger(logfile)

    # Create sec def request
    data_req = Dtc.SecurityDefinitionForSymbolRequest()
    data_req.RequestID = requestID  # Note: Make sure this is unique when requesting multiple symbols
    data_req.Symbol = symbol
    data_req.Exchange = exchange
    # Send Request and log response
    send_message(data_req, Dtc.SECURITY_DEFINITION_FOR_SYMBOL_REQUEST, sock)
    m_type, m_resp = get_message(sock)
    logRec.debug("%s, %s", m_type[0], m_resp)
    logStdout.debug("%s, %s", m_type[0], m_resp)
    quit(sock)
コード例 #8
0
ファイル: dtcstatic.py プロジェクト: cloudostrich/dtcpy
def history(requestID,
            symbol,
            exchange,
            record_interval,
            sock,
            logfile,
            start=0,
            end=0,
            max=0):
    """Retrieve Historical data direct from DTC"""
    # custom logger with own txt file
    logRec = create_logger(logfile)

    # Create Historical Data Request
    data_req = Dtc.HistoricalPriceDataRequest()
    data_req.RequestID = requestID  # Note: Make sure this is unique when requesting multiple symbols
    data_req.Symbol = symbol
    data_req.Exchange = exchange
    data_req.RecordInterval = record_interval
    data_req.StartDateTime = start
    data_req.EndDateTime = end
    data_req.MaxDaysToReturn = max
    # Send Request and log Response_Header
    send_message(data_req, Dtc.HISTORICAL_PRICE_DATA_REQUEST, sock)
    m_type, m_resp = get_message(sock)
    logRec.debug("%s, %s", m_type[0], m_resp)
    logStdout.debug("%s, %s", m_type[0], m_resp)
    # Get the rest/whole of the historical data
    while True:
        mt, mr = get_message(sock)
        mr1 = chekker2(mr)
        logRec.debug("%s, %s", mt[0], mr1)
        logStdout.debug("%s, %s", mt[0], mr1)
        if mt[0] == 'HISTORICAL_PRICE_DATA_RECORD_RESPONSE' and mr.IsFinalRecord:
            logStdout.info('FINISH')
            break
    quit(sock)
コード例 #9
0
ファイル: raw_test.py プロジェクト: cloudostrich/dtcpp
def create_enc_req(encoding):
    enc_req = Dtc.EncodingRequest()
    enc_req.Encoding = encoding
    enc_req.ProtocolType = "DTC"
    enc_req.ProtocolVersion = Dtc.CURRENT_VERSION
    return enc_req