|
|
 |
|

08-24-2009, 08:45 AM
|
|
Member
|
|
Join Date: Sep 2006
Posts: 29
|
|
|
Just to confirm - until OTO support is there, the OCO group will still hang out there and will need to be closed if the underlying market order is manually closed, correct?
|

08-25-2009, 11:10 AM
|
|
Member
|
|
Join Date: Oct 2008
Posts: 609
|
|
|
Yes, you are right.
|

09-02-2009, 08:44 PM
|
|
Member
|
|
Join Date: Sep 2006
Posts: 29
|
|
Quote:
Originally Posted by Nikolay.Gekht
You must create the object as the core object, i.e. using the OrdersIDEnumAut.CreateInstance method. This is the standard ATL approach to create the ole automation objects.
Please see an example below. The OCO-related code is shown in bold.
Code:
void main(int argc, char **argv)
{
//read input parameters
if (argc < 3)
{
printf("Usage: TestOCO.exe LoginID Password [Terminal URL]\n");
return;
}
const char *szLogin = argv[1];
const char *szPwd = argv[2];
const char *szHost = argc > 3 ? argv[3] : "Demo";
const char *szUrl = argc > 4 ? argv[4] : "www.fxcorporate.com";
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
FXCore::ICoreAutPtr pCore;
FXCore::ITradeDeskAutPtr pTradeDesk;
try
{
//--------------------------------------------------------------------------------
//create o2go object and login
//--------------------------------------------------------------------------------
HRESULT hr = pCore.CreateInstance(__uuidof(FXCore::CoreAut));
if (FAILED(hr))
{
printf("Failed to create CoreAut instance.");
return;
}
//create trader trade desk and log in
pTradeDesk = pCore->CreateTradeDesk("trader");
printf("Connectig to the server(%s, %s, %s, %s)...\n", szLogin, szPwd, szUrl, szHost);
pTradeDesk->Login(szLogin, szPwd, szUrl, szHost);
printf("Connected successfully.\n");
//--------------------------------------------------------------------------------
//collect all required information
//--------------------------------------------------------------------------------
FXCore::ITableAutPtr acct = pTradeDesk->FindMainTable("accounts");
FXCore::ITableAutPtr offer = pTradeDesk->FindMainTable("offers");
_bstr_t account_id = acct->CellValue(1, "AccountID").bstrVal;
int unit_size = acct->CellValue(1, "BaseUnitSize").intVal;
_bstr_t instrument = offer->CellValue(1, "Instrument").bstrVal;
double ask = offer->CellValue(1, "Ask").dblVal;
double bid = offer->CellValue(1, "Bid").dblVal;
double ptsize = offer->CellValue(1, "PointSize").dblVal;
//--------------------------------------------------------------------------------
//create the entry orders
//--------------------------------------------------------------------------------
VARIANT vOrderID, vDealInt;
VariantInit(&vOrderID);
VariantInit(&vDealInt);
printf("Create the first entry order...\n");
pTradeDesk->CreateEntryOrder(account_id, instrument, true, unit_size, ask + ptsize * 100, 0,0,0, &vOrderID, &vDealInt);
_bstr_t order1 = vOrderID.bstrVal;
VariantClear(&vOrderID);
VariantClear(&vDealInt);
printf("The order %s is created\n", (LPCTSTR)order1);
printf("Create the second entry order...\n");
pTradeDesk->CreateEntryOrder(account_id, instrument, true, unit_size, ask + ptsize * 100, 0,0,0, &vOrderID, &vDealInt);
_bstr_t order2 = vOrderID.bstrVal;
VariantClear(&vOrderID);
VariantClear(&vDealInt);
printf("The order %s is created\n", (LPCTSTR)order2);
//--------------------------------------------------------------------------------
//create an OCO
//--------------------------------------------------------------------------------
printf("Create an OCO...\n");
FXCore::IOrdersIDEnumAutPtr pEnum;
hr = pEnum.CreateInstance(__uuidof(FXCore::OrdersIDEnumAut));
pEnum->Add(order1);
pEnum->Add(order2);
VARIANT vResult, vOCOID;
pTradeDesk->CreateOCO(pEnum, &vResult, &vOCOID);
int OCO = vOCOID.iVal;
VariantClear(&vResult);
VariantClear(&vOCOID);
printf("The OCO %d is created\n", OCO);
//--------------------------------------------------------------------------------
//finalizing
//--------------------------------------------------------------------------------
printf("Disconnecting...\n");
pTradeDesk->Logout();
printf("Disconnected.\n");
}
catch(_com_error e)
{
//errors processing
_bstr_t c = e.Description();
if (c.length() == 0)
c = e.ErrorMessage();
printf("An error occurs. Error details: '%s'.\n", (const char*)c);
if (pTradeDesk->IsLoggedIn())
pTradeDesk->Logout();
}
CoUninitialize();
}
|
Is there any alternative for initializing that object perhaps using CoCreateInstance? ? Up until now I have been able to avoid ATL, but my CoCreateInstance call fails:
IOrdersIDEnumAut* pGroup;
hResult = CoCreateInstance(CLSID_OrdersIDEnumAut,NULL,CLSCTX _INPROC_SERVER,IID_IOrdersIDEnumAut,(void**)&pGrou p);
|

