Hello, welcome back to my blog about automated trading. Last week I have made example for the stocks screening. This week I will write about the quotes during trading session.
For the source code example, please download repository and update to branch 4-real-time-quotes, changeset f33d07def714.
For the source code example, please download repository and update to branch 4-real-time-quotes, changeset f33d07def714.
Background
Realtime quotes are another essential part of the system for the automated trading. As historical quotes are used during the night for heavy computing, real time quotes are used during the trading session for knowing immediate price (and others). In my system real time quotes has the following data.
- Symbol - company identification
- Timestamp
- Previous close - close price from the previous trading day
- Open - price at the open
- Bid
- Ask
- Volume
Coding
On the broker side, typically there is exposed very simplistic API. Client needs to log in and subscribe or unsubscribe quotes. Then there are few administrative messages (e.g. heartbeat, error, logout). That's it. So let's look to the source code. I have implemented solution which works with MbTrading.
First there are 2 interfaces - QuoteConnector and QuoteReceiver. QuoteConnector is the actual class which allows QuoteReceiver to register for subscription. QuoteReceiver then receives the subscribed quotes. Then the actual implementation is done through MbTradingQuoteConnector with unit test MbTradingQuoteConnectorTest. Now if you have trading account with MbTrading, then you can fill in credentials into MbTradingQuoteConnectorTestInternetApp and connect it with the actual broker. And finally as I have talked about the speed, then there is example for performance testing - MbTradingQuoteUtilsPerformanceTestApp. This is application which measures how fast I am able to parse broker message received. I personally use this style for any optimization, knowing that unit test will cover the correct functionality. So play with that and have fun!
First there are 2 interfaces - QuoteConnector and QuoteReceiver. QuoteConnector is the actual class which allows QuoteReceiver to register for subscription. QuoteReceiver then receives the subscribed quotes. Then the actual implementation is done through MbTradingQuoteConnector with unit test MbTradingQuoteConnectorTest. Now if you have trading account with MbTrading, then you can fill in credentials into MbTradingQuoteConnectorTestInternetApp and connect it with the actual broker. And finally as I have talked about the speed, then there is example for performance testing - MbTradingQuoteUtilsPerformanceTestApp. This is application which measures how fast I am able to parse broker message received. I personally use this style for any optimization, knowing that unit test will cover the correct functionality. So play with that and have fun!
That's it for today. Next week I will introduce the generic interface for the trading algorithms. Thank you for reading!
No comments:
Post a Comment