compile error in writing to file in QuotesDelta.java

Custom indicators, trading strategies, data export and recording and more...
ingyukoh
Posts: 33
Joined: Tue Nov 26, 2019 7:06 am
Been thanked: 1 time

compile error in writing to file in QuotesDelta.java

Post by ingyukoh » Mon Dec 30, 2019 1:09 am

Following clearly written "Developing with Bookmap API(step-by-step)",
small changes in code "QuotesDelata.java" like
"line1.setColor(Color.Gray)" instead of Color.Orange
are successfully exported into jar and imported into Bookmap through
settings -> Api plugins configuration.


Goal is: communicate order book and trade data through TCP into C# and python program for my
deep learning algorithm based on orderbook and trade data through TCP communication.
As a first step to achieve this goal,
I modified QuotesDelta.java
1. import java.io.FileWriter; // Import the FileWriter class
import java.io.IOException; // Import the IOException class to handle errors
2. modified onDepth method as

@Override
public void onDepth(boolean isBid, int price, int size) {
int prevSize = book.onDepth(isBid, price, size);
if (snapshotCompleted) {
int delta = size - prevSize;
if (isBid) {
bidDelta += delta;
} else {
askDelta += delta;
}

FileWriter myWriter = new FileWriter("D:\\filename3.txt",true); // ERROR!

}
}

In exporting compile error is reported.
What is cause of this error?
I have checked FileWriter statement in independent separate java.

ingyukoh
Posts: 33
Joined: Tue Nov 26, 2019 7:06 am
Been thanked: 1 time

Re: compile error in writing to file in QuotesDelta.java

Post by ingyukoh » Mon Dec 30, 2019 1:20 am

Following "How to report your Bookmap API issues",
1. Version: 7.0.0 build:83
2. Expored with compile errors: simple-demo-master/src/main/java/com/bookmap/api/simple.demo.indicators/QuoteDelta.java
in JAR Export

3. codes:

package com.bookmap.api.simple.demo.indicators;

import java.awt.Color;

import com.bookmap.api.simple.demo.utils.data.OrderBookBase;

import velox.api.layer1.annotations.Layer1ApiVersion;
import velox.api.layer1.annotations.Layer1ApiVersionValue;
import velox.api.layer1.annotations.Layer1SimpleAttachable;
import velox.api.layer1.annotations.Layer1StrategyName;
import velox.api.layer1.data.InstrumentInfo;
import velox.api.layer1.layers.utils.OrderBook;
import velox.api.layer1.messages.indicators.Layer1ApiUserMessageModifyIndicator.GraphType;
import velox.api.layer1.simplified.Api;
import velox.api.layer1.simplified.Bar;
import velox.api.layer1.simplified.BarDataListener;
import velox.api.layer1.simplified.CustomModule;
import velox.api.layer1.simplified.DepthDataListener;
import velox.api.layer1.simplified.Indicator;
import velox.api.layer1.simplified.InitialState;
import velox.api.layer1.simplified.Intervals;
import velox.api.layer1.simplified.SnapshotEndListener;
import java.io.FileWriter; // Import the FileWriter class
import java.io.IOException; // Import the IOException class to handle errors

@Layer1SimpleAttachable
@Layer1StrategyName("Quotes Delta")
@Layer1ApiVersion(Layer1ApiVersionValue.VERSION1)
public class QuotesDelta implements CustomModule, BarDataListener, DepthDataListener, SnapshotEndListener {

protected final OrderBookBase book = new OrderBookBase();
private int bidDelta = 0;
private int askDelta = 0;
private boolean snapshotCompleted = false;

private Indicator line1;

@Override
public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
line1 = api.registerIndicator("Quotes Delta", GraphType.BOTTOM);
line1.setColor(Color.GRAY);
//line1.setColor(Color.YELLOW);
}

@Override
public void onBar(OrderBook orderBook, Bar bar) {
line1.addPoint(bidDelta - askDelta);

}

@Override
public long getInterval() {
return Intervals.INTERVAL_100_MILLISECONDS;
}

@Override
public void onDepth(boolean isBid, int price, int size) {
int prevSize = book.onDepth(isBid, price, size);
if (snapshotCompleted) {
int delta = size - prevSize;
if (isBid) {
bidDelta += delta;
} else {
askDelta += delta;
}

FileWriter myWriter = new FileWriter("D:\\filename3.txt",true); //ERRORS!

}
}

@Override
public void onSnapshotEnd() {
snapshotCompleted = true;
}

@Override
public void stop() {
}
}

ingyukoh
Posts: 33
Joined: Tue Nov 26, 2019 7:06 am
Been thanked: 1 time

Re: compile error in writing to file in QuotesDelta.java

Post by ingyukoh » Mon Dec 30, 2019 3:15 am

solved

Eclipse shows error/warning flags
with
"surround with try/catch"

Exporting into JAR and importing again in Bookmap gives correctly appending "hello world"
each time of onDepth calls.

//FileWriter myWriter = new FileWriter("D:\\filename3.txt",true);
try {
FileWriter myWriter = new FileWriter("D:\\filename3.txt",true);
myWriter.write("hello world\n");
myWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Pleasant surprises are:
Eclipse IDE is quite good.
Java is stricter than C# and Python in syntax/semantics.

Post Reply