Convert TrueFX.com tick data to Zorro-Trader.com .t6 bar format
######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;
Each bar contains predefined number of ticks, like 1000. Time increment is then irregular by definition. Begin a fresh bar also after weekends, holidays.
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)
ZHistoryEdit.exe (linked from Zorro download page) can create .t6 files
.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);
}
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
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
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