我尝试使用普通Java从未压缩的数据(已经是非lzma-ed XXh_ticks.bi5)读取Dukascopy数据,但我找不到正确的方法。那个话题有一个例子吗?
AFAIK字段的顺序是:
不幸的是,我不知道JAVA数据类型和我将查看的字节顺序。
我很感激您能为我提供任何帮助。
==编辑(从评论中获得更好的可读性)
int size_milliseconds = Integer.BYTES;
int size_ask = Integer.BYTES;
int size_bid = Integer.BYTES;
int size_ask_volume = Float.BYTES;
int size_bid_volume = Float.BYTES;
int buffersize = size_milliseconds + size_ask + size_bid + size_ask_volume + size_bid_volume;
==编辑(第一次尝试......结果看起来不错)
String fileName = "11h_ticks.bi5";
try {
int size_milliseconds = Integer.BYTES;
int size_ask = Integer.BYTES;
int size_bid = Integer.BYTES;
int size_askv = Float.BYTES;
int size_bidv = Float.BYTES;
int buffersize = size_milliseconds + size_ask + size_bid + size_askv + size_bidv;
int nRead = 0;
double PriceFactor = 100000.00000;
FileInputStream inputStream = new FileInputStream(fileName);
byte[] buffer = new byte[buffersize];
ByteBuffer bb = ByteBuffer.wrap(buffer);
bb.order(ByteOrder.BIG_ENDIAN);
while ((nRead = inputStream.read(buffer)) != -1) {
bb.rewind();
int millisec = bb.getInt();
int ask = bb.getInt();
int bid = bb.getInt();
float askv = bb.getFloat();
float bidv = bb.getFloat();
double dask = ask / PriceFactor;
double dbid = bid / PriceFactor;
String rowstring="Millisec=" + (String)Integer.toString(millisec) + ", ask=" + (String)Double.toString(dask) + ", bid=" + (String)Double.toString(dbid) + ", ask_vol=" + (String)Float.toString(askv) + ", bid_vol=" + (String)Float.toString(bidv);
System.out.println(rowstring);
}
inputStream.close();
} catch (FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
} catch (IOException ex) {
System.out.println(
"Error reading file '" + fileName + "'");
}
具有以下结果:
Millisec=269, ask=1.11645, bid=1.11643, ask_vol=1.87, bid_vol=3.0
Millisec=320, ask=1.11645, bid=1.11643, ask_vol=2.25, bid_vol=3.0
Millisec=574, ask=1.11645, bid=1.11643, ask_vol=3.0, bid_vol=3.0
Millisec=777, ask=1.11645, bid=1.11643, ask_vol=3.0, bid_vol=2.25
Millisec=942, ask=1.11645, bid=1.11643, ask_vol=3.0, bid_vol=3.0
Millisec=1634, ask=1.11645, bid=1.11643, ask_vol=2.25, bid_vol=3.0
Millisec=1685, ask=1.11646, bid=1.11644, ask_vol=4.95, bid_vol=4.0
Millisec=1736, ask=1.11646, bid=1.11645, ask_vol=2.32, bid_vol=1.0
Millisec=1787, ask=1.11647, bid=1.11644, ask_vol=4.87, bid_vol=3.0
Millisec=1838, ask=1.11647, bid=1.11644, ask_vol=2.62, bid_vol=4.12
Millisec=1889, ask=1.11647, bid=1.11644, ask_vol=2.25, bid_vol=4.5
Millisec=1940, ask=1.11647, bid=1.11644, ask_vol=1.12, bid_vol=4.5
Millisec=2004, ask=1.11648, bid=1.11644, ask_vol=6.4, bid_vol=5.25
Millisec=2055, ask=1.11648, bid=1.11644, ask_vol=7.15, bid_vol=5.25
Millisec=2157, ask=1.11648, bid=1.11644, ask_vol=6.55, bid_vol=5.25
Millisec=2209, ask=1.11648, bid=1.11644, ask_vol=9.4, bid_vol=5.25
Millisec=2260, ask=1.11647, bid=1.11644, ask_vol=5.62, bid_vol=5.25
到目前为止,这么好。 2016年7月1日上午11:00的价格似乎是正确的。但这是我的问题:
一个。卷,我无法判断它是否好。或者不重要,只有相对大小才重要?对此有何建议?
B中。 ByteOrder怎么样?那是对的吗?使用LITTLE_ENDIAN(在dukascopy数据的不同论坛条目中建议)仅产生乱码输出。
℃。以上输出用于EURUSD。如果我在USA30IDXUSD上运行它,那么输出不可用。我需要改变什么? USA30IDXUSD的输出:
Millisec=158, ask=184.52136, bid=184.50411, ask_vol=5.5E-5, bid_vol=2.5E-4
Millisec=377, ask=184.52506, bid=184.50381, ask_vol=5.5E-5, bid_vol=2.5E-4
Millisec=842, ask=184.52342, bid=184.50336, ask_vol=5.5E-5, bid_vol=2.5E-4
Millisec=2139, ask=184.52328, bid=184.50465, ask_vol=5.5E-5, bid_vol=2.5E-4
Millisec=2636, ask=184.51599, bid=184.50234, ask_vol=3.0E-6, bid_vol=9.4E-5
Millisec=3129, ask=184.5154, bid=184.50316, ask_vol=3.0E-6, bid_vol=9.4E-5
Millisec=3349, ask=184.51607, bid=184.49866, ask_vol=3.0E-6, bid_vol=9.4E-5
Millisec=3679, ask=184.51599, bid=184.49944, ask_vol=3.0E-6, bid_vol=9.4E-5
Millisec=4009, ask=184.5155, bid=184.4998, ask_vol=3.0E-6, bid_vol=9.4E-5
Millisec=4449, ask=184.51532, bid=184.50248, ask_vol=3.0E-6, bid_vol=9.4E-5
Millisec=4779, ask=184.51502, bid=184.50385, ask_vol=3.0E-6, bid_vol=9.4E-5
Millisec=5267, ask=184.51586, bid=184.50095, ask_vol=3.0E-6, bid_vol=9.4E-5
Millisec=5659, ask=184.51569, bid=184.50094, ask_vol=3.0E-6, bid_vol=9.4E-5
Millisec=6099, ask=184.51579, bid=184.50268, ask_vol=3.0E-6, bid_vol=9.4E-5
根据我的经纪人的历史,当天道琼斯指数并未超过18000(O:17882.6,H:17997.1,L:17857.1,C:17963.1),因此使用不同的PriceFactor不会是一个解决方案。那么USA30IDXUSD的音量怎么样? 我想我该死的......; - )