C# Programming
07-11-2009, 03:00 PM
Hi there,
I have a StreamEvent from a StockExchange Data Provider API. The Event is triggered every time a new price occurs for the respective Instrument on the Exchange.
I can fill the Stream with multiple Intruments, lets say 50.000. So the StreamEvent is triggered about mutiple thousand times in one second.
In the Stream, I first check the price difference in percent between the last price and the new one:
private double abw;
void TPBrief_Brief(int SymbolNr, float NewPrice, float Volume, DateTime Time)
{
abw = (((InstrumentObject)os[SymbolNr]).LastPrice - NewPrice) / (((InstrumentObject)os[SymbolNr]).LastPrice/ 100);
if (abw >= 1.5) {//do whatever}
// rest of code
}
As you can see, I hold my Instrument Objects in a Hashtable, key is Symbolnr, value the InstrumentObject. The first line in this event is the one which is triggered that often, so I just want to know how to optimize this line.
As I learned from various articles, Hashtable should be replaced with a Dictionary, this is one thing I will do.
But what about this variation:
void TPBrief_Brief(int SymbolNr, float NewPrice, float Volume, DateTime Time)
{
IntrumentObject io = ((InstrumentObject)os[SymbolNr]);
abw = (io.LastPrice - NewPrice) / (io.LastPrice/ 100);
if (abw >= 1.5) {//do whatever}
// rest of code
}
Could this be faster than the first one? What's about the Calculation of the difference? Can this code fragment be optimized?
Any help would be appreciated!
I have a StreamEvent from a StockExchange Data Provider API. The Event is triggered every time a new price occurs for the respective Instrument on the Exchange.
I can fill the Stream with multiple Intruments, lets say 50.000. So the StreamEvent is triggered about mutiple thousand times in one second.
In the Stream, I first check the price difference in percent between the last price and the new one:
private double abw;
void TPBrief_Brief(int SymbolNr, float NewPrice, float Volume, DateTime Time)
{
abw = (((InstrumentObject)os[SymbolNr]).LastPrice - NewPrice) / (((InstrumentObject)os[SymbolNr]).LastPrice/ 100);
if (abw >= 1.5) {//do whatever}
// rest of code
}
As you can see, I hold my Instrument Objects in a Hashtable, key is Symbolnr, value the InstrumentObject. The first line in this event is the one which is triggered that often, so I just want to know how to optimize this line.
As I learned from various articles, Hashtable should be replaced with a Dictionary, this is one thing I will do.
But what about this variation:
void TPBrief_Brief(int SymbolNr, float NewPrice, float Volume, DateTime Time)
{
IntrumentObject io = ((InstrumentObject)os[SymbolNr]);
abw = (io.LastPrice - NewPrice) / (io.LastPrice/ 100);
if (abw >= 1.5) {//do whatever}
// rest of code
}
Could this be faster than the first one? What's about the Calculation of the difference? Can this code fragment be optimized?
Any help would be appreciated!