Work on stop loss
This commit is contained in:
parent
3f43ff6f29
commit
0cedbbc3d4
@ -1,4 +1,4 @@
|
||||
#Mon, 31 Dec 2018 14:02:50 +0100
|
||||
#Tue, 01 Jan 2019 15:33:07 +0100
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
|
@ -45,8 +45,23 @@ public class Account {
|
||||
|
||||
Trader owner;
|
||||
//public Exchange exchange = null;
|
||||
|
||||
|
||||
private World world;
|
||||
|
||||
|
||||
|
||||
private boolean unlimited = false;
|
||||
|
||||
public boolean isUnlimied() {
|
||||
return unlimited;
|
||||
}
|
||||
|
||||
void setUnlimied(boolean unlimied) {
|
||||
this.unlimited = unlimied;
|
||||
}
|
||||
|
||||
|
||||
private double leverage = 0.0;
|
||||
|
||||
public double getLeverage() {
|
||||
@ -83,9 +98,6 @@ public class Account {
|
||||
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
|
||||
synchronized void add(AssetPack pack) {
|
||||
assets.put(pack.asset, get(pack.asset) + pack.volume);
|
||||
assets_avail.put(pack.asset, getAvail(pack.asset) + pack.volume);
|
||||
|
@ -62,6 +62,11 @@ public class GodWorld implements GetJson, World {
|
||||
return scheduler.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractAsset getDefaultCurrency() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class JKEYS {
|
||||
|
||||
public static final String ASSETS = "assets";
|
||||
|
@ -90,4 +90,9 @@ public class RealWorld implements World {
|
||||
return godworld.getAssetPair(asset, currency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractAsset getDefaultCurrency() {
|
||||
return godworld.getDefaultCurrency();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public class SimpleTrader extends AbstractTrader implements EventListener {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Account account_s, account_b;
|
||||
public Account account_10, account_1;
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
@ -96,47 +96,43 @@ public class SimpleTrader extends AbstractTrader implements EventListener {
|
||||
|
||||
AssetPair p = getWorld().getDefaultAssetPair();
|
||||
|
||||
account_s = new Account(getWorld());
|
||||
account_b = new Account(getWorld());
|
||||
account_10 = new Account(getWorld());
|
||||
account_1 = new Account(getWorld());
|
||||
|
||||
AssetPack pack;
|
||||
pack = new AssetPack(p.getAsset(),200);
|
||||
account_s.add(pack);
|
||||
|
||||
pack = new AssetPack(p.getCurrency(),0);
|
||||
account_b.add(pack);
|
||||
pack = new AssetPack(p.getAsset(), 0);
|
||||
account_10.add(pack);
|
||||
|
||||
pack = new AssetPack(p.getCurrency(), 1000);
|
||||
account_b.add(pack);
|
||||
account_b.setLeverage(0.0);
|
||||
account_10.add(pack);
|
||||
account_10.setLeverage(10);
|
||||
|
||||
pack = new AssetPack(p.getCurrency(), 100000);
|
||||
account_1.add(pack);
|
||||
account_1.setLeverage(1.0);
|
||||
|
||||
ex = getWorld().getDefaultExchange();
|
||||
api = ex.getAPI(p);
|
||||
|
||||
AssetPair msftp = getWorld().getAssetPair(getWorld().getAssetBySymbol("MSFT"),
|
||||
getWorld().getAssetBySymbol("EUR"));
|
||||
TradingAPI mapi = ex.getAPI(msftp);
|
||||
|
||||
Order ob = api.createOrder(account_10, Order.Type.BUYLIMIT, 20, 100);
|
||||
Order mob = mapi.createOrder(account_10, Order.Type.SELLLIMIT, 80, 100);
|
||||
|
||||
Order oa = api.createOrder(account_1, Order.Type.SELLLIMIT, 100, 100);
|
||||
Order oaaa = mapi.createOrder(account_1, Order.Type.BUYLIMIT, 100, 100);
|
||||
|
||||
|
||||
Order oa = api.createOrder(account_b, Order.Type.BUYLIMIT, 50, 100);
|
||||
// Order ob = api.createOrder(account_s, Order.Type.SELLLIMIT, 200,100);
|
||||
|
||||
|
||||
|
||||
|
||||
// Order oa = api.createOrder(account_b, Order.Type.BUYLIMIT, 100, 10.0);
|
||||
// Order ob = api.createOrder(account_b, Order.Type.BUYLIMIT, 100, 9.0);
|
||||
// Order oc = api.createOrder(account_b, Order.Type.BUYLIMIT, 100, 8.0);
|
||||
|
||||
// Order o2 = api.createOrder(account_s, Order.Type.SELLLIMIT, 300, 1.0);
|
||||
|
||||
|
||||
//Order ou = api.createOrder(account_b, Order.Type.BUYLIMIT, 30, 10.0);
|
||||
|
||||
|
||||
|
||||
|
||||
//Order oax = mapi.createOrder(account_1, Order.Type.BUYLIMIT, 100, 100);
|
||||
|
||||
// Order oa = api.createOrder(account_1, Order.Type.BUYLIMIT, 100, 10.0);
|
||||
// Order ob = api.createOrder(account_1, Order.Type.BUYLIMIT, 100, 9.0);
|
||||
// Order oc = api.createOrder(account_1, Order.Type.BUYLIMIT, 100, 8.0);
|
||||
// Order o2 = api.createOrder(account_10, Order.Type.SELLLIMIT, 300, 1.0);
|
||||
//Order ou = api.createOrder(account_1, Order.Type.BUYLIMIT, 30, 10.0);
|
||||
// Order o1 = api.createOrder(account, Order.Type.SELLLIMIT, 250, 278);
|
||||
|
||||
|
||||
long delay = (long) (1000.0f * getWorld().randNextFloat(3.0f, 12.7f));
|
||||
setStatus(String.format("Initial delay: Sleeping for %d seconds.", delay));
|
||||
// getWorld().schedule(this, delay);
|
||||
@ -150,9 +146,6 @@ public class SimpleTrader extends AbstractTrader implements EventListener {
|
||||
|
||||
double limit = 253.871239;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public long receive(Event task) {
|
||||
// System.out.printf("Here we are !!! %f\n", getWorld().randNextFloat(12f, 27f));
|
||||
|
@ -428,8 +428,12 @@ class TradingEngine implements TradingAPI {
|
||||
|
||||
double order_limit;
|
||||
|
||||
if (account.isUnlimied()) {
|
||||
order_limit = l;
|
||||
} else {
|
||||
switch (type) {
|
||||
case BUYLIMIT: {
|
||||
|
||||
// verfify available currency for a buy limit order
|
||||
AbstractAsset currency = this.assetpair.getCurrency();
|
||||
|
||||
@ -491,6 +495,7 @@ class TradingEngine implements TradingAPI {
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
o = new Order(this, account, type, v, order_limit);
|
||||
|
||||
@ -500,58 +505,166 @@ class TradingEngine implements TradingAPI {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
executeOrders();
|
||||
// last_quote.price = 200;
|
||||
for (FiringEvent e : book_listener) {
|
||||
for (FiringEvent e : book_listener
|
||||
|
||||
|
||||
) {
|
||||
e.fire();
|
||||
}
|
||||
return o ;
|
||||
|
||||
}
|
||||
|
||||
HashSet<FiringEvent> book_listener = new HashSet<>();
|
||||
HashSet
|
||||
|
||||
<FiringEvent
|
||||
|
||||
> book_listener
|
||||
|
||||
= new HashSet
|
||||
|
||||
<>();
|
||||
|
||||
@Override
|
||||
public void addOrderBookListener(EventListener listener) {
|
||||
book_listener.add(new FiringEvent(listener));
|
||||
public
|
||||
|
||||
void addOrderBookListener
|
||||
|
||||
(EventListener
|
||||
|
||||
listener
|
||||
|
||||
) {
|
||||
book_listener
|
||||
|
||||
.add
|
||||
|
||||
(new FiringEvent
|
||||
|
||||
(listener
|
||||
|
||||
));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set getOrderBook(Order.Type type) {
|
||||
switch (type) {
|
||||
case BUYLIMIT:
|
||||
case BUY:
|
||||
return Collections.unmodifiableSet(bidbook);
|
||||
public Set
|
||||
|
||||
getOrderBook
|
||||
|
||||
(Order
|
||||
|
||||
.Type
|
||||
|
||||
type
|
||||
|
||||
) {
|
||||
switch (type
|
||||
|
||||
) {
|
||||
case BUYLIMIT
|
||||
|
||||
:
|
||||
case BUY
|
||||
|
||||
:
|
||||
return Collections
|
||||
|
||||
.unmodifiableSet
|
||||
|
||||
(bidbook
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
||||
case SELLLIMIT
|
||||
|
||||
:
|
||||
case SELL
|
||||
|
||||
:
|
||||
return Collections
|
||||
|
||||
.unmodifiableSet
|
||||
|
||||
(askbook
|
||||
|
||||
);
|
||||
|
||||
|
||||
case SELLLIMIT:
|
||||
case SELL:
|
||||
return Collections.unmodifiableSet(askbook);
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set
|
||||
getBidBook() {
|
||||
return getOrderBook(Order.Type.BUYLIMIT
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set
|
||||
getAskBook() {
|
||||
return getOrderBook(Order.Type.SELL
|
||||
|
||||
|
||||
getBidBook
|
||||
|
||||
() {
|
||||
return getOrderBook
|
||||
|
||||
(Order
|
||||
|
||||
.Type
|
||||
|
||||
.BUYLIMIT
|
||||
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Quote> getQuoteHistory() {
|
||||
public Set
|
||||
|
||||
|
||||
getAskBook
|
||||
|
||||
() {
|
||||
return getOrderBook
|
||||
|
||||
(Order
|
||||
|
||||
.Type
|
||||
|
||||
.SELL
|
||||
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set
|
||||
|
||||
<Quote
|
||||
|
||||
> getQuoteHistory
|
||||
|
||||
() {
|
||||
return Collections
|
||||
.unmodifiableSet(quote_history
|
||||
|
||||
|
||||
.unmodifiableSet
|
||||
|
||||
(quote_history
|
||||
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,7 @@ public interface World {
|
||||
|
||||
public Exchange getDefaultExchange();
|
||||
public AssetPair getDefaultAssetPair();
|
||||
public AbstractAsset getDefaultCurrency();
|
||||
|
||||
Collection<Trader> getTradersCollection();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user