09-02-2009, 09:45 PM
|
|
Member
|
|
Join Date: Oct 2008
Posts: 609
|
|
Here is a short example which demonstrates work with the IOrdersIDEnumAut interfaces from plain C++.
Code:
#include <windows.h>
#include <stdio.h>
extern const CLSID IID_IOrdersIDEnumAut = {0x683c7df3, 0x7279, 0x4757, { 0x9c, 0xbc, 0x9f, 0x74, 0xa5, 0xcf, 0x8b, 0x21}};
extern const CLSID CLSID_OrdersIDEnumAut = {0xe19e101e, 0x6d95, 0x4aa1, {0xad, 0xe0, 0xad, 0xa5, 0xb2, 0x17, 0x8a, 0x0d}};
class IOrdersIDEnumAut : public IDispatch
{
public:
virtual HRESULT __stdcall get_Count (
/*[out,retval]*/ long * plCount ) = 0;
virtual HRESULT __stdcall raw_Item (
/*[in]*/ long lIndex,
/*[out,retval]*/ BSTR * psOut ) = 0;
virtual HRESULT __stdcall _NewEnum (
/*[out,retval]*/ IUnknown * * ppUnknown ) = 0;
virtual HRESULT __stdcall Add (
/*[in]*/ BSTR sOrderID ) = 0;
virtual HRESULT __stdcall Remove (
/*[in]*/ BSTR sOrderID ) = 0;
virtual HRESULT __stdcall RemoveAt (
/*[in]*/ long lIndex ) = 0;
virtual HRESULT __stdcall Clear ( ) = 0;
virtual HRESULT __stdcall Contains (
/*[in]*/ BSTR sOrderID,
/*[out,retval]*/ VARIANT_BOOL * bIsExists ) = 0;
};
void main(void)
{
CoInitialize(0);
IOrdersIDEnumAut *group = 0;
HRESULT hr = CoCreateInstance(CLSID_OrdersIDEnumAut, 0, CLSCTX_INPROC_SERVER, IID_IOrdersIDEnumAut, (void **)&group);
if (FAILED(hr))
{
printf("CoCreateInstance failed: %08x\n", hr);
return ;
}
group->Add(L"1");
group->Add(L"2");
group->Add(L"3");
VARIANT_BOOL out;
group->Contains(L"1", &out);
printf("%i\n", out);
group->Contains(L"4", &out);
printf("%i\n", out);
group->Release();
}
Compile it using cl q.cpp -link ole32.lib (VCVARS has to be applied).
p.s. Please, pay attention on correct GUIDs and interfaces in your example.
|

09-02-2009, 11:03 PM
|
|
Member
|
|
Join Date: Sep 2006
Posts: 29
|
|
|
There must be something wrong with my Order2Go installation - first the C# issue and now this - your examples work fine from the command line but running my other applications outside of the command line don't.
|

09-03-2009, 07:14 AM
|
|
Member
|
|
Join Date: Oct 2008
Posts: 609
|
|
|
It rather looks like something wrong with supplementary files, like an interop library for C# and headers for C++. Unfortunately, I'm writing right now from air, but I'll prepare and the both today's evening.
|

09-17-2009, 09:15 PM
|
|
Member
|
|
Join Date: Sep 2006
Posts: 29
|
|
|
How did you generate the GUIDs above? I am looking for the for the new CreateOrdersIDE method.
|
 |
|
| Thread Tools |
|
|
| Rate This Thread |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|