public partial class Form1 : Form
{
//######################## RTD METHODS ########################
// Test harness that emulates the interaction of
// Excel with an RTD server.
void processRTD()
{
//RTD
int topicID = 100;
const String RTDProgID = "esrtd";
const String topic1 = "HSI J2-HKF";
bool firstUpdate = true;
try
{
Object ret;
// Create the RTD server.
Type rtd;
Object rtdServer = null;
rtd = Type.GetTypeFromProgID(RTDProgID);
rtdServer = Activator.CreateInstance(rtd);
IRtdServer server = rtdServer as IRtdServer;
// Create the updateEvent.
UpdateEvent updateEvent = new UpdateEvent();
ret = server.ServerStart(updateEvent);
// Connect Data.
Object[] topics = new Object[2];
topics[0] = topic1;
topicID++;
topics[1] = "Bid Size";
ret = server.ConnectData(topicID, topics, true);
topicID++;
topics[1] = "Bid";
ret = server.ConnectData(topicID, topics, true);
topicID++;
topics[1] = "Ask";
ret = server.ConnectData(topicID, topics, true);
topicID++;
topics[1] = "Ask Size";
ret = server.ConnectData(topicID, topics, true);
// Loop and wait for RTD to notify (via callback) that
// data is available.
int status = 1;
int topicCount = 4;
double value;
Object[,] r = new Object[2, 4];
while (status == 1 && !_shouldStop)
{
// Check that the RTD server is still alive.
status = server.Heartbeat();
// Get data from the RTD server.
r = server.RefreshData(topicCount);
if (r.Length > 0)
{
for (int i = 0; i < r.Length / 2; i++)
{
value = 0;
double.TryParse(r[1, i].ToString(), out value);
switch (r[0, i].ToString())
{
case bidQtyCode:
marketData.bestBidQty = value;
break;
case bidCode:
marketData.bestBid = value;
break;
case askCode:
marketData.bestAsk = value;
break;
case askQtyCode:
marketData.bestAskQty = value;
break;
}
}
updateDisplay(marketData);
if (firstUpdate)
{
firstUpdate = false;
resizeLadder();
}
}
Thread.Sleep(100);
}
// Disconnect from data topic.
server.DisconnectData(topicID);
// Shutdown the RTD server.
server.ServerTerminate();
}
catch {}
}
public class UpdateEvent : IRTDUpdateEvent
{
public long Count { get; set; }
public int HeartbeatInterval { get; set; }
public UpdateEvent()
{
// Do not call the RTD Heartbeat()
// method.
HeartbeatInterval = -1;
}
public void Disconnect()
{
// Do nothing.
}
public void UpdateNotify()
{
Count++;
}
}
private void button1_Click(object sender, EventArgs e)
{
m_GAPI.sendMsg(textBox1.Text);
}
}
// Form1 Class Ends
public class MarketData
{
private double _bestBid, _bestAsk, _bestBidQty, _bestAskQty;
public double bestBid
{
get { return _bestBid; }
set { _bestBid = value; }
}
public double bestAsk
{
get { return _bestAsk; }
set { _bestAsk = value; }
}
public double bestBidQty
{
get { return _bestBidQty; }
set { _bestBidQty = value; }
}
public double bestAskQty
{
get { return _bestAskQty; }
set { _bestAskQty = value; }
}
}
[ComImport,
TypeLibType((short)0x1040),
Guid("EC0E6191-DB51-11D3-8F3E-00C04F3651B8")]
public interface IRtdServer
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(10)]
int ServerStart([In, MarshalAs(UnmanagedType.Interface)] IRTDUpdateEvent callback);
[return: MarshalAs(UnmanagedType.Struct)]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(11)]
object ConnectData([In] int topicId, [In, MarshalAs(UnmanagedType.SafeArray,
SafeArraySubType = VarEnum.VT_VARIANT)] ref object[] parameters, [In, Out] ref bool newValue);
[return: MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(12)]
object[,] RefreshData([In, Out] ref int topicCount);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(13)]
void DisconnectData([In] int topicId);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(14)]
int Heartbeat();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(15)]
void ServerTerminate();
}
[ComImport,
TypeLibType((short)0x1040),
Guid("A43788C1-D91B-11D3-8F39-00C04F3651B8")]
public interface IRTDUpdateEvent
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(10),
PreserveSig]
void UpdateNotify();
[DispId(11)]
int HeartbeatInterval
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(11)]
get;
[param: In]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(11)]
set;
}
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(12)]
void Disconnect();
}
}