当前位置: 首页 > 工具软件 > AIOTrade > 使用案例 >

AioTrade Investigation (Section A: DataServer)

羊渝
2023-12-01
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.
 类似资料:

相关阅读

相关文章

相关问答