Some reformatting.
This commit is contained in:
parent
c1e3e2162c
commit
c0676d5b03
@ -9,6 +9,7 @@ public class Exchange extends Thread {
|
||||
|
||||
// Class to describe an executed order
|
||||
public class Quote {
|
||||
|
||||
double bid;
|
||||
double bid_size;
|
||||
double ask;
|
||||
@ -19,35 +20,29 @@ public class Exchange extends Thread {
|
||||
public long time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// QuoteReceiver has to be implemented by objects that wants
|
||||
// to receive quote updates
|
||||
public interface QuoteReceiver
|
||||
{
|
||||
public interface QuoteReceiver {
|
||||
|
||||
void UpdateQuote(Quote q);
|
||||
}
|
||||
|
||||
// Here we store the list of quote receivers
|
||||
TreeSet<QuoteReceiver> qrlist = new TreeSet<QuoteReceiver>();
|
||||
public void AddQuoteReceiver(QuoteReceiver qr)
|
||||
{
|
||||
|
||||
public void AddQuoteReceiver(QuoteReceiver qr) {
|
||||
qrlist.add(qr);
|
||||
}
|
||||
|
||||
// send updated quotes to all quote receivers
|
||||
void UpdateQuoteReceivers(Quote q)
|
||||
{
|
||||
void UpdateQuoteReceivers(Quote q) {
|
||||
Iterator<QuoteReceiver> i = qrlist.iterator();
|
||||
while (i.hasNext()) {
|
||||
i.next().UpdateQuote(q);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ArrayList<Quote> quoteHistory = new ArrayList<Quote>();
|
||||
public ArrayList<Quote> quoteHistory = new ArrayList();
|
||||
|
||||
// long time = 0;
|
||||
double price = 12.9;
|
||||
@ -57,7 +52,6 @@ public class Exchange extends Thread {
|
||||
long lastsize;
|
||||
|
||||
// Order orderlist[];
|
||||
|
||||
TreeSet<BuyOrder> bid = new TreeSet<BuyOrder>();
|
||||
TreeSet<SellOrder> ask = new TreeSet<SellOrder>();
|
||||
|
||||
@ -76,34 +70,28 @@ public class Exchange extends Thread {
|
||||
available.release();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void print_current() {
|
||||
|
||||
|
||||
BuyOrder b;
|
||||
SellOrder a;
|
||||
|
||||
|
||||
//String bid;
|
||||
|
||||
|
||||
if (bid.isEmpty()) {
|
||||
b = new BuyOrder();
|
||||
b.limit = -1;
|
||||
b.size = 0;
|
||||
} else
|
||||
} else {
|
||||
b = bid.first();
|
||||
}
|
||||
|
||||
if (ask.isEmpty()) {
|
||||
a = new SellOrder();
|
||||
a.limit = -1;
|
||||
a.size = 0;
|
||||
|
||||
} else
|
||||
} else {
|
||||
a = ask.first();
|
||||
|
||||
}
|
||||
|
||||
Logger.info(
|
||||
String.format("BID: %s(%s) LAST: %.2f(%d) ASK: %s(%s)\n",
|
||||
@ -164,18 +152,11 @@ public class Exchange extends Thread {
|
||||
if (b.limit >= a.limit) {
|
||||
double price;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (b.id < a.id)
|
||||
if (b.id < a.id) {
|
||||
price = b.limit;
|
||||
else
|
||||
} else {
|
||||
price = a.limit;
|
||||
|
||||
|
||||
}
|
||||
|
||||
long size = 0;
|
||||
|
||||
@ -201,7 +182,6 @@ public class Exchange extends Thread {
|
||||
this.UpdateQuoteReceivers(q);
|
||||
|
||||
//quoteHistory.add(q);
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
@ -251,7 +231,6 @@ public class Exchange extends Thread {
|
||||
*
|
||||
* }
|
||||
*/
|
||||
|
||||
public double getlastprice() {
|
||||
/*
|
||||
* SellOrder so = new SellOrder(); so.limit=1000.0; so.size=500;
|
||||
|
@ -6,15 +6,17 @@ public class Logger {
|
||||
static boolean info = true;
|
||||
|
||||
static void dbg(String s) {
|
||||
if (!dbg)
|
||||
if (!dbg) {
|
||||
return;
|
||||
}
|
||||
System.out.print("DBG: ");
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
static void info(String s) {
|
||||
if (!info)
|
||||
if (!info) {
|
||||
return;
|
||||
}
|
||||
System.out.print("INFO: ");
|
||||
System.out.println(s);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package StockExchange;
|
||||
|
||||
public class SellOrder extends Order {
|
||||
|
||||
@Override
|
||||
public int compareTo(Order o) {
|
||||
|
||||
if (o.limit < limit) {
|
||||
|
Loading…
Reference in New Issue
Block a user