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); RandomTrader rt = rcfg.createTrader(se, 1000, 100);
rt.start(); 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(); Formatter f = new Formatter();
switch (c) { switch (c) {
case 0: case 0:
return f.format("#%06x", o.id); return String.format("#%06x", o.id);
case 1: case 1:
return o.limit; return String.format("%.4f",o.limit);
case 2: case 2:
return o.volume; return String.format("%.4f", o.volume);
} }
return ""; return "";
} }

View File

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

View File

@ -27,7 +27,6 @@ package traders;
import java.util.*; import java.util.*;
import java.util.Random; import java.util.Random;
import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import sesim.AccountData; import sesim.AccountData;
@ -43,7 +42,7 @@ import sesim.*;
*/ */
public class RandomTrader extends AutoTrader { public class RandomTrader extends AutoTrader {
static Timer timer = new Timer(); //static Timer timer = new Timer();
enum Event { enum Event {
CANCEL, CANCEL,
@ -54,7 +53,7 @@ public class RandomTrader extends AutoTrader {
long event(){ long event(){
System.out.print("Hello world Iam a trader\n"); System.out.print("Hello world Iam a trader\n");
return this.cancelOrders(); return this.doTrade();
// doBuy(); // doBuy();
} }
@ -82,7 +81,7 @@ public class RandomTrader extends AutoTrader {
@Override @Override
public void start() { public void start() {
timer.schedule(new TimerTaskImpl(this), 0); Exchange.timer.schedule(new TimerTaskImpl(this), 0);
// timer.schedule(new TimerTaskImpl, date); // timer.schedule(new TimerTaskImpl, date);
} }
@ -143,18 +142,14 @@ public class RandomTrader extends AutoTrader {
} }
} }
doBuy(); return n;
return 15000;
} }
public boolean doBuy() { public long doBuy() {
RandomTraderConfig myconfig = (RandomTraderConfig)this.config; RandomTraderConfig myconfig = (RandomTraderConfig)this.config;
AccountData ad = this.se.getAccountData(account_id); AccountData ad = this.se.getAccountData(account_id);
OrderType type=OrderType.BID; OrderType type=OrderType.BID;
// how much money we ant to envest? // how much money we ant to envest?
@ -167,18 +162,63 @@ public class RandomTrader extends AutoTrader {
long volume = (long) (money / (limit * 1)); long volume = (long) (money / (limit * 1));
if (volume <= 0) { if (volume <= 0) {
//return false; return 0;
} }
System.out.print("Volume is:"+volume+"\n"); System.out.print("Volume is:"+volume+"\n");
System.out.print("My Ammount is: "+money+" My limit si:"+limit+ "\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();
} }
protected NextEvent createOrder() { protected NextEvent createOrder() {
@ -202,7 +242,7 @@ public class RandomTrader extends AutoTrader {
long time = trader.event(); long time = trader.event();
this.cancel(); this.cancel();
timer.schedule(new TimerTaskImpl(trader), time); Exchange.timer.schedule(new TimerTaskImpl(trader), time);
} }
} }