# pyctpfix **Repository Path**: youngjinliang/pyctpfix ## Basic Information - **Project Name**: pyctpfix - **Description**: 上期ctpfix网关接入demo - **Primary Language**: Python - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2023-11-02 - **Last Updated**: 2025-05-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # pyctpfix #### 介绍 上期ctpfix网关接入demo #### 使用说明 1. 使用demo见ctpfix_demo.py 2. 创建一个类,继承FIXEngine,demo中是创建class Client 3. 可以把需要的配置信息写在__init__的形参中,也可以直接配置在相关函数内。 4. 类内的join方法是fix client的启动方法。 5. 类内可以根据需要创建请求函数和回调函数 #### 回调说明 def onConnect(self, session): """ 连接回调 :param session: :return: """ logging.info("Established connection to %s" % (session.address(), )) # register to receive message notifications on the session which has just been created # 连接后,进行认证 (fix网关结算单已设置自动确认,不然这一步是结算单确认) ctptype = self.reqAuthenticate(session) #在connect里创建的请求函数 session.addMessageHandler(self.onAuthenticate, MessageDirection.INBOUND, ctptype) #添加回调函数onAuthenticate。需要指定ctptype,程序根据ctptype回调相应的函数,ctptyep可以通过msgtype或者msgtype+OnBehalfOfSubID指定;回调处理逻辑在ctpfix.connection.py 211行 session.handle_read(EventType.READ, None) #接收fix网关发来的消息 #### ctp fix协议说明 ctp fix网关使用是在fix标准协议上进行修改过的fix协议。 所以为了适配ctpfix协议,我们需要增加或修改type或者tag ctpfix.FIX42.msgtype.py ctpfix.FIX42.fixtags.py