量化合约开发系统代码流程(Python)*合约量化系统开发定制技术流程
量化投资都是一门高大上的技术,充斥着模型代码和算法假设,门槛非常高。其实,生活中的量化思想无处不在。量化交易系统有很多种,包括跨平台搬砖、趋势交易、对冲交易等。 1.Cross-platform brick moving means that when the price difference between different target platforms reaches a certain amount,it is sold on the platform with high price and bought on the platform with low price. 2.Trend trading will be more complex.It sends out signals of selling and buying according to the indicators of the trend. 3.Hedging refers to the simultaneous execution of two transactions related to the market,with opposite buying and selling directions,equal quantities,and balanced profits and losses to achieve the effect of hedging risks. 发送下单指令.注意:指令将在下次调用:py:meth:wait_update时发出 “”” if self._loop.is_running():#事件循环正在运行 #把下单请求函数打包成task排入事件循环 self.create_task(self._insert_order_async(…)) #下单后获取委托单order order=self.get_order(order_id,account=account) #更新委托单字段 order.update({“order_id”:order_id,”exchange_id”:exchange_id,…}) return order#返回委托单 else:#事件循环还未运行 #打包一个指令包 pack=self._get_insert_order_pack(…) #发送指令包 self._send_pack(pack) ##下单后获取委托单order order=self.get_order(order_id,account=account) #更新委托单字段 order.update({“order_id”:order_id,”exchange_id”:exchange_id,…}) return order#返回委托单 #发送指令包函数 def _send_pack(self,pack): #立即向队列发送指令包 if not self._is_slave: self._send_chan.send_nowait(pack) else: self._master._slave_send_pack(pack) #下单请求函数 async def _insert_order_async(…): #打包一个指令包 pack=self._get_insert_order_pack(…) #发送指令包 self._send_pack(pack) 下单的主要流程为:用协程任务打包一个指令包再发出去。create_task是无阻塞的,创建完task立即返回,get_order获取委托单也是无阻塞的,因此insert_order执行后会立即返回一个Order对象引用——order,不会等待委托单成交与否。 create_task把下单函数打包成task排入事件循环,需要在调用wait_update启动事件循环时才能执行该task并从队列取出指令包并发送向服务端。
发表回复