Skip to content

Commit

Permalink
Update Java reference API
Browse files Browse the repository at this point in the history
  • Loading branch information
rylorin committed Sep 22, 2023
1 parent 09522ab commit 6f1593c
Show file tree
Hide file tree
Showing 41 changed files with 1,888 additions and 695 deletions.
10 changes: 5 additions & 5 deletions ref/client/Bar.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class Bar {
private double m_high;
private double m_low;
private double m_close;
private long m_volume;
private Decimal m_volume;
private int m_count;
private double m_wap;
private Decimal m_wap;

public Bar(String time, double open, double high, double low, double close, long volume, int count, double wap) {
public Bar(String time, double open, double high, double low, double close, Decimal volume, int count, Decimal wap) {
this.m_time = time;
this.m_open = open;
this.m_high = high;
Expand Down Expand Up @@ -45,15 +45,15 @@ public double close() {
return m_close;
}

public long volume() {
public Decimal volume() {
return m_volume;
}

public int count() {
return m_count;
}

public double wap() {
public Decimal wap() {
return m_wap;
}

Expand Down
38 changes: 29 additions & 9 deletions ref/client/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,35 @@ public Builder( int size ) {
m_sb = new ByteBuffer( size );
}

public void send(int a) {
public void send(int a) throws EClientException {
send( String.valueOf(a) );
}

public void sendMax(int a) {
public void sendMax(int a) throws EClientException {
send( a == Integer.MAX_VALUE ? "" : String.valueOf( a) );
}

public void send(double a) {
public void send(double a) throws EClientException {
send( String.valueOf( a) );
}

public void sendMax(double a) {
public void sendMax(double a) throws EClientException {
send( a == Double.MAX_VALUE ? "" : String.valueOf( a) );
}

public void send(Boolean a) {
public void send(Boolean a) throws EClientException {
sendMax(a == null ? Integer.MAX_VALUE : a ? 1 : 0);
}

public void send( IApiEnum a) {
public void send( IApiEnum a) throws EClientException {
send( a == null ? null : a.getApiString() );
}

public void send( String a) {
public void send( String a) throws EClientException {
if (a != null && !isAsciiPrintable(a)) {
throw new EClientException(EClientErrors.INVALID_SYMBOL, a);
}

if (a != null) {
byte[] buffer = a.getBytes(StandardCharsets.UTF_8);
m_sb.write( buffer, 0, buffer.length );
Expand All @@ -62,14 +66,14 @@ public void send( byte[] bytes ) {
}
}

public void send(List<TagValue> miscOptions) {
public void send(List<TagValue> miscOptions) throws EClientException {
String miscOptionsString = Optional.ofNullable(miscOptions).orElse(new ArrayList<TagValue>()).stream().
map(option -> option.m_tag + "=" + option.m_value + ";").reduce("", (sum, option) -> sum + option);

send(miscOptionsString);
}

public void send(Contract contract) {
public void send(Contract contract) throws EClientException {
send(contract.conid());
send(contract.symbol());
send(contract.getSecType());
Expand Down Expand Up @@ -106,6 +110,22 @@ static void intToBytes(int val, byte b[], int position) {
b[position+2] = (byte)(0xff & (val >> 8));
b[position+3] = (byte)(0xff & val);
}

private static boolean isAsciiPrintable(String str) {
if (str == null) {
return false;
}
for (int i = 0; i < str.length(); i++) {
if (isAsciiPrintable(str.charAt(i)) == false) {
return false;
}
}
return true;
}

private static boolean isAsciiPrintable(char ch) {
return ch >= 32 && ch < 127;
}

/** inner class: ByteBuffer - storage for bytes and direct access to buffer. */
private static class ByteBuffer extends ByteArrayOutputStream {
Expand Down
24 changes: 21 additions & 3 deletions ref/client/Contract.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class Contract implements Cloneable {
private String m_tradingClass;
private String m_secIdType; // CUSIP;SEDOL;ISIN;RIC
private String m_secId;
private String m_description;
private String m_issuerId;

private DeltaNeutralContract m_deltaNeutralContract;
private boolean m_includeExpired; // can not be set to true for orders
Expand Down Expand Up @@ -54,6 +56,8 @@ public class Contract implements Cloneable {
public DeltaNeutralContract deltaNeutralContract() { return m_deltaNeutralContract; }
public List<ComboLeg> comboLegs() { return m_comboLegs; }
public String comboLegsDescrip() { return m_comboLegsDescrip; }
public String description() { return m_description; }
public String issuerId() { return m_issuerId; }

// Set
public void conid(int v) { m_conid = v; }
Expand All @@ -77,6 +81,8 @@ public class Contract implements Cloneable {
public void includeExpired(boolean v) { m_includeExpired = v; }
public void comboLegs(List<ComboLeg> v) { m_comboLegs = v; }
public void comboLegsDescrip(String v) { m_comboLegsDescrip = v; }
public void description(String v) { m_description = v; }
public void issuerId(String v) { m_issuerId = v; }

public Contract() {
m_conid = 0;
Expand Down Expand Up @@ -105,7 +111,7 @@ public Contract(int p_conId, String p_symbol, String p_secType, String p_lastTra
double p_strike, String p_right, String p_multiplier,
String p_exchange, String p_currency, String p_localSymbol, String p_tradingClass,
List<ComboLeg> p_comboLegs, String p_primaryExch, boolean p_includeExpired,
String p_secIdType, String p_secId) {
String p_secIdType, String p_secId, String p_description, String p_issuerId) {
m_conid = p_conId;
m_symbol = p_symbol;
m_secType = p_secType;
Expand All @@ -121,7 +127,9 @@ public Contract(int p_conId, String p_symbol, String p_secType, String p_lastTra
m_comboLegs = p_comboLegs;
m_primaryExch = p_primaryExch;
m_secIdType = p_secIdType;
m_secId = p_secId ;
m_secId = p_secId;
m_description = p_description;
m_issuerId = p_issuerId;
}

@Override
Expand Down Expand Up @@ -187,6 +195,14 @@ public boolean equals(Object p_other) {
return false;
}
}

if (Util.StringCompare(m_description, l_theOther.m_description) != 0) {
return false;
}
if (Util.StringCompare(m_issuerId, l_theOther.m_issuerId) != 0) {
return false;
}

return true;
}

Expand All @@ -201,7 +217,7 @@ public int hashCode() {
}

/** Returns a text description that can be used for display. */
public String description() {
public String textDescription() {
StringBuilder sb = new StringBuilder();

if (isCombo() ) {
Expand Down Expand Up @@ -264,6 +280,8 @@ public boolean isCombo() {
add( sb, "primaryExch", m_primaryExch);
add( sb, "secIdType", m_secIdType);
add( sb, "secId", m_secId);
add( sb, "description", m_description);
add( sb, "issuerId", m_issuerId);

return sb.toString();
}
Expand Down
2 changes: 2 additions & 0 deletions ref/client/ContractDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public String toString() {
+ "secType: " + m_contract.secType().toString() + "\n"
+ "primaryExch: " + m_contract.primaryExch() + "\n"
+ "currency: " + m_contract.currency() + "\n"
+ "description: " + m_contract.description() + "\n"
+ "issuerId: " + m_contract.issuerId() + "\n"
+ "derivativeSecTypes: " + Arrays.toString(m_derivativeSecTypes) + "\n";
}
}
30 changes: 23 additions & 7 deletions ref/client/ContractDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ public class ContractDetails {
private String m_liquidHours;
private String m_evRule;
private double m_evMultiplier;
private int m_mdSizeMultiplier;
private List<TagValue> m_secIdList; // CUSIP/ISIN/etc.
private int m_aggGroup;
private String m_underSymbol;
private String m_underSecType;
private String m_marketRuleIds;
private String m_realExpirationDate;
private String m_lastTradeTime;
private String m_stockType; // COMMON, ETF, ADR etc.
private Decimal m_minSize;
private Decimal m_sizeIncrement;
private Decimal m_suggestedSizeIncrement;

// BOND values
private String m_cusip;
Expand Down Expand Up @@ -68,14 +71,17 @@ public class ContractDetails {
public String liquidHours() { return m_liquidHours; }
public String evRule() { return m_evRule; }
public double evMultiplier() { return m_evMultiplier; }
public int mdSizeMultiplier() { return m_mdSizeMultiplier; }
public List<TagValue> secIdList() { return m_secIdList; }
public int aggGroup() { return m_aggGroup; }
public String underSymbol() { return m_underSymbol; }
public String underSecType() { return m_underSecType; }
public String marketRuleIds() { return m_marketRuleIds; }
public String realExpirationDate() { return m_realExpirationDate; }
public String lastTradeTime() { return m_lastTradeTime; }
public String stockType() { return m_stockType; }
public Decimal minSize() { return m_minSize; }
public Decimal sizeIncrement() { return m_sizeIncrement; }
public Decimal suggestedSizeIncrement() { return m_suggestedSizeIncrement; }

public String cusip() { return m_cusip; }
public String ratings() { return m_ratings; }
Expand Down Expand Up @@ -111,14 +117,17 @@ public class ContractDetails {
public void liquidHours(String liquidHours) { m_liquidHours = liquidHours; }
public void evRule(String evRule) { m_evRule = evRule; }
public void evMultiplier(double evMultiplier) { m_evMultiplier = evMultiplier; }
public void mdSizeMultiplier(int mdSizeMultiplier) { m_mdSizeMultiplier = mdSizeMultiplier; }
public void secIdList(List<TagValue> secIdList) { m_secIdList = secIdList; }
public void aggGroup(int aggGroup) { m_aggGroup = aggGroup; }
public void underSymbol(String underSymbol) { m_underSymbol = underSymbol; }
public void underSecType(String underSecType) { m_underSecType = underSecType; }
public void marketRuleIds(String marketRuleIds) { m_marketRuleIds = marketRuleIds; }
public void realExpirationDate(String realExpirationDate) { m_realExpirationDate = realExpirationDate; }
public void lastTradeTime(String lastTradeTime) { m_lastTradeTime = lastTradeTime; }
public void stockType(String stockType) { m_stockType = stockType; }
public void minSize(Decimal minSize) { m_minSize = minSize; }
public void sizeIncrement(Decimal sizeIncrement) { m_sizeIncrement = sizeIncrement; }
public void suggestedSizeIncrement(Decimal suggestedSizeIncrement) { m_suggestedSizeIncrement = suggestedSizeIncrement; }

public void cusip(String cusip) { m_cusip = cusip; }
public void ratings(String ratings) { m_ratings = ratings; }
Expand Down Expand Up @@ -147,8 +156,9 @@ public ContractDetails( Contract p_contract, String p_marketName,
double p_minTick, String p_orderTypes, String p_validExchanges, int p_underConId, String p_longName,
String p_contractMonth, String p_industry, String p_category, String p_subcategory,
String p_timeZoneId, String p_tradingHours, String p_liquidHours,
String p_evRule, double p_evMultiplier, int p_mdSizeMultiplier, int p_aggGroup,
String p_underSymbol, String p_underSecType, String p_marketRuleIds, String p_realExpirationDate, String p_lastTradeTime) {
String p_evRule, double p_evMultiplier, int p_aggGroup,
String p_underSymbol, String p_underSecType, String p_marketRuleIds, String p_realExpirationDate, String p_lastTradeTime,
String p_stockType, Decimal p_minSize, Decimal p_sizeIncrement, Decimal p_suggestedSizeIncrement) {
m_contract = p_contract;
m_marketName = p_marketName;
m_minTick = p_minTick;
Expand All @@ -165,13 +175,16 @@ public ContractDetails( Contract p_contract, String p_marketName,
m_liquidHours = p_liquidHours;
m_evRule = p_evRule;
m_evMultiplier = p_evMultiplier;
m_mdSizeMultiplier = p_mdSizeMultiplier;
m_aggGroup = p_aggGroup;
m_underSymbol = p_underSymbol;
m_underSecType = p_underSecType;
m_marketRuleIds = p_marketRuleIds;
m_realExpirationDate = p_realExpirationDate;
m_lastTradeTime = p_lastTradeTime;
m_stockType = p_stockType;
m_minSize = p_minSize;
m_sizeIncrement = p_sizeIncrement;
m_suggestedSizeIncrement = p_suggestedSizeIncrement;
}

@Override public String toString() {
Expand All @@ -193,13 +206,16 @@ public ContractDetails( Contract p_contract, String p_marketName,
add( sb, "liquidHours", m_liquidHours);
add( sb, "evRule", m_evRule);
add( sb, "evMultiplier", m_evMultiplier);
add( sb, "mdSizeMultiplier", m_mdSizeMultiplier);
add( sb, "aggGroup", m_aggGroup);
add( sb, "underSymbol", m_underSymbol);
add( sb, "underSecType", m_underSecType);
add( sb, "marketRuleIds", m_marketRuleIds);
add( sb, "realExpirationDate", m_realExpirationDate);
add( sb, "lastTradeTime", m_lastTradeTime);
add( sb, "stockType", m_stockType);
add( sb, "minSize", m_minSize);
add( sb, "sizeIncrement", m_sizeIncrement);
add( sb, "suggestedSizeIncrement", m_suggestedSizeIncrement);

add( sb, "cusip", m_cusip);
add( sb, "ratings", m_ratings);
Expand Down
Loading

0 comments on commit 6f1593c

Please sign in to comment.