Go Back   DailyFX Forex Forum | FX Forum > FXCM Products and Services > FXProgrammers > Discussion / Support Forum > Order2Go COM Trading API Support

Reply
 
Thread Tools Rate Thread
  #31 (permalink)  
Old 08-24-2009, 08:45 AM
Member
 
Join Date: Sep 2006
Posts: 29
dwmcqueen is on a distinguished road
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?
Reply With Quote
  #32 (permalink)  
Old 08-25-2009, 11:10 AM
Member
 
Join Date: Oct 2008
Posts: 609
Nikolay.Gekht is on a distinguished road
Yes, you are right.
Reply With Quote
  #33 (permalink)  
Old 09-02-2009, 08:44 PM
Member
 
Join Date: Sep 2006
Posts: 29
dwmcqueen is on a distinguished road
Quote:
Originally Posted by Nikolay.Gekht View Post
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);
Reply With Quote
  #34 (permalink)  
Old 09-02-2009, 09:45 PM
Member
 
Join Date: Oct 2008
Posts: 609
Nikolay.Gekht is on a distinguished road
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.
Reply With Quote
  #35 (permalink)  
Old 09-02-2009, 11:03 PM
Member
 
Join Date: Sep 2006
Posts: 29
dwmcqueen is on a distinguished road
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.
Reply With Quote
  #36 (permalink)  
Old 09-03-2009, 07:14 AM
Member
 
Join Date: Oct 2008
Posts: 609
Nikolay.Gekht is on a distinguished road
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.
Reply With Quote
  #37 (permalink)  
Old 09-17-2009, 09:15 PM
Member
 
Join Date: Sep 2006
Posts: 29
dwmcqueen is on a distinguished road
How did you generate the GUIDs above? I am looking for the for the new CreateOrdersIDE method.
Reply With Quote
Reply

Tags
order2go

Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Disclaimer: Trading foreign exchange on margin carries a high level of risk, and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with foreign exchange trading, and seek advice from an independent financial advisor if you have any doubts. Any opinions, news, research, analyses, prices, or other information contained on this website is provided as general market commentary and does not constitute investment advice. Forex Capital Markets LLC. will not accept liability for any loss or damage, including without limitation to, any loss of profit, which may arise directly or indirectly from use of or reliance on such information.

All times are GMT -5. The time now is 09:06 AM.
Copyright ©2009 Daily FX. All Rights Reserved.