Some imprements

This commit is contained in:
7u83 2017-03-19 18:07:58 +01:00
parent 0c152dca81
commit cd2d0c65ff
8 changed files with 164 additions and 57 deletions

View File

@ -43,13 +43,5 @@
<exec.executable>java</exec.executable>
</properties>
</action>
<action>
<actionName>build</actionName>
<packagings>
<packaging>*</packaging>
</packagings>
<goals>
<goal>install</goal>
</goals>
</action>
</actions>

23
pom.xml
View File

@ -48,6 +48,11 @@
<artifactId>AbsoluteLayout</artifactId>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>webstart-maven-plugin</artifactId>
<version>1.0-beta-7</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -62,4 +67,22 @@
<url>file:${project.basedir}/lib</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<version>1.0-beta-7</version>
<artifactId>webstart-maven-plugin</artifactId>
<configuration>
<jnlp>
<mainClass>com.cauwersin.SeSim.gui.NewMDIApplication</mainClass>
</jnlp>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -487,6 +487,15 @@
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
<SubComponents>
<Component class="gui.Statistics" name="statistics1">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="top"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>

View File

@ -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;

View File

@ -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(

View File

@ -378,8 +378,11 @@ public class Exchange {
public TreeSet<Quote> 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<Order> bid = order_books.get(OrderType.BUYLIMIT);
SortedSet<Order> 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();

View File

@ -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<TimerTaskDef> it = s.iterator();

View File

@ -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;
}