uses one and only one exchange - for now

This commit is contained in:
7u83 2018-12-21 23:50:25 +01:00
parent 06727072e4
commit 2250a1e4eb

View File

@ -26,6 +26,7 @@
package opensesim.trader; package opensesim.trader;
import opensesim.world.AbstractTrader; import opensesim.world.AbstractTrader;
import opensesim.world.Exchange;
import opensesim.world.World; import opensesim.world.World;
import opensesim.world.scheduler.Event; import opensesim.world.scheduler.Event;
import opensesim.world.scheduler.EventListener; import opensesim.world.scheduler.EventListener;
@ -37,12 +38,13 @@ import org.json.JSONObject;
*/ */
public class SimpleTrader extends AbstractTrader implements EventListener { public class SimpleTrader extends AbstractTrader implements EventListener {
Exchange ex = null;
@Override @Override
public String getStrategyTypeName() { public String getStrategyTypeName() {
return "Very Simple Trader"; return "Very Simple Trader";
} }
public SimpleTrader(World world, JSONObject cfg) { public SimpleTrader(World world, JSONObject cfg) {
super(world, cfg); super(world, cfg);
} }
@ -69,12 +71,23 @@ public class SimpleTrader extends AbstractTrader implements EventListener{
return 0; return 0;
} }
@Override @Override
public void start() { public void start() {
setVerbose(true); setVerbose(true);
setStatus("Trader started"); setStatus("Trader started");
// set exchange if we haven't one already
if (ex == null) {
ex = getWorld().getDefaultExchange();
}
if (ex != null) {
this.log(String.format("Exchange is %s", ex.getName()));
} else {
this.log("No exchange. Stopping.");
setStatus("Stopped.");
return;
}
long delay = (long) (1000.0f * getWorld().randNextFloat(3.0f, 12.7f)); long delay = (long) (1000.0f * getWorld().randNextFloat(3.0f, 12.7f));
setStatus(String.format("Initial delay: Sleeping for %d seconds.", delay)); setStatus(String.format("Initial delay: Sleeping for %d seconds.", delay));
getWorld().schedule(this, delay); getWorld().schedule(this, delay);