some scheduler testing testing

This commit is contained in:
7u83 2017-04-11 07:56:43 +02:00
parent f0888a55d0
commit 4dcc9d8d56
6 changed files with 38 additions and 24 deletions

View File

@ -1,4 +1,4 @@
#Mon, 10 Apr 2017 19:52:24 +0200 #Tue, 11 Apr 2017 07:53:43 +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=

View File

@ -44,27 +44,22 @@ public class Statistics extends javax.swing.JPanel {
new Timer().schedule(new TimerTask() { new Timer().schedule(new TimerTask() {
@Override @Override
public void run() { public void run() {
System.out.printf("Statistics comming\n");
Exchange.Statistics s = Globals.se.getStatistics(); Exchange.Statistics s = Globals.se.getStatistics();
tradesLabel.setText(String.format("%d", s.trades)); tradesLabel.setText(String.format("%d", s.trades));
if (s.heigh == null) {
if (s.heigh == null){
labelHigh.setText("--"); labelHigh.setText("--");
} } else {
else {
labelHigh.setText(Globals.se.getMoneyFormatter().format(s.heigh)); labelHigh.setText(Globals.se.getMoneyFormatter().format(s.heigh));
} }
if (s.low == null){ if (s.low == null) {
labelLow.setText("--"); labelLow.setText("--");
} } else {
else {
labelLow.setText(Globals.se.getMoneyFormatter().format(s.low)); labelLow.setText(Globals.se.getMoneyFormatter().format(s.low));
} }
} }
}, 1000, 1000); }, 1000, 1000);

View File

@ -31,6 +31,8 @@ import gui.tools.NummericCellRenderer;
import java.awt.Component; import java.awt.Component;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@ -126,6 +128,15 @@ public class OrderBook extends javax.swing.JPanel implements Exchange.BookReceiv
cfgChanged(); cfgChanged();
// Globals.se.addBookReceiver(Exchange.OrderType.BUYLIMIT, this); // Globals.se.addBookReceiver(Exchange.OrderType.BUYLIMIT, this);
Globals.addCfgListener(this); Globals.addCfgListener(this);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// System.out.printf("Update order book\n");
// UpdateOrderBook();
}
}, 1000, 1000);
} }
boolean oupdate = false; boolean oupdate = false;

View File

@ -1136,6 +1136,7 @@ public class Exchange {
Account a = accounts.get(account_id); Account a = accounts.get(account_id);
if (a == null) { if (a == null) {
System.out.printf("Order not places account\n");
return -1; return -1;
} }
@ -1154,7 +1155,7 @@ public class Exchange {
buy_failed++; buy_failed++;
break; break;
} }
System.out.printf("Order ffailed %f %f \n",o.volume,o.limit);
return -1; return -1;

View File

