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.in.editor=false
annotation.processing.processors.list=

View File

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

View File

@ -31,6 +31,8 @@ import gui.tools.NummericCellRenderer;
import java.awt.Component;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
@ -126,6 +128,15 @@ public class OrderBook extends javax.swing.JPanel implements Exchange.BookReceiv
cfgChanged();
// Globals.se.addBookReceiver(Exchange.OrderType.BUYLIMIT, 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;

View File

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

View File

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

View File

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