Some work on traders ...

This commit is contained in:
7u83
2016-12-26 13:36:59 +01:00
parent 818282d4cb
commit 5fa813df72
8 changed files with 59 additions and 12 deletions

View File

@ -12,6 +12,9 @@ public class Account {
*/
public double money = 0;
/**
* Name of this account
*/
public String name = "";
public boolean orderpending = false;

View File

@ -95,9 +95,9 @@ public class Exchange extends Thread {
Logger.info(
String.format("BID: %s(%s) LAST: %.2f(%d) ASK: %s(%s)\n",
b.format_limit(), b.format_size(),
b.format_limit(), b.format_volume(),
lastprice, lastsize,
a.format_limit(), a.format_size())
a.format_limit(), a.format_volume())
);
}
@ -194,6 +194,11 @@ public class Exchange extends Thread {
// SellOrder op = ask.peek();
}
private void InitOrder(Order o){
double moneyNeeded = o.volume * o.limit;
}
public void SendOrder(SellOrder o) {
// System.out.println("EX Sellorder");

View File

@ -2,7 +2,7 @@ package SeSim;
import java.util.Random;
public class MTrader implements Trader {
public class MTrader extends Trader {
Exchange ex;
Random rand;

View File

@ -42,7 +42,7 @@ public abstract class Order implements Comparable<Order> {
return String.format("%.2f", limit);
}
String format_size() {
String format_volume() {
return String.format("%d", volume);
}

View File

@ -3,14 +3,13 @@ package SeSim;
import java.util.Random;
import SeSim.Order.OrderStatus;
public class RandomTrader extends ThreadedTrader {
public class RandomTrader extends Trader {
// public Account account=new Account();
Exchange ex = null;
Random rand = new Random();
public String name;
// my current order
private Order myorder = null;

View File

@ -1,11 +1,12 @@
package SeSim;
public abstract class ThreadedTrader extends Thread implements Trader {
public abstract class ThreadedTrader extends Thread {
protected long sleeptime = 100;
public void RandomTrader(Exchange ex, long shares, double money) {
// this.ex=ex;
}
@ -15,8 +16,9 @@ public abstract class ThreadedTrader extends Thread implements Trader {
sleep(sleeptime);
} catch (InterruptedException e) {
System.out.println("Interrupted");
return;
}
trade();
// trade();
}
}

View File

@ -1,11 +1,13 @@
package SeSim;
public interface Trader {
public abstract class Trader {
// String name = null;
String name = null;
public void trade();
public abstract void trade();
public Account account = new Account();
// public Exchange ex=null;
};