-
-
Save miguelvm/38d331f3fe805a21c5e7bd82c90d0fac to your computer and use it in GitHub Desktop.
Sierra Chart SCID Format Reader in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.DataInputStream; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
import java.nio.ByteBuffer; | |
import java.nio.ByteOrder; | |
import java.sql.Date; | |
import java.util.Calendar; | |
public class SCIDReader { | |
private static boolean RUNNING = true; | |
public static void main(String[] args) throws IOException, InterruptedException { | |
File f = new File("/home/vlad/.wine/drive_c/SierraChart/Data/EURUSD.scid"); | |
FileInputStream fis = new FileInputStream(f); | |
DataInputStream ds = new DataInputStream(fis); | |
byte[] header = new byte[4]; | |
byte[] osm = new byte[4]; | |
ds.read(header); | |
System.out.println(new String(header)); | |
ds.read(header); | |
System.out.println("Header Size: " + getUInt32(header)); | |
ds.read(header); | |
System.out.println("Record Size: " + getUInt32(header)); | |
ds.skipBytes(56 - (4 * 3)); | |
double dt; | |
float open; | |
float high; | |
float low; | |
float close; | |
long numTrades; | |
long totalVolume; | |
long bidVolume; | |
long askVolume; | |
long start = System.currentTimeMillis(); | |
while (RUNNING) { | |
while (ds.available() == 0) { | |
// Tail the file | |
System.out.print("."); | |
Thread.sleep(100); | |
} | |
dt = Double.longBitsToDouble(Long.reverseBytes(ds.readLong())); | |
open = reverse(ds.readFloat()); | |
high = reverse(ds.readFloat()); | |
low = reverse(ds.readFloat()); | |
close = reverse(ds.readFloat()); | |
ds.read(osm); | |
numTrades = getUInt32(osm); | |
ds.read(osm); | |
totalVolume = getUInt32(osm); | |
ds.read(osm); | |
bidVolume = getUInt32(osm); | |
ds.read(osm); | |
askVolume = getUInt32(osm); | |
System.out.println(new Date(convertWindowsTimeToMilliseconds(dt))); | |
System.out.format( | |
"%.4f Open: %.4f High: %.4f Low: %.4f Close: %.4f Trades: %4d TotalVol: %4d Bid/Ask %3d / %3d\n", | |
dt, open, high, low, close, numTrades, totalVolume, bidVolume, askVolume); | |
} | |
System.out.println(System.currentTimeMillis() - start); | |
ds.close(); | |
} | |
/** | |
* Thanks to @see http://stackoverflow.com/a/13203649 | |
*/ | |
public static long getUInt32(byte[] bytes) { | |
long value = ((bytes[0] & 0xFF) << 0) | ((bytes[1] & 0xFF) << 8) | ((bytes[2] & 0xFF) << 16) | |
| ((bytes[3] & 0xFF) << 24); | |
return value; | |
} | |
public static float reverse(float x) { | |
return ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN).putFloat(x).order(ByteOrder.LITTLE_ENDIAN) | |
.getFloat(0); | |
} | |
/** | |
* Thanks to @see | |
* http://svn.codehaus.org/groovy/modules/scriptom/branches/SCRIPTOM | |
* -1.5.4-ANT/src/com/jacob/com/DateUtilities.java | |
*/ | |
static public long convertWindowsTimeToMilliseconds(double comTime) { | |
long result = 0; | |
comTime = comTime - 25569D; | |
Calendar cal = Calendar.getInstance(); | |
result = Math.round(86400000L * comTime) - cal.get(Calendar.ZONE_OFFSET); | |
cal.setTime(new Date(result)); | |
result -= cal.get(Calendar.DST_OFFSET); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment