From cd2d0c65ffe188dcd0b7dd2ce6045a200a983c63 Mon Sep 17 00:00:00 2001
From: 7u83 <7u83@maiol.ru>
Date: Sun, 19 Mar 2017 18:07:58 +0100
Subject: [PATCH] Some imprements
---
nbactions.xml | 10 +--
pom.xml | 23 ++++++
src/main/java/gui/NewMDIApplication.form | 9 +++
src/main/java/gui/NewMDIApplication.java | 7 +-
src/main/java/gui/TraderListPanel.java | 4 +-
src/main/java/sesim/Exchange.java | 99 ++++++++++++++++++++----
src/main/java/sesim/Scheduler.java | 2 +-
src/main/java/traders/RandomTraderA.java | 67 +++++++++-------
8 files changed, 164 insertions(+), 57 deletions(-)
diff --git a/nbactions.xml b/nbactions.xml
index 73f6ef7..29021cf 100644
--- a/nbactions.xml
+++ b/nbactions.xml
@@ -43,13 +43,5 @@
java
-
- build
-
- *
-
-
- install
-
-
+
diff --git a/pom.xml b/pom.xml
index db7d0df..3a83ad5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,6 +48,11 @@
AbsoluteLayout
SNAPSHOT
+
+ org.codehaus.mojo
+ webstart-maven-plugin
+ 1.0-beta-7
+
UTF-8
@@ -62,4 +67,22 @@
file:${project.basedir}/lib
+
+
+
+
+ 1.0-beta-7
+ webstart-maven-plugin
+
+
+
+ com.cauwersin.SeSim.gui.NewMDIApplication
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/gui/NewMDIApplication.form b/src/main/java/gui/NewMDIApplication.form
index 0510c05..1070f5b 100644
--- a/src/main/java/gui/NewMDIApplication.form
+++ b/src/main/java/gui/NewMDIApplication.form
@@ -487,6 +487,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/gui/NewMDIApplication.java b/src/main/java/gui/NewMDIApplication.java
index eb1c042..4c5750b 100644
--- a/src/main/java/gui/NewMDIApplication.java
+++ b/src/main/java/gui/NewMDIApplication.java
@@ -68,7 +68,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
}
AutoTraderInterface createTraderNew(Exchange se, long id, String name, double money, double shares, JSONObject cfg) {
- System.out.printf("!!!! creating new\n");
+
String base = cfg.getString("base");
AutoTraderInterface ac = Globals.tloader.getStrategyBase(base);
if (ac == null) {
@@ -114,7 +114,6 @@ public class NewMDIApplication extends javax.swing.JFrame {
for (int i1 = 0; i1 < count; i1++) {
AutoTraderInterface trader;
- System.out.printf("shoudl create new\n");
trader = this.createTraderNew(Globals.se, id, t.getString("Name") + i1, money, shares, strategy);
Globals.se.traders.add(trader);
@@ -166,6 +165,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
chart = new chart.Chart();
quoteVertical1 = new gui.orderbook.QuoteVertical();
jSplitPane5 = new javax.swing.JSplitPane();
+ statistics1 = new gui.Statistics();
menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
@@ -319,6 +319,8 @@ public class NewMDIApplication extends javax.swing.JFrame {
jSplitPane3.setLeftComponent(quoteVertical1);
jSplitPane5.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
+ jSplitPane5.setTopComponent(statistics1);
+
jSplitPane3.setLeftComponent(jSplitPane5);
getContentPane().add(jSplitPane3, java.awt.BorderLayout.CENTER);
@@ -801,6 +803,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
private javax.swing.JMenuItem simMenuPause;
private javax.swing.JMenuItem simMenuStart;
private javax.swing.JMenuItem simMenuStop;
+ private gui.Statistics statistics1;
private javax.swing.JButton stopButton;
private javax.swing.JMenuItem viewClock;
private javax.swing.JMenu viewMenu;
diff --git a/src/main/java/gui/TraderListPanel.java b/src/main/java/gui/TraderListPanel.java
index 18697a5..ef54f4f 100644
--- a/src/main/java/gui/TraderListPanel.java
+++ b/src/main/java/gui/TraderListPanel.java
@@ -62,7 +62,7 @@ public class TraderListPanel extends javax.swing.JPanel {
sesim.Quote q = Globals.se.getLastQuoete();
double price = q == null ? 0 : q.price;
- //DefaultTableModel newmodel = new DefaultTableModel();
+
int size = Globals.se.traders.size();
model.setRowCount(size);
for (int i = 0; i < size; i++) {
@@ -141,7 +141,7 @@ public class TraderListPanel extends javax.swing.JPanel {
}
- void test() {
+ void ZZtest() {
// new javax.swing.table.DefaultTableModel
MyModel m = new MyModel(
diff --git a/src/main/java/sesim/Exchange.java b/src/main/java/sesim/Exchange.java
index accedf6..4486c35 100644
--- a/src/main/java/sesim/Exchange.java
+++ b/src/main/java/sesim/Exchange.java
@@ -378,8 +378,11 @@ public class Exchange {
public TreeSet quoteHistory; // = new TreeSet<>();
final void initExchange() {
+ buy_orders = 0;
+ sell_orders = 0;
timer = new Scheduler(); // timer = new Scheduler();
- random = new Random(12);
+ // random = new Random(12);
+ random = new Random();
quoteHistory = new TreeSet();
accounts = new ConcurrentHashMap<>();
@@ -413,6 +416,16 @@ public class Exchange {
public long trades;
public long orders;
+
+ void reset() {
+ trades = 0;
+
+ }
+
+ Statistics() {
+
+ }
+
};
Statistics statistics;
@@ -516,7 +529,7 @@ public class Exchange {
}
public Double getBestPrice() {
-System.out.printf("Get BP\n");
+ System.out.printf("Get BP\n");
SortedSet bid = order_books.get(OrderType.BUYLIMIT);
SortedSet ask = order_books.get(OrderType.SELLLIMIT);
@@ -538,14 +551,14 @@ System.out.printf("Get BP\n");
// there is bid and ask
if (a != null && b != null) {
Quote q = new Quote();
-System.out.printf("aaaaa bbbbb %f %f \n",a.limit,b.limit);
+ System.out.printf("aaaaa bbbbb %f %f \n", a.limit, b.limit);
// if there is no last quote calculate from bid and ask
//if (lq == null) {
- double rc =(bid.first().limit + ask.first().limit) / 2.0;
- System.out.printf("RCRC2.0: %f\n",rc);
- return rc;
+ double rc = (bid.first().limit + ask.first().limit) / 2.0;
+ System.out.printf("RCRC2.0: %f\n", rc);
+ return rc;
- // }
+ // }
/*
if (lq.price < b.limit) {
return b.limit;
@@ -556,7 +569,7 @@ System.out.printf("aaaaa bbbbb %f %f \n",a.limit,b.limit);
}
return lq.price;
-*/
+ */
}
if (a != null) {
@@ -620,12 +633,12 @@ System.out.printf("aaaaa bbbbb %f %f \n",a.limit,b.limit);
Quote q = new Quote();
// if there is no last quote calculate from bid and ask
- // if (lq == null) {
- q.price = (bid.first().limit + ask.first().limit) / 2.0;
- return q;
- // }
+ if (lq == null) {
+ q.price = (bid.first().limit + ask.first().limit) / 2.0;
+ return q;
+ }
- /* if (lq.price < b.limit) {
+ if (lq.price < b.limit) {
q.price = b.limit;
return q;
}
@@ -634,8 +647,7 @@ System.out.printf("aaaaa bbbbb %f %f \n",a.limit,b.limit);
return q;
}
return lq;
- */
- }
+ }
if (a != null) {
Quote q = new Quote();
@@ -1025,9 +1037,32 @@ System.out.printf("aaaaa bbbbb %f %f \n",a.limit,b.limit);
}
+ long buy_orders = 0;
+ long sell_orders = 0;
+
private void addOrderToBook(Order o) {
order_books.get(o.type).add(o);
+ switch (o.type) {
+ case BUY:
+ case BUYLIMIT:
+ buy_orders++;
+ break;
+ case SELL:
+ case SELLLIMIT:
+ sell_orders++;
+ break;
+ }
+// System.out.printf("B/S %d/%d Failed B/S: %d/%d\n", buy_orders, sell_orders,buy_failed,sell_failed);
+ }
+
+ long buy_failed = 0;
+ long sell_failed = 0;
+
+
+ public void ua(Account a){
+ //.money=1000.0;
+ // a.shares=100;
}
/**
@@ -1044,9 +1079,25 @@ System.out.printf("aaaaa bbbbb %f %f \n",a.limit,b.limit);
if (a == null) {
return -1;
}
+
+
Order o = new Order(a, type, volume, limit);
if (o.volume <= 0 || o.limit <= 0) {
+
+ switch (o.type) {
+ case SELL:
+ case SELLLIMIT:
+ sell_failed++;
+ break;
+ case BUY:
+ case BUYLIMIT:
+ buy_failed++;
+ break;
+ }
+
+
+
return -1;
}
@@ -1089,6 +1140,24 @@ System.out.printf("aaaaa bbbbb %f %f \n",a.limit,b.limit);
public Account getAccount(double account_id) {
return accounts.get(account_id);
}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*public AccountData getAccountData(double account_id) {
tradelock.lock();
diff --git a/src/main/java/sesim/Scheduler.java b/src/main/java/sesim/Scheduler.java
index 98e0cdb..82e8974 100644
--- a/src/main/java/sesim/Scheduler.java
+++ b/src/main/java/sesim/Scheduler.java
@@ -338,7 +338,7 @@ public class Scheduler extends Thread {
Object rc = event_queue.remove(t);
if (s.size() > 1) {
- System.out.printf("Events in a row: %d\n", s.size());
+ //System.out.printf("Events in a row: %d\n", s.size());
}
Iterator it = s.iterator();
diff --git a/src/main/java/traders/RandomTraderA.java b/src/main/java/traders/RandomTraderA.java
index bb38acb..ee3e496 100644
--- a/src/main/java/traders/RandomTraderA.java
+++ b/src/main/java/traders/RandomTraderA.java
@@ -73,7 +73,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
a.setListener(this);
long delay = (long) (getRandom(initial_delay[0], initial_delay[1]) * 1000);
- setStatus("Inital delay: %d\n",delay);
+ setStatus("Inital delay: %d\n", delay);
timerTask = se.timer.startTimerTask(this, delay);
}
@@ -82,6 +82,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
// System.out.printf("Enter TimerTask for %d / %d\n", System.identityHashCode(this), Thread.currentThread().getId());
sesim.Exchange.Account a = se.getAccount(account_id);
// System.out.printf("Have Account %d\n", Thread.currentThread().getId());
+ Globals.se.ua(a);
long rc = this.doTrade();
setStatus("Sleeping for %d ms", rc);
return rc;
@@ -116,7 +117,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
}
void setStatus(String format, Object... arguments) {
- // String s = String.format(format, arguments);
+ // String s = String.format(format, arguments);
// System.out.printf("%s: %s\n", this.getName(), s);
}
@@ -206,8 +207,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
// System.out.printf("We have now to wait for %d\n", w);
//timerTask = se.timer.startTimerTask(this, w);
- // se.timer.XXXrescheduleTimerTask(timerTask, w);
-
+ // se.timer.XXXrescheduleTimerTask(timerTask, w);
}
// System.out.printf("Updatetd Account\n", "");
@@ -237,6 +237,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
mode = Action.BUY;
return getRandom(buy_wait);
}
+ // System.out.printf("Buy failed\n");
return null;
}
@@ -247,6 +248,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
return getRandom(sell_wait);
}
+ // System.out.printf("Sell failed\n");
return null;
}
@@ -279,44 +281,43 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
long doTrade() {
long co = cancelOrders();
- setStatus("Orders cancled: %d",co);
- if (co>0)
+ setStatus("Orders cancled: %d", co);
+ if (co > 0) {
mode = Action.RANDOM;
+ }
Action a = getAction();
// System.out.printf("Action is %s\n", a.toString());
if (mode == Action.RANDOM) {
-
- setStatus("Mode is %s, next action is %s",mode.toString(),a.toString());
-
+
+ setStatus("Mode is %s, next action is %s", mode.toString(), a.toString());
+
// System.out.printf("Action: %s\n", a.toString());
Integer rc = doTrade1(a);
if (rc != null) {
- setStatus("Action %s success full, ret %d",a.toString(),rc);
+ setStatus("Action %s successfull, ret %d", a.toString(), rc);
return rc;
}
-
rc = doTrade1(Action.BUY);
if (rc != null) {
- setStatus("BuyAction %s successfull, ret %d",a.toString(),rc);
-
+ setStatus("BuyAction %s successfull, ret %d", a.toString(), rc);
return rc;
}
+
rc = doTrade1(Action.SELL);
if (rc != null) {
- setStatus("SellAction %s successfull, ret %d",a.toString(),rc);
+ setStatus("SellAction %s successfull, ret %d", a.toString(), rc);
return rc;
}
-
+
setStatus("No trade possible, returning 5000");
-// System.out.printf("All ha s failed\n");
+ //System.out.printf("All ha s failed\n");
return 5000;
}
-
- setStatus("Current mode is %s",mode.toString());
+ setStatus("Current mode is %s", mode.toString());
return waitAfterOrder();
}
@@ -379,23 +380,28 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
double limit;
limit = lp + getRandomAmmount(lp, buy_limit);
-
- System.out.printf("Creating Buy Order from lp: %f, %f\n",lp,limit);
+ //System.out.printf("Creating Buy Order from lp: %f, %f\n",lp,limit);
double volume = money / limit;
// System.out.printf("Volume : %f", volume);
limit = se.roundMoney(limit);
volume = se.roundShares(volume);
- if (volume <= 0 || money <= 0) {
+ // if (volume <= 0 || money <= 0) {
+ // System.out.printf("Buy failed %f, %f / %f (%f)\n", volume,money,limit,ad.getMoney());
// System.out.printf("Buy Order wont work\n");
+ // return false;
+ // }
+ long rc = se.createOrder(account_id, type, volume, limit);
+
+ if (rc == -1) {
+
+// System.out.printf("Buy failed %f, %f / %f (%f)\n", volume, money, limit, ad.getMoney());
return false;
}
+ //System.out.printf("Creating Sell Order from lp: %f, %f\n",lp,limit);
- se.createOrder(account_id, type, volume, limit);
- System.out.printf("Creating Sell Order from lp: %f, %f\n",lp,limit);
-
return true;
}
@@ -421,13 +427,18 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
limit = lp + getRandomAmmount(lp, sell_limit);
se.roundMoney(limit);
- if (volume <= 0 || limit <= 0) {
+ // if (volume <= 0 || limit <= 0) {
+ // System.out.printf("Sell failed %f, %f (%f)\n", volume,limit,ad.getMoney());
// System.out.printf("Sell wont work\n");
+ // return false;
+ // }
+// System.out.printf("Create a Sell Order %f %f!!!!\n", volume, limit);
+ long rc = se.createOrder(account_id, type, volume, limit);
+ if (rc == -1) {
+ //System.out.printf("Sell failed %f, %f (%f)\n", volume, limit, ad.getMoney());
+
return false;
}
-// System.out.printf("Create a Sell Order %f %f!!!!\n", volume, limit);
- se.createOrder(account_id, type, volume, limit);
-
return true;
}