Statistics are working with low/high etc.
This commit is contained in:
parent
9089e8f8b1
commit
f0888a55d0
@ -1,4 +1,4 @@
|
|||||||
#Sun, 09 Apr 2017 23:54:11 +0200
|
#Mon, 10 Apr 2017 19:52:24 +0200
|
||||||
annotation.processing.enabled=true
|
annotation.processing.enabled=true
|
||||||
annotation.processing.enabled.in.editor=false
|
annotation.processing.enabled.in.editor=false
|
||||||
annotation.processing.processors.list=
|
annotation.processing.processors.list=
|
||||||
|
@ -49,6 +49,22 @@ public class Statistics extends javax.swing.JPanel {
|
|||||||
|
|
||||||
tradesLabel.setText(String.format("%d", s.trades));
|
tradesLabel.setText(String.format("%d", s.trades));
|
||||||
|
|
||||||
|
|
||||||
|
if (s.heigh == null){
|
||||||
|
labelHigh.setText("--");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
labelHigh.setText(Globals.se.getMoneyFormatter().format(s.heigh));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s.low == null){
|
||||||
|
labelLow.setText("--");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
labelLow.setText(Globals.se.getMoneyFormatter().format(s.low));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}, 1000, 1000);
|
}, 1000, 1000);
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package sesim;
|
package sesim;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@ -19,6 +20,8 @@ public class Exchange {
|
|||||||
ConcurrentLinkedQueue<Order> order_queue = new ConcurrentLinkedQueue();
|
ConcurrentLinkedQueue<Order> order_queue = new ConcurrentLinkedQueue();
|
||||||
|
|
||||||
private double money_df = 10000;
|
private double money_df = 10000;
|
||||||
|
private int money_decimals=2;
|
||||||
|
DecimalFormat money_formatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the number of decimals used with money
|
* Set the number of decimals used with money
|
||||||
@ -27,9 +30,13 @@ public class Exchange {
|
|||||||
*/
|
*/
|
||||||
public void setMoneyDecimals(int n) {
|
public void setMoneyDecimals(int n) {
|
||||||
money_df = Math.pow(10, n);
|
money_df = Math.pow(10, n);
|
||||||
|
money_decimals=n;
|
||||||
|
money_formatter=getFormatter(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double shares_df = 1;
|
private double shares_df = 1;
|
||||||
|
private double shares_decimals=0;
|
||||||
|
private DecimalFormat shares_formatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the number of decimals for shares
|
* Set the number of decimals for shares
|
||||||
@ -38,6 +45,8 @@ public class Exchange {
|
|||||||
*/
|
*/
|
||||||
public void setSharesDecimals(int n) {
|
public void setSharesDecimals(int n) {
|
||||||
shares_df = Math.pow(10, n);
|
shares_df = Math.pow(10, n);
|
||||||
|
shares_decimals=n;
|
||||||
|
shares_formatter = getFormatter(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double roundToDecimals(double val, double f) {
|
public double roundToDecimals(double val, double f) {
|
||||||
@ -52,6 +61,28 @@ public class Exchange {
|
|||||||
return roundToDecimals(money, money_df);
|
return roundToDecimals(money, money_df);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DecimalFormat getFormatter(int n){
|
||||||
|
DecimalFormat formatter;
|
||||||
|
String s = "#0.";
|
||||||
|
if (n == 0) {
|
||||||
|
s = "#";
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
s = s + "0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new DecimalFormat(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DecimalFormat getMoneyFormatter(){
|
||||||
|
return money_formatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DecimalFormat getSharesFormatter(){
|
||||||
|
return shares_formatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Definition of order types
|
* Definition of order types
|
||||||
*/
|
*/
|
||||||
@ -389,7 +420,8 @@ public class Exchange {
|
|||||||
|
|
||||||
traders = new ArrayList();
|
traders = new ArrayList();
|
||||||
|
|
||||||
num_trades = 0;
|
statistics = new Statistics();
|
||||||
|
//num_trades = 0;
|
||||||
|
|
||||||
this.ohlc_data = new HashMap();
|
this.ohlc_data = new HashMap();
|
||||||
|
|
||||||
@ -416,28 +448,34 @@ public class Exchange {
|
|||||||
|
|
||||||
public long trades;
|
public long trades;
|
||||||
public long orders;
|
public long orders;
|
||||||
|
public Double heigh;
|
||||||
|
public Double low;
|
||||||
|
|
||||||
void reset() {
|
public final void reset() {
|
||||||
trades = 0;
|
trades = 0;
|
||||||
|
heigh=null;
|
||||||
|
low=null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Statistics() {
|
Statistics() {
|
||||||
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Statistics statistics;
|
Statistics statistics;
|
||||||
|
|
||||||
long num_trades = 0;
|
// long num_trades = 0;
|
||||||
long num_orders = 0;
|
// long num_orders = 0;
|
||||||
|
|
||||||
public Statistics getStatistics() {
|
public Statistics getStatistics() {
|
||||||
Statistics s = new Statistics();
|
return statistics;
|
||||||
|
/* Statistics s = new Statistics();
|
||||||
s.trades = num_trades;
|
s.trades = num_trades;
|
||||||
s.orders = num_orders;
|
s.orders = num_orders;
|
||||||
return s;
|
return s;
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -759,8 +797,8 @@ public class Exchange {
|
|||||||
// long time = 0;
|
// long time = 0;
|
||||||
//double theprice = 12.9;
|
//double theprice = 12.9;
|
||||||
// long orderid = 1;
|
// long orderid = 1;
|
||||||
double lastprice = 100.0;
|
//double lastprice = 100.0;
|
||||||
long lastsvolume;
|
// long lastsvolume;
|
||||||
|
|
||||||
// private final Locker tradelock = new Locker();
|
// private final Locker tradelock = new Locker();
|
||||||
public ArrayList<Order> getOrderBook(OrderType type, int depth) {
|
public ArrayList<Order> getOrderBook(OrderType type, int depth) {
|
||||||
@ -935,6 +973,29 @@ public class Exchange {
|
|||||||
removeOrderIfExecuted(b);
|
removeOrderIfExecuted(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void addQuoteToHistory(Quote q){
|
||||||
|
if (statistics.heigh==null){
|
||||||
|
statistics.heigh=q.price;
|
||||||
|
}
|
||||||
|
else if (statistics.heigh<q.price){
|
||||||
|
statistics.heigh=q.price;
|
||||||
|
}
|
||||||
|
if (statistics.low==null){
|
||||||
|
statistics.low=q.price;
|
||||||
|
}
|
||||||
|
else if(statistics.low>q.price){
|
||||||
|
statistics.low=q.price;
|
||||||
|
}
|
||||||
|
|
||||||
|
quoteHistory.add(q);
|
||||||
|
updateOHLCData(q);
|
||||||
|
updateQuoteReceivers(q);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -1016,7 +1077,8 @@ public class Exchange {
|
|||||||
volume_total += volume;
|
volume_total += volume;
|
||||||
money_total += price * volume;
|
money_total += price * volume;
|
||||||
|
|
||||||
num_trades++;
|
// num_trades++;
|
||||||
|
statistics.trades++;
|
||||||
|
|
||||||
this.checkSLOrders(price);
|
this.checkSLOrders(price);
|
||||||
|
|
||||||
@ -1030,10 +1092,12 @@ public class Exchange {
|
|||||||
q.volume = volume_total;
|
q.volume = volume_total;
|
||||||
q.time = timer.currentTimeMillis();
|
q.time = timer.currentTimeMillis();
|
||||||
|
|
||||||
this.quoteHistory.add(q);
|
|
||||||
this.updateOHLCData(q);
|
|
||||||
|
|
||||||
this.updateQuoteReceivers(q);
|
addQuoteToHistory(q);
|
||||||
|
|
||||||
|
//this.quoteHistory.add(q);
|
||||||
|
//this.updateOHLCData(q);
|
||||||
|
//this.updateQuoteReceivers(q);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1099,7 +1163,9 @@ public class Exchange {
|
|||||||
// System.out.printf("Getting executor in create Order\n", Thread.currentThread().getId());
|
// System.out.printf("Getting executor in create Order\n", Thread.currentThread().getId());
|
||||||
synchronized (executor) {
|
synchronized (executor) {
|
||||||
|
|
||||||
num_orders++;
|
//num_orders++;
|
||||||
|
statistics.orders++;
|
||||||
|
|
||||||
addOrderToBook(o);
|
addOrderToBook(o);
|
||||||
a.orders.put(o.id, o);
|
a.orders.put(o.id, o);
|
||||||
a.update(o);
|
a.update(o);
|
||||||
|
Loading…
Reference in New Issue
Block a user