Codes to pull data from TWS Interactive Broker - C#

Discussion in 'App Development' started by lordoftrades, Apr 9, 2013.

  1. vicirek

    vicirek

    Yes at the core it is field decoding and encoding with conversion from to strings. There is a lot of code in their API (here C++) but you can focus on folders "Shared", "SocketClient" and review some files for example

    ..shared\EClientSocketBaseImpl.h, IBString.h

    here are some code snippets of 1 decoder and encoder showing the action on double using atof (STL), snprintf. Once the encoding/decoding is done appropriate method/callback is called based on message id and API user can process it in appropriate overrided function in their implementation. It would be unlikely that any other mechanism would be used considering that sockets send/receive chars.

    template<>
    void EClientSocketBase::EncodeField<double>(std::wtf:stream& os, double doubleValue)
    {
    char str[128];

    snprintf(str, sizeof(str), "%.10g", doubleValue);

    EncodeField<const char*>(os, str);
    }


    bool EClientSocketBase::DecodeField(double& doubleValue, const char*& ptr, const char* endPtr)
    {
    if( !CheckOffset(ptr, endPtr))
    return false;
    const char* fieldBeg = ptr;
    const char* fieldEnd = FindFieldEnd(fieldBeg, endPtr);
    if( !fieldEnd)
    return false;
    doubleValue = atof(fieldBeg);
    ptr = ++fieldEnd;
    return true;
    }
     
    #21     Apr 11, 2013
  2. hftvol

    hftvol

    thanks for the reference.

     
    #22     Apr 11, 2013