AioTrade Investigation (Section A: DataServer)

本文介绍了AioTrade中DataServer的功能与工作流程。DataServer负责从数据源加载报价数据并进行处理,不再保存数据,记录订阅的合约及符号到合约的映射。通过心跳事件触发数据加载请求,完成数据处理后通知处理完毕。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

AioTrade Investigation (Section A: DataServer)
guibin.beijing@gmail.com
AioTrade source code: [url]https://github.com/dcaoyuan/aiotrade[/url]

Note: The DataServer we are talking about is just org.aiotrade.lib.math.timeseries.DataServer, and the source code can be found at [url]https://github.com/dcaoyuan/aiotrade/tree/master/libs/lib.math/src/main/scala/org/aiotrade/lib/math/timeseries/datasource/DataServer.scala[/url]

DataServer's responsibility is to load the quote data from some data source, and do the processing logic via processData. The old version DataServer could save the data in its storage quotes, but now it doesn't.

This DataServer also records the contract who subscribe this DataServer, and records the symbol to contract mapping. One DataServer could act as the data source for several uniSymbols. According to the design, each security could have its own data server, different security could have different data server.

1. object DataServer
This [b]object DataServer[/b] just publish the heart beat to drive the workflow in class DataServer. The heart beat is implemented by the simple timer.

2. Workflow of class DataServer
e: event; a: action.
e: [u]HeartBeat(interval) [/u]-> e: [u]AskLoadData(loadedTime, subscribedContracts)[/u] -> a: [u][b]requestData(afterTime, contracts) [/b][/u]-> e: [u]DataLoaded(values: Array[V], contract)[/u] -> a: [u][b]processData(values, contract.asInstanceOf[C])[/b][/u] -> e: [u]DataProcessed[/u]

3. Explanation for the workflow
The object DataServer fires the heart beat periodically, class DataServer should listen to this object DataServer. When receives the heart beat, class DataServer will judge whether it should react to this. If it is refreshable and is not loading data at that moment, it will react to publish the AskLoadData event to drive the requestData action.
In the requestData action, class DataServer should request the data from the itself's data source, such as database, dbf, yahoo's web service etc.
When finishes requesting data, it should publish the event DataLoaded to drive the processData. The logic in the processData can be merging the tickers into time serieses.
After processing data, class DataServer will publish the event DataProcessed to notify its finishing processing data.

4. Other functions in class DataServer
Class DataServer has a method named [u]protected def publishData(msg: Any)[/u], by default, it will publish msg to local reactor. If necessary, we can override this function to publish the msg to remote reactor via AMQP etc.
The methods startRefresh and stopRefresh can be use to enable or disable the heart beat to let the workflow work or not.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值