Moved Account class out of Exchange to sesim
This commit is contained in:
parent
dfe4661d11
commit
4aacac8d76
@ -1,4 +1,4 @@
|
||||
#Mon, 09 Oct 2017 14:13:25 +0200
|
||||
#Mon, 09 Oct 2017 16:27:25 +0200
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
|
@ -34,7 +34,7 @@ import java.util.Map;
|
||||
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import sesim.Exchange.Account;
|
||||
import sesim.Account;
|
||||
import sesim.Order;
|
||||
import sesim.Order.OrderType;
|
||||
import traders.ManTrader.CreateOrderDialog;
|
||||
|
@ -40,7 +40,7 @@ import javax.swing.table.TableRowSorter;
|
||||
|
||||
import sesim.AutoTraderInterface;
|
||||
import sesim.Exchange;
|
||||
import sesim.Exchange.Account;
|
||||
import sesim.Account;
|
||||
|
||||
/**
|
||||
*
|
||||
|
89
src/sesim/Account.java
Normal file
89
src/sesim/Account.java
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2017, tobias
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package sesim;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Implements a trading account
|
||||
*/
|
||||
public class Account implements Comparable {
|
||||
|
||||
private Exchange.AccountListener listener = null;
|
||||
|
||||
protected final double id;
|
||||
protected double shares;
|
||||
protected double money;
|
||||
protected AutoTraderInterface owner;
|
||||
|
||||
protected final ConcurrentHashMap<Long, Order> orders;
|
||||
|
||||
@Override
|
||||
public int compareTo(Object a) {
|
||||
Account account = (Account) a;
|
||||
return this.id - account.id < 0 ? -1 : 1;
|
||||
}
|
||||
|
||||
Account(double id, double money, double shares) {
|
||||
this.id=id;
|
||||
//id = (random.nextDouble() + (account_id_generator.getNext()));
|
||||
orders = new ConcurrentHashMap();
|
||||
this.money = money;
|
||||
this.shares = shares;
|
||||
}
|
||||
|
||||
public double getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public double getShares() {
|
||||
return shares;
|
||||
}
|
||||
|
||||
public double getMoney() {
|
||||
return money;
|
||||
}
|
||||
|
||||
public AutoTraderInterface getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<Long, Order> getOrders() {
|
||||
return orders;
|
||||
}
|
||||
|
||||
public void setListener(Exchange.AccountListener al) {
|
||||
this.listener = al;
|
||||
}
|
||||
|
||||
public void update(Order o) {
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
listener.accountUpdated(this, o);
|
||||
}
|
||||
|
||||
}
|
@ -72,7 +72,7 @@ public abstract class AutoTraderBase implements AutoTraderInterface, TimerTaskRu
|
||||
}
|
||||
private long id;
|
||||
|
||||
public Exchange.Account getAccount() {
|
||||
public Account getAccount() {
|
||||
return se.getAccount(account_id);
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ public interface AutoTraderInterface {
|
||||
*/
|
||||
public void init(Exchange se, long id, String name, double money, double shares, JSONObject cfg);
|
||||
|
||||
public Exchange.Account getAccount();
|
||||
public Account getAccount();
|
||||
|
||||
public void start();
|
||||
|
||||
|
@ -39,6 +39,7 @@ import org.json.JSONObject;
|
||||
import sesim.Order.OrderStatus;
|
||||
import sesim.Order.OrderType;
|
||||
|
||||
|
||||
/**
|
||||
* @desc Echchange class
|
||||
* @author 7u83
|
||||
@ -209,65 +210,6 @@ public class Exchange {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements a trading account
|
||||
*/
|
||||
public class Account implements Comparable {
|
||||
|
||||
private AccountListener listener = null;
|
||||
|
||||
private final double id;
|
||||
private double shares;
|
||||
private double money;
|
||||
protected AutoTraderInterface owner;
|
||||
|
||||
private final ConcurrentHashMap<Long, Order> orders;
|
||||
|
||||
@Override
|
||||
public int compareTo(Object a) {
|
||||
Account account = (Account) a;
|
||||
return this.id - account.id < 0 ? -1 : 1;
|
||||
}
|
||||
|
||||
Account(double money, double shares) {
|
||||
id = (random.nextDouble() + (account_id_generator.getNext()));
|
||||
orders = new ConcurrentHashMap();
|
||||
this.money = money;
|
||||
this.shares = shares;
|
||||
}
|
||||
|
||||
public double getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public double getShares() {
|
||||
return shares;
|
||||
}
|
||||
|
||||
public double getMoney() {
|
||||
return money;
|
||||
}
|
||||
|
||||
public AutoTraderInterface getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<Long, Order> getOrders() {
|
||||
return orders;
|
||||
}
|
||||
|
||||
public void setListener(AccountListener al) {
|
||||
this.listener = al;
|
||||
}
|
||||
|
||||
public void update(Order o) {
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
listener.accountUpdated(this, o);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void createTraders(JSONArray traderdefs) {
|
||||
for (int i = 0; i < traderdefs.length(); i++) {
|
||||
@ -285,7 +227,9 @@ public class Exchange {
|
||||
|
||||
public double createAccount(double money, double shares) {
|
||||
|
||||
Account a = new Account(money, shares);
|
||||
double id = (random.nextDouble() + (account_id_generator.getNext()));
|
||||
|
||||
Account a = new Account(id, money, shares);
|
||||
accounts.put(a.id, a);
|
||||
return a.id;
|
||||
}
|
||||
|
@ -55,11 +55,11 @@ public class Order {
|
||||
protected final long id;
|
||||
protected final long created;
|
||||
|
||||
protected final Exchange.Account account;
|
||||
protected final Account account;
|
||||
|
||||
double cost;
|
||||
|
||||
Order(long id, long created, Exchange.Account account, OrderType type, double volume, double limit) {
|
||||
Order(long id, long created, Account account, OrderType type, double volume, double limit) {
|
||||
//id = order_id_generator.getNext();
|
||||
this.id = id;
|
||||
this.account = account;
|
||||
@ -108,7 +108,7 @@ public class Order {
|
||||
return cost / e;
|
||||
}
|
||||
|
||||
public Exchange.Account getAccount() {
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
*/
|
||||
package traders.ManTrader;
|
||||
|
||||
import sesim.Exchange.Account;
|
||||
import sesim.Account;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -27,7 +27,7 @@ package traders.ManTrader;
|
||||
|
||||
import gui.Globals;
|
||||
|
||||
import sesim.Exchange.Account;
|
||||
import sesim.Account;
|
||||
import sesim.Order.OrderType;
|
||||
import sesim.Quote;
|
||||
|
||||
|
@ -39,6 +39,7 @@ import sesim.Exchange;
|
||||
import sesim.Exchange.AccountListener;
|
||||
import sesim.Order.OrderStatus;
|
||||
import sesim.Order;
|
||||
import sesim.Account;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -115,7 +116,7 @@ public class ManTrader extends AutoTraderBase implements AccountListener, AutoTr
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accountUpdated(Exchange.Account a, Order o) {
|
||||
public void accountUpdated(Account a, Order o) {
|
||||
//this.consoleDialog.cons
|
||||
//System.out.printf("AccountListener called\n");
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
package traders.ManTrader;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import sesim.Exchange.Account;
|
||||
import sesim.Account;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -34,7 +34,7 @@ import org.json.JSONObject;
|
||||
import sesim.AutoTraderBase;
|
||||
import sesim.AutoTraderGui;
|
||||
import sesim.Exchange;
|
||||
import sesim.Exchange.Account;
|
||||
import sesim.Account;
|
||||
import sesim.Exchange.AccountListener;
|
||||
|
||||
import sesim.Order.OrderType;
|
||||
@ -86,7 +86,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
|
||||
public long timerTask() {
|
||||
intask = true;
|
||||
owait = null;
|
||||
sesim.Exchange.Account a = se.getAccount(account_id);
|
||||
sesim.Account a = se.getAccount(account_id);
|
||||
long rc = this.doTrade();
|
||||
setStatus("Sleeping for %d ms", rc);
|
||||
intask = false;
|
||||
|
@ -35,7 +35,7 @@ import org.json.JSONObject;
|
||||
|
||||
import sesim.AutoTraderBase;
|
||||
import sesim.AutoTraderGui;
|
||||
import sesim.Exchange.Account;
|
||||
import sesim.Account;
|
||||
import sesim.Order.OrderType;
|
||||
import sesim.Quote;
|
||||
|
||||
@ -75,7 +75,7 @@ public class RandomTraderB extends AutoTraderBase {
|
||||
|
||||
@Override
|
||||
public long timerTask() {
|
||||
sesim.Exchange.Account a = se.getAccount(account_id);
|
||||
sesim.Account a = se.getAccount(account_id);
|
||||
long rc = this.doTrade();
|
||||
return rc;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user