Added some stuff.

This commit is contained in:
7u83 2017-01-14 14:42:00 +01:00
parent 4973868db5
commit 7bf55870b1
6 changed files with 65 additions and 44 deletions

View File

@ -42,7 +42,8 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
OHLCDataItem current = null;
int min;
int max;
int getY(float Y){
return 0;
@ -200,12 +201,12 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
// max = 5;
// min = 0;
System.out.print("Fval: " + y + " " + min + "\n");
// System.out.print("Fval: " + y + " " + min + "\n");
y -= min;
System.out.print("VAL New" + y + "\n");
// System.out.print("VAL New" + y + "\n");
//val/ ((data.max-data.min)/dim.height);
System.out.print("MINMAX " + min + " " + max + " " + dim.height + "\n");
// System.out.print("MINMAX " + min + " " + max + " " + dim.height + "\n");
y = dim.height - (dim.height * y / (max - min));
@ -217,7 +218,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
lastx = x;
lasty = (int) y;
System.out.print("Draw Line: " + x + " " + y + "\n");
// System.out.print("Draw Line: " + x + " " + y + "\n");
}

View File

@ -183,7 +183,7 @@ public class MainWin extends javax.swing.JFrame {
}//GEN-LAST:event_jButton1ActionPerformed
private void FileRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileRunActionPerformed
se.start();
// se.start();
}//GEN-LAST:event_FileRunActionPerformed
private void helpAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpAboutActionPerformed
@ -206,14 +206,16 @@ public class MainWin extends javax.swing.JFrame {
// SwitchingTraderConfig rcfg1 = new SwitchingTraderConfig();
RandomTraderConfig rcfg1 = new RandomTraderConfig();
AutoTrader rt1 = rcfg1.createTrader(se, 1000000, 0);
rt1.setName("Bob");
rt1.start();
//AutoTrader rt2 = rcfg1.createTrader(se, 1, 100);
//rt2.start();
RandomTraderConfig cfg = new RandomTraderConfig();
for (int i=0; i<100; i++){
for (int i=0; i<10000; i++){
AutoTrader randt = cfg.createTrader(se, 100, 100);
randt.setName("Alice");
randt.start();
}

View File

@ -35,6 +35,8 @@ public abstract class AutoTrader {
protected Exchange se;
protected AutoTraderConfig config;
protected String name;
@ -42,12 +44,17 @@ public abstract class AutoTrader {
account_id = se.createAccount(money, shares);
this.se=se;
this.config=config;
this.name="";
}
/*public AutoTrader(Exchange se, double money, double shares){
this(se,money,shares,null);
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
*/
public abstract void start();

View File

@ -9,7 +9,7 @@ import sesim.Order_old.OrderType_old;
*
* @author tube
*/
public class Exchange extends Thread {
public class Exchange { //extends Thread {
public enum OrderType {
BID, ASK
@ -23,9 +23,9 @@ public class Exchange extends Thread {
*/
public class Account implements Comparable {
protected double id;
protected double shares;
protected double money;
private double id;
private double shares;
private double money;
private final HashMap<Long, Order> orders;
@ -287,12 +287,13 @@ public class Exchange extends Thread {
while (i.hasNext()) {
i.next().UpdateOrderBook();
}
try {
/* try {
sleep(10);
} catch (InterruptedException e) {
System.out.println("I was Interrupted");
}
*/
}
// Here we store the list of quote receivers
@ -324,7 +325,7 @@ public class Exchange extends Thread {
public TreeSet<Order_old> bid;
public TreeSet<Order_old> ask;
private Locker tradelock = new Locker();
private final Locker tradelock = new Locker();
/*
private final Semaphore available = new Semaphore(1, true);
@ -704,12 +705,12 @@ public class Exchange extends Thread {
if (a == null) {
return -1;
}
tradelock.lock();
Order o = new Order(a, type, volume, limit);
addOrderToBook(o);
a.orders.put(o.id, o);
tradelock.lock();
this.executeOrders();
tradelock.unlock();
this.updateBookReceivers(OrderType.ASK);
@ -842,9 +843,9 @@ public class Exchange extends Thread {
/**
*
*/
@Override
// @Override
public void run() {
while (true) {
/* while (true) {
try {
sleep(1500);
} catch (InterruptedException e) {
@ -853,6 +854,7 @@ public class Exchange extends Thread {
print_current();
}
*/
}
}

View File

@ -44,34 +44,32 @@ public class RandomTrader extends AutoTrader {
//static Timer timer = new Timer();
enum Event {
/* enum Event {
CANCEL,
CREATE
}
*/
public long megaLoop(){
long rc=0;
for (int i=0; i<1; i++){
rc+=i;
// System.out.print(rc+"\n");
}
return rc;
}
long event(){
// System.out.print("Hello world Iam a trader\n");
return this.doTrade();
// doBuy();
if ("Alice".equals(this.name)){
megaLoop();
}
sesim.Exchange.Account a = se.getAccount(account_id);
long rc = this.doTrade();
// System.out.print(String.format("%s: %.0f/%.2f\n", this.getName(),a.getShares(),a.getMoney()));
return rc;
}
class NextEvent {
public Event event;
public long time;
/* NextEvent(Event e, long time) {
this.event = e;
this.time = time;
}
*/
}
public RandomTrader(Exchange se, double money, double shares, RandomTraderConfig config) {
super(se, money, shares, config);
if (this.config == null) {
@ -96,11 +94,12 @@ public class RandomTrader extends AutoTrader {
}
double start = 0.1;
Timer timer=new Timer();
@Override
public void start() {
Exchange.timer.schedule(new TimerTaskImpl(this), 0);
timer.schedule(new TimerTaskImpl(this,timer), 0);
// timer.schedule(new TimerTaskImpl, date);
}
@ -256,10 +255,11 @@ public class RandomTrader extends AutoTrader {
private static class TimerTaskImpl extends TimerTask {
RandomTrader trader;
NextEvent nextevent;
Timer timer;
public TimerTaskImpl(RandomTrader trader) {
public TimerTaskImpl(RandomTrader trader, Timer timer) {
this.trader = trader;
this.timer=timer;
}
@ -267,10 +267,10 @@ public class RandomTrader extends AutoTrader {
public void run() {
long time = trader.event();
time/=50;
time/=1;
this.cancel();
Exchange.timer.schedule(new TimerTaskImpl(trader), time);
timer.schedule(new TimerTaskImpl(trader,timer), time);
}
}

View File

@ -51,6 +51,14 @@ public class Test {
double aid1 = se.createAccount(100, 100);
double aid2 = se.createAccount(100, 100);
sesim.Exchange.Account a = se.getAccount(aid1);
System.out.print(a.getMoney());
System.exit(0);
/*
AccountData a1 = se.getAccountData(aid1);
AccountData a2 = se.getAccountData(aid2);
@ -76,6 +84,7 @@ public class Test {
//S/ystem.out.print(aid);
//System.out.print("\n");
*/
}
}