@ -268,6 +268,7 @@ public class Scheduler extends Thread {
// HashMap<TimerTaskDef, Long> tasks = new HashMap<>(); // HashMap<TimerTaskDef, Long> tasks = new HashMap<>();
private boolean addTimerTask(TimerTaskDef e) { private boolean addTimerTask(TimerTaskDef e) {
// System.out.printf("Add TimerTask %d %d\n",e.curevtime,e.newevtime);
// long evtime = time + currentTimeMillis(); // long evtime = time + currentTimeMillis();
SortedSet<TimerTaskDef> s = event_queue.get(e.newevtime); SortedSet<TimerTaskDef> s = event_queue.get(e.newevtime);
if (s == null) { if (s == null) {
@ -293,9 +294,10 @@ public class Scheduler extends Thread {
// if (evtime == null) { // if (evtime == null) {
// return; // return;
// } // }
System.out.printf("Cancel my %d\n", e.id);
SortedSet<TimerTaskDef> s = event_queue.get(e.curevtime); SortedSet<TimerTaskDef> s = event_queue.get(e.curevtime);
if (s == null) { if (s == null) {
System.out.printf("My not found\n");
return; return;
} }
@ -389,6 +391,8 @@ public class Scheduler extends Thread {
while (!set_tasks.isEmpty()) { while (!set_tasks.isEmpty()) {
TimerTaskDef td = set_tasks.poll(); TimerTaskDef td = set_tasks.poll();
System.out.printf("There is a set task %d %d\n",td.curevtime,td.newevtime);
this.cancelMy(td); this.cancelMy(td);
this.addTimerTask(td); this.addTimerTask(td);

View File

@ -77,11 +77,15 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
timerTask = se.timer.startTimerTask(this, delay); timerTask = se.timer.startTimerTask(this, delay);
} }
boolean intask=false;
@Override @Override
public long timerTask() { public long timerTask() {
intask=true;
sesim.Exchange.Account a = se.getAccount(account_id); sesim.Exchange.Account a = se.getAccount(account_id);
long rc = this.doTrade(); long rc = this.doTrade();
setStatus("Sleeping for %d ms", rc); setStatus("Sleeping for %d ms", rc);
intask =false;
setStatus("Return fromtask %d", rc);
return rc; return rc;
} }
@ -114,8 +118,8 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
} }
void setStatus(String format, Object... arguments) { 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); System.out.printf("%s: %s\n", this.getName(), s);
} }
private Float[] to_float(JSONArray a) { private Float[] to_float(JSONArray a) {
@ -191,6 +195,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
@Override @Override
public void accountUpdated(Account a, Exchange.Order o) { public void accountUpdated(Account a, Exchange.Order o) {
setStatus("Account update -%s ",o.getOrderStatus().toString());
//System.out.printf("Order updated %s %d\n", o.getOrderStatus().toString(), Thread.currentThread().getId()); //System.out.printf("Order updated %s %d\n", o.getOrderStatus().toString(), Thread.currentThread().getId());
if (o.getOrderStatus() == OrderStatus.CLOSED) { if (o.getOrderStatus() == OrderStatus.CLOSED) {
@ -203,6 +208,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
// System.out.printf("We have now to wait for %d\n", w); // System.out.printf("We have now to wait for %d\n", w);
// se.timer.cancelTimerTask(this); // se.timer.cancelTimerTask(this);
// timerTask = se.timer.startTimerTask(this, w); // timerTask = se.timer.startTimerTask(this, w);
setStatus("Reschedule %d",w);
se.timer.rescheduleTimerTask(timerTask, w); se.timer.rescheduleTimerTask(timerTask, w);
} }
// System.out.printf("Updatetd Account\n", ""); // System.out.printf("Updatetd Account\n", "");
@ -225,11 +231,12 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
Action mode = Action.RANDOM; Action mode = Action.RANDOM;
Integer doTrade1(Action a) { Integer doTrade1(Action a) {
setStatus("doTrade1 with action %s",a.toString());
switch (a) { switch (a) {
case BUY: { case BUY: {
boolean rc = doBuy(); boolean rc = doBuy();
if (rc) { if (rc) {
setStatus("dobuy");
mode = Action.BUY; mode = Action.BUY;
return getRandom(buy_wait); return getRandom(buy_wait);
} }
@ -240,6 +247,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
case SELL: { case SELL: {
boolean rc = doSell(); boolean rc = doSell();
if (rc) { if (rc) {
setStatus("dosell");
mode = Action.SELL; mode = Action.SELL;
return getRandom(sell_wait); return getRandom(sell_wait);
@ -310,7 +318,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
setStatus("No trade possible, returning 5000"); setStatus("No trade possible, returning 5000");
//System.out.printf("All ha s failed\n"); //System.out.printf("All ha s failed\n");
return 5000; return 5007;
} }
setStatus("Current mode is %s", mode.toString()); setStatus("Current mode is %s", mode.toString());
@ -430,12 +438,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
// } // }
// System.out.printf("Create a Sell Order %f %f!!!!\n", volume, limit); // System.out.printf("Create a Sell Order %f %f!!!!\n", volume, limit);
long rc = se.createOrder(account_id, type, volume, limit); long rc = se.createOrder(account_id, type, volume, limit);
if (rc == -1) { return rc != -1;
//System.out.printf("Sell failed %f, %f (%f)\n", volume, limit, ad.getMoney());
return false;
}
return true;
} }