Reading data from Dukascopy tick binary file

后端 未结 2 988
陌清茗
陌清茗 2020-12-09 06:52

I have downloaded the Dukascopy tick data and I have decompressing it with easylzma library. The original compressed binary file is EURUSD/2010/00/08/12h_ticks.bi5 (EURUSD/2

相关标签:
2条回答
  • 2020-12-09 07:28

    ii1 is seconds within this hour

    ii2 is Ask * 10000

    ii3 is Bid * 10000

    ff1 is Ask Volume

    ff2 is Bid Volume

    0 讨论(0)
  • 2020-12-09 07:33

    The data appears to be stored in big endian format in the file. You'll need to convert it to little endian when you load it.

    #include <iostream>
    #include <fstream>
    #include <algorithm>
    
    template<typename T>
    void ByteSwap(T* p)
    {
        for (int i = 0;  i < sizeof(T)/2;  ++i)
            std::swap( ((char *)p)[i], ((char *)p)[sizeof(T)-1-i] );
    }
    
    int main()
    {
        int ii1;
        int ii2;
        int ii3;
        float ff1;
        float ff2;
        std::ifstream in("12h_ticks",std::ofstream::binary);
        in.read((char*)(&ii1), sizeof(int));
        in.read((char*)(&ii2), sizeof(int));
        in.read((char*)(&ii3), sizeof(int));
        in.read((char*)(&ff1), sizeof(float));
        in.read((char*)(&ff2), sizeof(float));
    
        ByteSwap(&ii1);
        ByteSwap(&ii2);
        ByteSwap(&ii3);
        ByteSwap(&ff1);
        ByteSwap(&ff2);
    
        std::cout << " ii1=" << ii1 << std::endl;
        std::cout << " ii2=" << ii2 << std::endl;
        std::cout << " ii3=" << ii3 << std::endl;
        std::cout << " ff1=" << ff1 << std::endl;
        std::cout << " ff2=" << ff2 << std::endl;
        in.close();
        return 0;
    }
    

    This gives the result:

    ii1=970
    ii2=143040
    ii3=143030
    ff1=6.4
    ff2=9.5
    

    I grabbed the ByteSwap function from here if you want to read more about that subject. How do I convert between big-endian and little-endian values in C++?

    0 讨论(0)
提交回复
热议问题