Interface improved

This commit is contained in:
7u83 2017-01-12 09:07:08 +01:00 committed by 7u83
parent 68d7925f82
commit 0373f310a7
4 changed files with 67 additions and 22 deletions

View File

@ -192,6 +192,9 @@ public class MainWin extends javax.swing.JFrame {
RandomTrader rt = rcfg.createTrader(se, 1000, 100);
rt.start();
RandomTraderConfig rcfg1 = new RandomTraderConfig();
RandomTrader rt1 = rcfg.createTrader(se, 1000, 100);
rt1.start();

View File

@ -159,12 +159,12 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B
Formatter f = new Formatter();
switch (c) {
case 0:
return f.format("#%06x", o.id);
return String.format("#%06x", o.id);
case 1:
return o.limit;
return String.format("%.4f",o.limit);
case 2:
return o.volume;
return String.format("%.4f", o.volume);
}
return "";
}

View File

@ -17,6 +17,7 @@ public class Exchange extends Thread {
}
IDGenerator account_id = new IDGenerator();
public static Timer timer=new Timer();
private class Account implements Comparable {
@ -485,7 +486,7 @@ public class Exchange extends Thread {
q.time = System.currentTimeMillis();
System.out.print("Price" + q.price + "," + q.volume + "\n");
//this.updateQuoteReceivers(q);
}
private void executeOrders_old() {
@ -660,6 +661,7 @@ public class Exchange extends Thread {
tradelock.unlock();
this.updateBookReceivers(OrderType.ASK);
this.updateBookReceivers(OrderType.BID);
return o.id;
}

View File

@ -27,7 +27,6 @@ package traders;
import java.util.*;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import sesim.AccountData;
@ -43,7 +42,7 @@ import sesim.*;
*/
public class RandomTrader extends AutoTrader {
static Timer timer = new Timer();
//static Timer timer = new Timer();
enum Event {
CANCEL,
@ -54,7 +53,7 @@ public class RandomTrader extends AutoTrader {
long event(){
System.out.print("Hello world Iam a trader\n");
return this.cancelOrders();
return this.doTrade();
// doBuy();
}
@ -82,7 +81,7 @@ public class RandomTrader extends AutoTrader {
@Override
public void start() {
timer.schedule(new TimerTaskImpl(this), 0);
Exchange.timer.schedule(new TimerTaskImpl(this), 0);
// timer.schedule(new TimerTaskImpl, date);
}
@ -143,15 +142,11 @@ public class RandomTrader extends AutoTrader {
}
}
doBuy();
return 15000;
return n;
}
public boolean doBuy() {
public long doBuy() {
RandomTraderConfig myconfig = (RandomTraderConfig)this.config;
AccountData ad = this.se.getAccountData(account_id);
@ -167,16 +162,61 @@ public class RandomTrader extends AutoTrader {
long volume = (long) (money / (limit * 1));
if (volume <= 0) {
//return false;
return 0;
}
System.out.print("Volume is:"+volume+"\n");
System.out.print("My Ammount is: "+money+" My limit si:"+limit+ "\n");
//System.exit(0);
se.createOrder(account_id, OrderType.BID, volume, limit);
return true;
se.createOrder(account_id, type, volume, limit);
return getRandom(myconfig.buy_order_wait)*1000;
}
public long doSell() {
RandomTraderConfig myconfig = (RandomTraderConfig)this.config;
AccountData ad = this.se.getAccountData(account_id);
OrderType type=OrderType.ASK;
// how much money we ant to envest?
double volume = (long)getRandomAmmount(ad.shares, myconfig.sell_volume);
double lp = 100.0; //se.getBestLimit(type);
double limit;
limit = lp + getRandomAmmount(lp, myconfig.sell_limit);
// long volume = (long) (money / (limit * 1));
// if (volume <= 0) {
// return false;
// }
System.out.print("Volume is:"+volume+"\n");
System.out.print("My Ammount is: "+volume+" My limit si:"+limit+ "\n");
se.createOrder(account_id, type, volume, limit);
return getRandom(myconfig.sell_order_wait)*1000;
}
long doTrade(){
cancelOrders();
int what = rand.nextInt(2);
if (what==0)
return doBuy();
else
return doSell();
}
@ -202,7 +242,7 @@ public class RandomTrader extends AutoTrader {
long time = trader.event();
this.cancel();
timer.schedule(new TimerTaskImpl(trader), time);
Exchange.timer.schedule(new TimerTaskImpl(trader), time);
}
}