Code Monkey home page Code Monkey logo

truefx-to-zorro's Introduction

TrueFX-to-Zorro

Convert TrueFX.com tick data to Zorro-Trader.com .t6 bar format

In and Out

######Download URL example (requires login after free registration) http://truefx.com/dev/data/2016/MAY-2016/EURUSD-2016-05.zip

######Content EUR/USD,20160502 00:00:00.959,1.14601,1.14605 EUR/USD,20160502 00:00:00.991,1.14599,1.14605 EUR/USD,20160502 00:00:01.018,1.14599,1.14604 EUR/USD,20160502 00:00:01.078,1.14599,1.14605

######Zorro .t6 format typedef struct T6 { DATE time; //double, 8bytes, base 1900-01-01 float fHigh, fLow; //single float fOpen, fClose; float fVal, fVol; // additional data, like ask-bid spread, volume etc. } T6;

Aggregation

Each bar contains predefined number of ticks, like 1000. Time increment is then irregular by definition. Begin a fresh bar also after weekends, holidays.

Spread Increase Before Weekend

USD/JPY,20160506 20:59:56.266,107.089996,107.166
USD/JPY,20160506 20:59:56.291,107.089996,107.209999
USD/JPY,20160506 20:59:56.414,106.986,107.265999
USD/JPY,20160506 20:59:58.136,106.986,107.265999
USD/JPY,20160506 20:59:59.085,106.978996,107.273003
USD/JPY,20160506 20:59:59.203,106.978996,107.273003
USD/JPY,20160506 20:59:59.437,106.917999,107.488998
USD/JPY,20160509 00:00:00.026,107.359001,107.366997
USD/JPY,20160509 00:00:00.140,107.359001,107.366997
![Zorro Chart Viewer with N-tick chart](./doc/img/ PlotCurve_USDJPY.png)

Example conversion

ZHistoryEdit.exe (linked from Zorro download page) can create .t6 files

Converting .zip to .gz

.gz format is the one supported by zlib stdio-like functions gzgets() and others. TrueFX files are .zip, however.
Here's how the conversion from .zip to .gz can be done without ever storing the infalted file on disk. gzip is able to create .gz files from stdin, which is fed by fUnZip:

funzip.exe EURUSD-2016-06.zip | gzip -9 > EURUSD-2016-06.csv.gz

Here's an example code using zlib using stdio-like access, reading the first line from .gz file:

#include "zlib/zlib.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
    const char *fname = "short.txt.gz";
    gzFile fr;
    Byte *uncompr;
    uLong uncomprLen = 10000*sizeof(int);
    uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
    strcpy((char*)uncompr, "garbage");

    fr = gzopen(fname, "rb");
    if (fr == NULL) {
        printf("gzopen error\n");
        exit(1);
    }
    gzgets(fr, (char*)uncompr, (int)uncomprLen);
    printf("uncompr==%s\n", uncompr);
    gzclose(fr);

    free(uncompr);
    return(0);
} 

Links (which contributed to the code)

fUnZip for extracting .zip to stdout and gzip for making .gz from stdin
http://stackoverflow.com/questions/7775027/how-to-create-file-of-x-size
Converting from year-month-day-... to microsoft VariantTime - Reactos sources, they in turn borrowed from PostgreSQL
how-is-variant-time-date-double-8-byte-handled on Stackoverflow - pointing to Reactos

Links (just for info)

wget for download, here is the setup for Windows and the manual
There are also curl and aria2 out there
TrueFX download script - fails
Recursively list directories in C
Doubly-Linked List in C How are zlib, gzip and zip related
zlib cannot handle zip, see contrib/minizip for wrapper or see Mark Adler's sunzip or winimage.com/zLibDll
zlib, example of stdio-like gzopen() and gzgets()
standalone conversion for epoch see also CRAN lubridate source; not used in this code
Mathias Svensson TimeConverion GUI

Thrown away

Here is a (Windows) command line to convert .zip to gzip stream (not a valid .gz file) and decompress again to check if it worked. Keep in mind that the magic two-bytes header {31, 139} is not present in this case, gzgets() simply returns bytes from the file in this case.

funzip.exe EURUSD-2016-06.zip | zpipe.exe > EURUSD-2016-06.csv.gz
cat EURUSD-2016-06.csv.gz | zpipe.exe -d | more

truefx-to-zorro's People

Contributors

webradio avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.