Profile Picture

Requirement for Broker plugin

Posted By silvermoot 8 Years Ago
Message
Posted Thursday August 27 2009
Hi, i want to create a plugin for my broker but i have a problem, i cannot add reference to their library in Right Edge...
It is a COM library, .tlb file....

What do i do? Is it still possible for me to create the plugin?
Posted Thursday August 27 2009
You will need to build your plugin outside of RightEdge, probably in Visual Studio but you could also do it in SharpDevelop or something. I'm not an expert on COM Interop, but if the COM object is usable from .NET, you should be able to get it to work.

Thanks,
Daniel
Posted Thursday August 27 2009
Thank you for the quick reply.

So if i understand well, i create a new project in visual C#, i add all RE dll libs to it, plus my COM lib from my broker and start creating my IBroker interface
Once this is done, how i put all this in the RE plateform?
Posted Friday August 28 2009
silvermoot (8/27/2009)
Thank you for the quick reply.

So if i understand well, i create a new project in visual C#, i add all RE dll libs to it, plus my COM lib from my broker and start creating my IBroker interface
Once this is done, how i put all this in the RE plateform?


Copy the compiled DLL to the Plugins folder under the RightEdge installation directory.

Note that you'll also need to implement the IService interface.

Thanks,
Daniel
Posted Friday August 28 2009
Ok, so i need to create a new library project then.
For the IService interface i have to implement all methods related to feeds and connection like GetTickDataInterface, GetBarDataInterface, Connect
and Disconnect...
I use IQ Feed and i don't need any particular connection/deconnection since all i have to do is to be connected normally in my trading plateform... so i don't want to implement them, i just do nothing in those methods or return null?
Posted Friday August 28 2009
silvermoot (8/28/2009)
Ok, so i need to create a new library project then.
For the IService interface i have to implement all methods related to feeds and connection like GetTickDataInterface, GetBarDataInterface, Connect
and Disconnect...
I use IQ Feed and i don't need any particular connection/deconnection since all i have to do is to be connected normally in my trading plateform... so i don't want to implement them, i just do nothing in those methods or return null?


Correct. There is a sample of a skeleton service included with RightEdge, and we've posted the source to the Interactive Brokers plugin on these forums if you want something to refer to.

Thanks,
Daniel
Posted Friday August 28 2009
Ok yes i got it , thank you
Posted Sunday August 30 2009
Hi there, i implemented my custom IBroker interface and i would like you guys to confirm that i did the right thing.

Before, i just want to explain the basic event structure from my broker:

Case 1 : 1 order with 1 fill
Open order X :
1-stiOrderUpdate event fired (contains the average execution price and the order status)
2-stiTradeUpdate event fired (contains the execution price)

Case 2 : 1 order with 2 partially fills
Open order X :
1-stiOrderUpdate event fired for first partially fill
2-stiTradeUpdate event fired for first partially fill
1-stiOrderUpdate event fired for second partially fill
2-stiTradeUpdate event fired for second partially fill

In my new IBroker interface i mapped RE's OrderUpdated to my stiOrderUpdate and PositionAvailable event to my stiTradeUpdate event

Implementation of:
stiOrderUpdate()
-> basically i just call OrderUpdated(openOrder, null, description);
-> here i don't put anything in the fill parameter...i wait for a stiTradeUpdate

stiTradeUpdate()
-> I create a new fill object based in the execution price that i received and i set the quantity plus FillDateTime
-> If this is the last fill or partially fill, i call OrderUpdated and PositionAvailable

Here is my complete code for those 2 methods:

        
private void STIOrderUpdated(object sender, STIOrderUpdateEventArgs e)
{
SterlingLib.structSTIOrderUpdate s = e.StructOrderUpdate;
RightEdge.Common.BrokerOrder openOrder;
Fill fill = null;
String description = "";

if( openOrders.ContainsKey( s.bstrClOrderId ))
{
openOrder = openOrders[s.bstrClOrderId];

switch (s.nOrderStatus)
{
...
//FILLED
case 5:
//The fill price will be set in OnTradeUpdated()
description = "osSTIFilled";//s.ProcessOrderUpdateFilled(ref structUpdate);
openOrder.OrderState = BrokerOrderState.Filled;
break;
...
case 8:
description = "osSTICanceled";
openOrder.OrderState = BrokerOrderState.Cancelled;
break;
...
//PARTIALLY FILLED
case 10:
//The fill price will be set in OnTradeUpdated()
description = "osSTIPartiallyFilled fExecPrice=" + s.fAvgExecPrice + " nLvsQuantity=" + s.nLvsQuantity;//s.ProcessOrderUpdatePartiallyFilled(ref structUpdate);
openOrder.OrderState = BrokerOrderState.PartiallyFilled;
break;
...
}

//Envoit le signal au framework
OrderUpdated(openOrder, fill, description);

Trace.WriteLine(description);
}
}

private void STITradeUpdated(object sender, STITradeUpdateEventArgs e)
{
SterlingLib.structSTITradeUpdate s = e.StructTradeUpdate;
RightEdge.Common.BrokerOrder openOrder;

if (openOrders.ContainsKey(s.bstrClOrderId))
{
openOrder = openOrders[s.bstrClOrderId];

Fill aFill = new Fill();
aFill.FillDateTime = DateUtil.GetDateFromString(s.bstrTradeTime);
aFill.Price = new Price(s.fExecPrice, s.fExecPrice);
aFill.Quantity = s.nQuantity;
aFill.Commission = 0;

openOrder.Fills.Add(aFill);

//If leaves quantity > 0 then one or more orders may come later to fill the order
//If leaves quantity = 0 that means the order was either completely filled or cancelled
if (s.nLvsQuantity == 0 && openOrder.OrderState != BrokerOrderState.Cancelled)
{
//Envoit le signal au framework
OrderUpdated(openOrder, aFill, "TradeUpdated");
PositionAvailable(openOrder.OrderSymbol, (int)openOrder.Shares);


Trace.WriteLine("PositionAvailable");

if (openOrder.OrderState == BrokerOrderState.Filled ||
openOrder.OrderState == BrokerOrderState.Rejected ||
openOrder.OrderState == BrokerOrderState.Cancelled)
{
openOrders.Remove(openOrder.OrderId);
}
}
}
}



Thank you guys

Edited: Sunday August 30 2009 by silvermoot
Posted Monday August 31 2009
It doesn't sound like you actually need to send anything to RightEdge in response to the stiOrderUpdate event. There might be problems if you update the order status to filled without including the actual fill information.

Also, PositionAvailable doesn't do anything, so there's no need to call it.

Thanks,
Daniel
Posted Monday August 31 2009
Ok so when i trigger the OrderUpdated event its because the trade as been completed...
But as you see i just call it when i received all fills (for partially fills), is it ok to do so?


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems