We provide a job file directory that can by jobs to write files for retrieval via SFTP
Introduction
All jobs inherit a directory of a java.io type File called JobFilesDir and jobs have permission to write files there. This will create a file called myfile.txt in the jobfiles directory which you should have access to via sftp freewayuser@<production IP>. The directory will be in freewayuser's home directory and is named jobfiles.
If SFTP will have to be setup access the server. Support Services will need to open a port for sftp on the firewall which would require a source IP from for whitelisting.
Example - Flushing all market stats messages to file
Below is a very simple job write ALL Market Stats messages to a file. The file name is set in the onRamp configuration.
import com.optionscity.freeway.api.AbstractJob;
import com.optionscity.freeway.api.IContainer;
import com.optionscity.freeway.api.IJobSetup;
import com.optionscity.freeway.api.messages.MarketStatsMessage;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
/**
* Example job to demonstrate file writing and flushing values (useful for debugging)
* @author acrichton
* @date 05/07/21
* @version 1.0
*/
public class FlushDemoJob extends AbstractJob {
File file;
String filename;
@Override
public void install(IJobSetup setup) {
setup.setDefaultDescription("Job to demonstrate flushing values to a file");
setup.addVariable("file name", "File name of output" , "String", "");
}
@Override
public void begin(IContainer container) {
super.begin(container);
container.subscribeToMarketStatsMessages();
filename = getStringVar("file name");
// All jobs inherit a directory of a java.io type File called JobFilesDir.
// Jobs have permission to write files there.
file = new File(JobFilesDir,filename);
log(">> New file: " + filename);
}
@Override
public void onMarketStats(MarketStatsMessage msg) {
writeTradeToFile(msg);
}
private void writeTradeToFile(MarketStatsMessage msg){
try {
FileWriter fw = new FileWriter(file,true);
String line = msg.instrumentId + ", " + msg.marketUpdateType.toString() + ", " + msg.price + ", "
+ msg.quantity + "\n" ;
log(">> Writing line to file: " + line);
fw.write(line);
fw.flush();
} catch (IOException e){
failJob("io exception, " + e);
}
}
}
Output:
[optionscity@CH2-OCTRL-1170-102-01 jobfiles]$ head trades050721a.out
CL-20210720-F, LAST, 75.39, 1
CL-20210720-F, TRADE_VOLUME, 0.0, 63959
CL-20210720-F, TRADE_VOLUME, 0.0, 63960
CL-20210720-F, LAST, 75.4, 1
CL-20210720-F, TRADE_VOLUME, 0.0, 63960
CL-20210720-F, TRADE_VOLUME, 0.0, 63961
CL-20210720-F, LAST, 75.4, 1
CL-20210720-F, TRADE_VOLUME, 0.0, 63961
CL-20210720-F, TRADE_VOLUME, 0.0, 63962
CL-20210720-F, LAST, 75.4, 2