Git Product home page Git Product logo

leopard-quant's Introduction

策略实现

需要实现TemplateSub接口。

type TemplateSub interface {
	OnStart(c Context)
	OnStop(c Context)
	OnTimer(c Context)
	OnTrade(c Context, trade model.Trade)
	OnTick(c Context, ticker model.Ticker)
	OnOrder(c Context, order model.Order)
	Name() string
}

事件引擎

分为普通事件和定时事件。发布事件时不同的种类会被路由到不同的管道,不同类型的事件互不干扰,也因此发布事件是异步的。

由于管道自带阻塞特性,当监听器处理任务执行耗时较长时,发布事件会阻塞。因此实际的任务处理也设计为异步。为了保证不创建过多的协程,选择使用协程池控制。 需要注意的是,同一种类型的事件,如果有多个处理器。则会顺序遍历执行,即他们也会互相影响。

  • 普通事件回调会在协程池中异步执行
  • 定时事件回调在管道中同步执行

eventEngine

网关引擎

负责以一套API对接多个Broker,屏蔽其差异。一般的通信方式为REST/WebSocket。举例当接收到BrokerWebSocket Ticker回调时,会使用事件引擎发布Tick事件。 总之,Broker状态的变化,网关引擎可以通过发布事件的形式告知其他组件。

算法引擎

算法引擎负责与网关交互,监听网关发布的Tick/Trade等事件。

算法模板

算法模板则直接作用于算法的实现。为什么需要算法模板这一层,因为不同的算法可能会订阅同一个币种,算法引擎在回调时可以遍历这些模板进行回调。同时将一些操作封装在模板这一层,降低对算法引擎的感知。

注意:如果回调事件中IO过长,而回调速度过快,会存在并发的问题,需要用户注意。

主引擎

封装了其它引擎中的操作,各组件可调用主引擎访问其他引擎提供的功能。

leopard-quant's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.