uses one and only one exchange - for now
This commit is contained in:
parent
06727072e4
commit
2250a1e4eb
@ -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;
|
||||||
@ -35,20 +36,21 @@ import org.json.JSONObject;
|
|||||||
*
|
*
|
||||||
* @author 7u83 <7u83@mail.ru>
|
* @author 7u83 <7u83@mail.ru>
|
||||||
*/
|
*/
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleTrader(){
|
public SimpleTrader() {
|
||||||
this(null,null);
|
this(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
float initial_delay[] = new float[2];
|
float initial_delay[] = new float[2];
|
||||||
@ -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);
|
||||||
@ -90,10 +103,10 @@ public class SimpleTrader extends AbstractTrader implements EventListener{
|
|||||||
public long receive(Event task) {
|
public long receive(Event task) {
|
||||||
// System.out.printf("Here we are !!! %f\n", getWorld().randNextFloat(12f, 27f));
|
// System.out.printf("Here we are !!! %f\n", getWorld().randNextFloat(12f, 27f));
|
||||||
|
|
||||||
long diff = getWorld().currentTimeMillis()-last_time;
|
long diff = getWorld().currentTimeMillis() - last_time;
|
||||||
last_time = getWorld().currentTimeMillis();
|
last_time = getWorld().currentTimeMillis();
|
||||||
|
|
||||||
System.out.printf("Here we are: %d - [%d]\n",Thread.currentThread().getId(),diff);
|
System.out.printf("Here we are: %d - [%d]\n", Thread.currentThread().getId(), diff);
|
||||||
getWorld().schedule(this, 1000);
|
getWorld().schedule(this, 1000);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user