Beispiel #1
0
    SYMBOL_LIST = [{_NAME: "ESM20_FUT_CME"}, {_NAME: "CLM20_FUT_NYMEX"}]
    # Generate symbol IDs
    for ix, symbol in enumerate(SYMBOL_LIST):
        SYMBOL_LIST[ix][_ID] = get_symbol_id(symbol[_NAME])

    class ExampleDTCClient(DTCClient):
        def __init__(self):
            super().__init__(on_message_handler=self.on_message_thread,
                             post_login_thread=self.post_login_thread)

        def post_login_thread(self):
            for ix, symbol in enumerate(SYMBOL_LIST):
                self.send(
                    MarketDataRequest(
                        request_action=RequestActionEnum.SUBSCRIBE,
                        symbol_id=SYMBOL_LIST[ix][_ID],
                        symbol=symbol[_NAME]))

        def on_message_thread(self, message):
            if isinstance(message, MarketDataSnapshot):
                marketDataSnapshot = MarketDataSnapshot()
                # do something with market data

    try:
        logger = Util.setup_logging("DTC_Client", console=CONSOLE_LOGGING)
        dtc_client = ExampleDTCClient()
        dtc_client.start()
    except BaseException as e:
        logging.error(e.__str__())
        logging.debug(traceback.format_exc())
    def generate_message_types(self, output_directory):
        message_type_dir = join(output_directory, _MESSAGE_TYPE_DIR)
        new_package(message_type_dir)
        template = env.get_template(_MESSAGE_TYPE_TEMPLATE)
        for struct in self.structs:
            name = struct[_PARSED_NAME]
            snake_name = camel_to_snake(name).upper()
            with open(join(message_type_dir, "%s.py" % camel_to_snake(name)),
                      "w") as f:
                f.write(
                    template.render(class_name=name,
                                    class_name_snake=snake_name,
                                    values=struct[_PROPERTIES]))

    def generate_python_code(self, output_directory):
        os.system("rm -rf %s" % output_directory)
        new_package(output_directory)
        self.generate_enums(output_directory)
        self.generate_message_types(output_directory)
        self.generate_message_util(output_directory)


if __name__ == '__main__':
    Util.setup_logging("CppHeaderParser",
                       console=CONSOLE_LOGGING,
                       log_to_file=False)
    parser = DTCProtocolHeaderParser("DTCProtocol.h")
    #logging.info(json.dumps(parser.structs, indent=4))
    parser.generate_python_code(output_directory=GENERATED_DIR)