some tes, some improvements
This commit is contained in:
parent
7c89af5a42
commit
5cf177a346
@ -305,11 +305,11 @@
|
|||||||
<Component id="jButton2" min="-2" pref="67" max="-2" attributes="0"/>
|
<Component id="jButton2" min="-2" pref="67" max="-2" attributes="0"/>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component id="stopButton" min="-2" pref="63" max="-2" attributes="0"/>
|
<Component id="stopButton" min="-2" pref="63" max="-2" attributes="0"/>
|
||||||
<EmptySpace pref="389" max="32767" attributes="0"/>
|
<EmptySpace pref="375" max="32767" attributes="0"/>
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
<Component id="clock" alignment="1" min="-2" max="-2" attributes="0"/>
|
<Component id="clock" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||||
<Group type="102" alignment="1" attributes="0">
|
<Group type="102" alignment="1" attributes="0">
|
||||||
<Component id="jComboBox1" min="-2" max="-2" attributes="0"/>
|
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component id="accelSpinner" min="-2" pref="100" max="-2" attributes="0"/>
|
<Component id="accelSpinner" min="-2" pref="100" max="-2" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
@ -326,18 +326,12 @@
|
|||||||
<Group type="102" attributes="0">
|
<Group type="102" attributes="0">
|
||||||
<EmptySpace min="-2" pref="3" max="-2" attributes="0"/>
|
<EmptySpace min="-2" pref="3" max="-2" attributes="0"/>
|
||||||
<Component id="clock" min="-2" max="-2" attributes="0"/>
|
<Component id="clock" min="-2" max="-2" attributes="0"/>
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Group type="102" attributes="0">
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<Component id="accelSpinner" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
<Component id="accelSpinner" min="-2" max="-2" attributes="0"/>
|
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
|
||||||
</Group>
|
|
||||||
<Group type="102" alignment="1" attributes="0">
|
|
||||||
<EmptySpace max="32767" attributes="0"/>
|
|
||||||
<Component id="jComboBox1" min="-2" max="-2" attributes="0"/>
|
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
|
||||||
</Group>
|
|
||||||
</Group>
|
</Group>
|
||||||
|
<EmptySpace min="0" pref="5" max="32767" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
</DimensionLayout>
|
</DimensionLayout>
|
||||||
@ -394,35 +388,23 @@
|
|||||||
<Component class="javax.swing.JSpinner" name="accelSpinner">
|
<Component class="javax.swing.JSpinner" name="accelSpinner">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
|
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
|
||||||
<SpinnerModel initial="1.0" minimum="0.0" numberType="java.lang.Double" stepSize="100.0" type="number"/>
|
<SpinnerModel initial="1.0" minimum="0.0" numberType="java.lang.Double" stepSize="1.0" type="number"/>
|
||||||
</Property>
|
</Property>
|
||||||
</Properties>
|
</Properties>
|
||||||
<Events>
|
<Events>
|
||||||
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="accelSpinnerStateChanged"/>
|
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="accelSpinnerStateChanged"/>
|
||||||
|
<EventHandler event="propertyChange" listener="java.beans.PropertyChangeListener" parameters="java.beans.PropertyChangeEvent" handler="accelSpinnerPropertyChange"/>
|
||||||
</Events>
|
</Events>
|
||||||
|
<AuxValues>
|
||||||
|
<AuxValue name="JavaCodeGenerator_SerializeTo" type="java.lang.String" value="NewMDIApplication_accelSpinner"/>
|
||||||
|
</AuxValues>
|
||||||
</Component>
|
</Component>
|
||||||
<Component class="gui.Clock" name="clock">
|
<Component class="gui.Clock" name="clock">
|
||||||
</Component>
|
</Component>
|
||||||
<Component class="javax.swing.JComboBox" name="jComboBox1">
|
<Component class="javax.swing.JLabel" name="jLabel1">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
<Property name="text" type="java.lang.String" value="Acceleration:"/>
|
||||||
<StringArray count="7">
|
|
||||||
<StringItem index="0" value="1x"/>
|
|
||||||
<StringItem index="1" value="2x"/>
|
|
||||||
<StringItem index="2" value="4x"/>
|
|
||||||
<StringItem index="3" value="10x"/>
|
|
||||||
<StringItem index="4" value="100x"/>
|
|
||||||
<StringItem index="5" value="1000x"/>
|
|
||||||
<StringItem index="6" value="max."/>
|
|
||||||
</StringArray>
|
|
||||||
</Property>
|
|
||||||
</Properties>
|
</Properties>
|
||||||
<Events>
|
|
||||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jComboBox1ActionPerformed"/>
|
|
||||||
</Events>
|
|
||||||
<AuxValues>
|
|
||||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
|
||||||
</AuxValues>
|
|
||||||
</Component>
|
</Component>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Container>
|
</Container>
|
||||||
|
@ -128,7 +128,9 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
|||||||
|
|
||||||
Globals.se.fairValue = moneyTotal / sharesTotal;
|
Globals.se.fairValue = moneyTotal / sharesTotal;
|
||||||
|
|
||||||
Globals.se.fairValue = 1.0;
|
// Globals.se.fairValue = 1.0;
|
||||||
|
System.out.printf("Failr Value is %f\n", Globals.se.fairValue);
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < Globals.se.traders.size(); i++) {
|
for (int i = 0; i < Globals.se.traders.size(); i++) {
|
||||||
Globals.se.traders.get(i).start();
|
Globals.se.traders.get(i).start();
|
||||||
@ -156,7 +158,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
|||||||
jButton2 = new javax.swing.JButton();
|
jButton2 = new javax.swing.JButton();
|
||||||
accelSpinner = new javax.swing.JSpinner();
|
accelSpinner = new javax.swing.JSpinner();
|
||||||
clock = new gui.Clock();
|
clock = new gui.Clock();
|
||||||
jComboBox1 = new javax.swing.JComboBox<>();
|
jLabel1 = new javax.swing.JLabel();
|
||||||
jSplitPane3 = new javax.swing.JSplitPane();
|
jSplitPane3 = new javax.swing.JSplitPane();
|
||||||
jSplitPane4 = new javax.swing.JSplitPane();
|
jSplitPane4 = new javax.swing.JSplitPane();
|
||||||
orderBooksHorizontal1 = new gui.orderbook.OrderBooksHorizontal();
|
orderBooksHorizontal1 = new gui.orderbook.OrderBooksHorizontal();
|
||||||
@ -243,20 +245,20 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
accelSpinner.setModel(new javax.swing.SpinnerNumberModel(1.0d, 0.0d, null, 100.0d));
|
accelSpinner.setModel(new javax.swing.SpinnerNumberModel(1.0d, 0.0d, null, 1.0d));
|
||||||
accelSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
|
accelSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
|
||||||
public void stateChanged(javax.swing.event.ChangeEvent evt) {
|
public void stateChanged(javax.swing.event.ChangeEvent evt) {
|
||||||
accelSpinnerStateChanged(evt);
|
accelSpinnerStateChanged(evt);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
accelSpinner.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
|
||||||
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1x", "2x", "4x", "10x", "100x", "1000x", "max." }));
|
public void propertyChange(java.beans.PropertyChangeEvent evt) {
|
||||||
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
|
accelSpinnerPropertyChange(evt);
|
||||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
||||||
jComboBox1ActionPerformed(evt);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jLabel1.setText("Acceleration:");
|
||||||
|
|
||||||
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
|
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
|
||||||
jPanel2.setLayout(jPanel2Layout);
|
jPanel2.setLayout(jPanel2Layout);
|
||||||
jPanel2Layout.setHorizontalGroup(
|
jPanel2Layout.setHorizontalGroup(
|
||||||
@ -267,11 +269,11 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
|||||||
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 389, Short.MAX_VALUE)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 375, Short.MAX_VALUE)
|
||||||
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addComponent(clock, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(clock, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
|
||||||
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(jLabel1)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(accelSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
.addComponent(accelSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||||
.addContainerGap())
|
.addContainerGap())
|
||||||
@ -284,15 +286,11 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
|||||||
.addGroup(jPanel2Layout.createSequentialGroup()
|
.addGroup(jPanel2Layout.createSequentialGroup()
|
||||||
.addGap(3, 3, 3)
|
.addGap(3, 3, 3)
|
||||||
.addComponent(clock, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(clock, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addGroup(jPanel2Layout.createSequentialGroup()
|
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addComponent(accelSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addComponent(accelSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(jLabel1))
|
||||||
.addGap(0, 0, Short.MAX_VALUE))
|
.addGap(0, 5, Short.MAX_VALUE))
|
||||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
|
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
||||||
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
||||||
.addContainerGap())))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_START);
|
getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_START);
|
||||||
@ -728,9 +726,9 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
|||||||
}
|
}
|
||||||
}//GEN-LAST:event_viewTraderListCheckBoxActionPerformed
|
}//GEN-LAST:event_viewTraderListCheckBoxActionPerformed
|
||||||
|
|
||||||
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
|
private void accelSpinnerPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_accelSpinnerPropertyChange
|
||||||
// TODO add your handling code here:
|
System.out.printf("Accel Spinner PRop Change\n");
|
||||||
}//GEN-LAST:event_jComboBox1ActionPerformed
|
}//GEN-LAST:event_accelSpinnerPropertyChange
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args the command line arguments
|
* @param args the command line arguments
|
||||||
@ -774,7 +772,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
|||||||
private javax.swing.JButton jButton2;
|
private javax.swing.JButton jButton2;
|
||||||
private javax.swing.JScrollPane jChartScrollPane;
|
private javax.swing.JScrollPane jChartScrollPane;
|
||||||
private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1;
|
private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1;
|
||||||
private javax.swing.JComboBox<String> jComboBox1;
|
private javax.swing.JLabel jLabel1;
|
||||||
private javax.swing.JMenuItem jMenuItem1;
|
private javax.swing.JMenuItem jMenuItem1;
|
||||||
private javax.swing.JMenuItem jMenuItem3;
|
private javax.swing.JMenuItem jMenuItem3;
|
||||||
private javax.swing.JMenuItem jMenuItem4;
|
private javax.swing.JMenuItem jMenuItem4;
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
package sesim;
|
package sesim;
|
||||||
|
|
||||||
//import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date;
|
//import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date;
|
||||||
|
import gui.Globals;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@ -364,6 +365,7 @@ public class Scheduler extends Thread {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long timerTask() {
|
public long timerTask() {
|
||||||
|
// System.out.printf("Current best brice %f\n", Globals.se.getBestPrice());
|
||||||
return 1000;
|
return 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -402,7 +404,7 @@ public class Scheduler extends Thread {
|
|||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
try {
|
try {
|
||||||
System.out.printf("My WTIME %d\n", wtime);
|
// System.out.printf("My WTIME %d\n", wtime);
|
||||||
if (wtime != -1 && !pause) {
|
if (wtime != -1 && !pause) {
|
||||||
wait(wtime);
|
wait(wtime);
|
||||||
} else {
|
} else {
|
||||||
|
@ -73,7 +73,8 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
|
|||||||
a.setListener(this);
|
a.setListener(this);
|
||||||
|
|
||||||
long delay = (long) (getRandom(initial_delay[0], initial_delay[1]) * 1000);
|
long delay = (long) (getRandom(initial_delay[0], initial_delay[1]) * 1000);
|
||||||
timerTask = se.timer.startTimerTask(this, delay);
|
setStatus("Inital delay: %d\n",delay);
|
||||||
|
timerTask = se.timer.startTimerTask(this, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -82,7 +83,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
|
|||||||
sesim.Exchange.Account a = se.getAccount(account_id);
|
sesim.Exchange.Account a = se.getAccount(account_id);
|
||||||
// System.out.printf("Have Account %d\n", Thread.currentThread().getId());
|
// System.out.printf("Have Account %d\n", Thread.currentThread().getId());
|
||||||
long rc = this.doTrade();
|
long rc = this.doTrade();
|
||||||
// System.out.printf("Exit TimerTask for %d / %d\n", System.identityHashCode(this), Thread.currentThread().getId());
|
setStatus("Sleeping for %d ms", rc);
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -114,6 +115,11 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
|
|||||||
return jo;
|
return jo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setStatus(String format, Object... arguments) {
|
||||||
|
// String s = String.format(format, arguments);
|
||||||
|
// System.out.printf("%s: %s\n", this.getName(), s);
|
||||||
|
}
|
||||||
|
|
||||||
private Float[] to_float(JSONArray a) {
|
private Float[] to_float(JSONArray a) {
|
||||||
Float[] ret = new Float[a.length()];
|
Float[] ret = new Float[a.length()];
|
||||||
for (int i = 0; i < a.length(); i++) {
|
for (int i = 0; i < a.length(); i++) {
|
||||||
@ -188,17 +194,19 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
|
|||||||
@Override
|
@Override
|
||||||
public void accountUpdated(Account a, Exchange.Order o) {
|
public void accountUpdated(Account a, Exchange.Order o) {
|
||||||
// System.out.printf("Order what %s %d\n", o.getOrderStatus().toString(), Thread.currentThread().getId());
|
// System.out.printf("Order what %s %d\n", o.getOrderStatus().toString(), Thread.currentThread().getId());
|
||||||
if (o.getOrderStatus() == OrderStatus.CLOSED ) {
|
if (o.getOrderStatus() == OrderStatus.CLOSED) {
|
||||||
|
|
||||||
// System.out.printf("Enteter canel timer %d\n", Thread.currentThread().getId());
|
// System.out.printf("Enteter canel timer %d\n", Thread.currentThread().getId());
|
||||||
// se.timer.cancelTimerTask(this);
|
// se.timer.cancelTimerTask(this);
|
||||||
//System.out.printf("back from canel timer %d\n", System.identityHashCode(this));
|
//System.out.printf("back from canel timer %d\n", System.identityHashCode(this));
|
||||||
//System.exit(0);
|
//System.exit(0);
|
||||||
|
|
||||||
Long w = waitAfterOrder();
|
Long w = waitAfterOrder();
|
||||||
|
|
||||||
|
setStatus("Order closed, %s", o.getType().toString());
|
||||||
|
|
||||||
// System.out.printf("We have now to wait for %d\n", w);
|
// System.out.printf("We have now to wait for %d\n", w);
|
||||||
//timerTask = se.timer.startTimerTask(this, w);
|
//timerTask = se.timer.startTimerTask(this, w);
|
||||||
se.timer.XXXrescheduleTimerTask(timerTask, w);
|
// se.timer.XXXrescheduleTimerTask(timerTask, w);
|
||||||
|
|
||||||
}
|
}
|
||||||
// System.out.printf("Updatetd Account\n", "");
|
// System.out.printf("Updatetd Account\n", "");
|
||||||
@ -248,16 +256,19 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long waitAfterOrder() {
|
||||||
long waitAfterOrder(){
|
if (mode == Action.BUY) {
|
||||||
if (mode == Action.BUY) {
|
|
||||||
mode = Action.RANDOM;
|
mode = Action.RANDOM;
|
||||||
return getRandom(wait_after_buy);
|
long r = getRandom(wait_after_buy);
|
||||||
|
setStatus("Wait after buy: %d ms", r);
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == Action.SELL) {
|
if (mode == Action.SELL) {
|
||||||
mode = Action.RANDOM;
|
mode = Action.RANDOM;
|
||||||
return getRandom(wait_after_sell);
|
long r = getRandom(wait_after_sell);
|
||||||
|
setStatus("Wait after sell: %d ms", r);
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
// System.out.printf("Return action 0\n");
|
// System.out.printf("Return action 0\n");
|
||||||
@ -265,36 +276,47 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
long doTrade() {
|
long doTrade() {
|
||||||
|
|
||||||
// System.out.printf("Do Trader %d\n", Thread.currentThread().getId());
|
long co = cancelOrders();
|
||||||
cancelOrders();
|
setStatus("Orders cancled: %d",co);
|
||||||
// System.out.printf("Orders Canceled %d\n", Thread.currentThread().getId());
|
if (co>0)
|
||||||
|
mode = Action.RANDOM;
|
||||||
|
|
||||||
Action a = getAction();
|
Action a = getAction();
|
||||||
|
|
||||||
// System.out.printf("Action is %s\n", a.toString());
|
// System.out.printf("Action is %s\n", a.toString());
|
||||||
|
|
||||||
if (mode == Action.RANDOM) {
|
if (mode == Action.RANDOM) {
|
||||||
|
|
||||||
|
setStatus("Mode is %s, next action is %s",mode.toString(),a.toString());
|
||||||
|
|
||||||
// System.out.printf("Action: %s\n", a.toString());
|
// System.out.printf("Action: %s\n", a.toString());
|
||||||
Integer rc = doTrade1(a);
|
Integer rc = doTrade1(a);
|
||||||
if (rc != null) {
|
if (rc != null) {
|
||||||
|
setStatus("Action %s success full, ret %d",a.toString(),rc);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rc = doTrade1(Action.BUY);
|
rc = doTrade1(Action.BUY);
|
||||||
if (rc != null) {
|
if (rc != null) {
|
||||||
|
setStatus("BuyAction %s successfull, ret %d",a.toString(),rc);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
rc = doTrade1(Action.SELL);
|
rc = doTrade1(Action.SELL);
|
||||||
if (rc != null) {
|
if (rc != null) {
|
||||||
|
setStatus("SellAction %s successfull, ret %d",a.toString(),rc);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setStatus("No trade possible, returning 5000");
|
||||||
// System.out.printf("All ha s failed\n");
|
// System.out.printf("All ha s failed\n");
|
||||||
return 5000;
|
return 5000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setStatus("Current mode is %s",mode.toString());
|
||||||
return waitAfterOrder();
|
return waitAfterOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.lang.ClassLoader.*;
|
import java.lang.ClassLoader.*;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import sesim.Scheduler.TimerTaskRunner;
|
import sesim.Scheduler.TimerTaskRunner;
|
||||||
@ -111,27 +112,28 @@ public class Test {
|
|||||||
static class Runner extends Thread {
|
static class Runner extends Thread {
|
||||||
|
|
||||||
}
|
}
|
||||||
static Scheduler s = new Scheduler();
|
static Scheduler s = new Scheduler();
|
||||||
|
|
||||||
static class MyTask implements TimerTaskRunner{
|
static class MyTask implements TimerTaskRunner {
|
||||||
|
|
||||||
|
long ctr = 0;
|
||||||
|
|
||||||
long ctr=0;
|
|
||||||
@Override
|
@Override
|
||||||
public long timerTask() {
|
public long timerTask() {
|
||||||
ctr++;
|
ctr++;
|
||||||
double r=1;
|
double r = 1;
|
||||||
for (int i=0; i<100000; i++){
|
for (int i = 0; i < 100000; i++) {
|
||||||
r=r+i*r;
|
r = r + i * r;
|
||||||
r=r+1.0;
|
r = r + 1.0;
|
||||||
}
|
}
|
||||||
synchronized (this){
|
synchronized (this) {
|
||||||
try {
|
try {
|
||||||
wait(500);
|
wait(500);
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.printf("TimerTask %d %d %f\n",ctr,s.currentTimeMillis(),r);
|
System.out.printf("TimerTask %d %d %f\n", ctr, s.currentTimeMillis(), r);
|
||||||
|
|
||||||
return 1000;
|
return 1000;
|
||||||
}
|
}
|
||||||
@ -143,25 +145,18 @@ public class Test {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args the command line arguments
|
* @param args the command line arguments
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws InterruptedException, MalformedURLException, InstantiationException, IllegalAccessException, IOException {
|
public static void main(String[] args) throws InterruptedException, MalformedURLException, InstantiationException, IllegalAccessException, IOException {
|
||||||
|
|
||||||
Clock clock = new Clock();
|
Random r;
|
||||||
|
r = new Random(10);
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
s.start();
|
int e = r.nextInt(50);
|
||||||
|
System.out.printf("Zufallszahl: %d\n", e);
|
||||||
s.setAcceleration(1);
|
}
|
||||||
|
|
||||||
MyTask t = new MyTask();
|
|
||||||
|
|
||||||
s.setAcceleration(1.0);
|
|
||||||
s.startTimerTask(t, 0);
|
|
||||||
|
|
||||||
s.join();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user