vnpy/UML/dataRecord.puml

223 lines
5.9 KiB
Plaintext
Raw Normal View History

2018-04-07 00:56:19 +00:00
@startuml
2018-04-08 14:31:33 +00:00
database mongoDB as db
2018-04-09 08:44:04 +00:00
participant runDataRecord as rundr
participant Process as run
2018-04-07 00:56:19 +00:00
participant MainEngine as me
2018-04-09 08:44:04 +00:00
participant LogEngine as runle
2018-04-09 12:18:24 +00:00
participant DataEngine as dte
2018-04-08 14:31:33 +00:00
participant LogEngine as le
2018-04-07 00:56:19 +00:00
participant DrEngine as dr
participant Queue as drq
2018-04-08 14:31:33 +00:00
participant Thread as drt
2018-04-07 00:56:19 +00:00
participant eventEngine as ee
2018-04-09 08:44:04 +00:00
participant EventProcessThread as eet
2018-04-07 00:56:19 +00:00
participant Queue as eeq
2018-04-09 08:44:04 +00:00
participant TimerThread as eetm
2018-04-10 06:41:45 +00:00
participant "ibGateway:vtGateway" as gw
participant "IbWrapper:EWrapper" as wrap
2018-04-07 00:56:19 +00:00
2018-04-09 08:44:04 +00:00
activate rundr
loop
2018-04-10 06:41:45 +00:00
rundr->rundr: 检查是否处于交易时间段\n非交易时间段不起动子进程
rundr->rundr: 若处于非交易时间段 && 有子进程存在,\n就终止子进程运行
rundr->run ** : 若处于交易时间段 && 不存在子进程\ncreate process
2018-04-09 08:44:04 +00:00
activate run
rundr->rundr: sleep(5)
end loop
deactivate rundr
run->runle ** : create runle
|||
2018-04-08 14:31:33 +00:00
|||
2018-04-09 08:44:04 +00:00
run->ee ** :create evnetEngine object
activate ee
ee->ee ++ : init()
ee->eeq ** : Create Queue
ee->eet ** : Create event process thread
note right: 事件处理子线程
ee->eetm ** : Create timer thread
note right: 定时器子线程
return
return object
2018-04-08 14:31:33 +00:00
|||
2018-04-09 08:44:04 +00:00
|||
run->me ** : new mainEngine(ee)
activate me
me->me ++ : init()
me->ee ++ : ee.start()
2018-04-08 14:31:33 +00:00
note right: 启动ee的子线程
2018-04-09 08:44:04 +00:00
ee->eet ++ #red : thread.start()
ee->eetm ++ #green : timer.start()
ee-->me--: return
2018-04-09 12:18:24 +00:00
me->dte ** :创建DataEngine()
activate dte
dte->dte ++ : init()
2018-04-10 06:41:45 +00:00
dte->dte ++ : loadContract()
return
|||
2018-04-09 12:18:24 +00:00
dte->dte ++ : registerEvent()
2018-04-10 06:41:45 +00:00
dte->ee ++ : ee.register(交易类事件, 对应的事件处理句柄)
note right
**以下事件处理句柄都在DataEngine中定义**
(EVENT_CONTRACT, processContractEvent) 合约
(EVENT_ORDER, processOrderEvent) 订单
(EVENT_TRADE, processTradeEvent) 交易
(EVENT_POSITION, processPositionEvent) 头寸
(EVENT_ACCOUNT, processAccountEvent) 帐号
(EVENT_LOG, processLogEvent) LOG
(EVENT_ERROR, processErrorEvent) ERROR
end note
2018-04-09 12:18:24 +00:00
return
2018-04-10 06:41:45 +00:00
return
2018-04-08 14:31:33 +00:00
return
2018-04-09 08:44:04 +00:00
return object
me->le ** :创建LogEngine()
activate le
le->le ++ : init()
return
return
me-->me--:return
me-->run--: object
2018-04-08 14:31:33 +00:00
|||
|||
2018-04-10 06:41:45 +00:00
run->me ++ : addGateway(ibGateway)
me->gw ** : Create IbGateway(ee, "IB")
activate gw
gw->gw ++ : init()
note right
** 将ee保存到私有变量
** 内部变量初始化为空
** 获取连接IB G/W的信息
end note
gw->wrap ** : Create IbWrap(self)
note right
EWrapper类是C++实现, 存在于IB提供的源代码中。
通过boost.python机制
Python的IbWrapper类从EWrapper派生
end note
activate wrap
wrap->wrap ++ : 构造函数()
return object
return object
return
return object
2018-04-08 14:31:33 +00:00
return
|||
|||
2018-04-10 06:41:45 +00:00
run->me ++ : addApp()
2018-04-09 08:44:04 +00:00
me->dr**: new DrEngine(me,ee)
activate dr
dr->dr++:init()
dr->drq **:Create Queue
dr->drt **:Create Thread
activate drt #blue
dr->dr:loadSetting()
note right
从配置文件中加载
订阅设置到字典对象
end note
dr->ee++:register(TICK, handler)
return
2018-04-10 06:41:45 +00:00
dr-->dr -- :
2018-04-09 08:44:04 +00:00
dr-->me--: object
2018-04-10 06:41:45 +00:00
|||
me->me ++ : 初始化其他内部变量
return
run<--me -- : return
|||
|||
run->ee: ee.regiser() 注册日志处理事件
activate ee
note right
登记EVENT_LOG事件处理句柄
登记EVENT_ERROR事件处理句柄
end note
return
|||
|||
run->me++: me.Connect(IB)
note right: 连接IB网关
me->gw ++ : gw.connect()
gw-> wrap : wrap.eConnect(host, port, clientId, false)
return
me->me ++ : dbConnect()
me->db ++ : MongoClient()
return dbClinet
me->ee ++ : ee.register(EVENT_LOG, self.dbLogging)
return
return
2018-04-09 08:44:04 +00:00
run<--me--:return
2018-04-07 00:56:19 +00:00
2018-04-08 14:31:33 +00:00
|||
|||
2018-04-09 08:44:04 +00:00
run->ee ++ : ee.register(EVENT_LOG, le.processLogEvent)
return
|||
|||
run->ee ++ : ee.register(EVENT_ERROR, le.processErrorEvent)
return
|||
|||
loop
run->run: sleep(1)
end loop
deactivate run
|||
|||
gw->eeq ++: queue.put(tick/bar)
return
|||
|||
eetm->ee -- : ee.__runTimer()
activate ee #green
loop
ee->eeq ++ : queue.put(定时器事件)
return
ee->ee : 休眠1秒
end loop
deactivate ee
|||
|||
eet->ee--: ee.run()
activate ee #red
loop
ee->eeq ++ :queue.get()
return event
ee->ee ++ : __process(event)
ee->dr ++ #red :call procecssTickEvent()
dr->dr ++ :OnTick()
dr->drq ++: queue.put(tick)
2018-04-08 14:31:33 +00:00
return
2018-04-09 08:44:04 +00:00
return
2018-04-07 00:56:19 +00:00
2018-04-09 08:44:04 +00:00
dr->dr ++ :OnBar()
dr->drq ++: queue.put(bar)
2018-04-08 14:31:33 +00:00
return
return
return
2018-04-09 08:44:04 +00:00
return
end loop
deactivate ee
2018-04-07 00:56:19 +00:00
2018-04-09 08:44:04 +00:00
drt->dr -- :run()
activate dr #blue
loop
dr->drq ++ :queue.get()
drq-->dr --:data
dr->me:insertDB(data)
end loop
deactivate dr
2018-04-07 00:56:19 +00:00
2018-04-09 08:44:04 +00:00
me->db: 写入mongoDB
2018-04-07 00:56:19 +00:00
@enduml