Unlimited sell order works now

This commit is contained in:
7u83 2017-02-21 00:52:34 +01:00
parent eb2b6844bd
commit 17f033df24
3 changed files with 31 additions and 21 deletions

View File

@ -774,6 +774,9 @@ public class Exchange {
double volume_total = 0; double volume_total = 0;
double money_total = 0; double money_total = 0;
while (true) {
// Match unlimited sell orders against unlimited buy orders // Match unlimited sell orders against unlimited buy orders
while (!ul_sell.isEmpty() && !ul_buy.isEmpty()) { while (!ul_sell.isEmpty() && !ul_buy.isEmpty()) {
System.out.printf("Cannot match two unlimited orders!\n"); System.out.printf("Cannot match two unlimited orders!\n");
@ -787,10 +790,17 @@ public class Exchange {
Order a = ul_sell.first(); Order a = ul_sell.first();
double price = b.limit; double price = b.limit;
double volume = b.volume >= a.volume ? a.volume : b.volume; double volume = b.volume >= a.volume ? a.volume : b.volume;
finishTrade(b, a, price, volume);
volume_total += volume;
money_total += price * volume;
this.checkSLOrders(price);
}
// Match limited against limited orders
if (bid.isEmpty() || ask.isEmpty()) {
break;
} }
while (!bid.isEmpty() && !ask.isEmpty()) {
Order b = bid.first(); Order b = bid.first();
Order a = ask.first(); Order a = ask.first();
@ -803,7 +813,6 @@ public class Exchange {
double volume = b.volume >= a.volume ? a.volume : b.volume; double volume = b.volume >= a.volume ? a.volume : b.volume;
finishTrade(b, a, price, volume); finishTrade(b, a, price, volume);
volume_total += volume; volume_total += volume;
money_total += price * volume; money_total += price * volume;
@ -812,7 +821,7 @@ public class Exchange {
this.checkSLOrders(price); this.checkSLOrders(price);
} }
//System.out.print("Volume total is "+volume_total+"\n");
if (volume_total == 0) { if (volume_total == 0) {
return; return;
} }

View File

@ -91,9 +91,10 @@
<Component class="javax.swing.JComboBox" name="typeComboBox"> <Component class="javax.swing.JComboBox" name="typeComboBox">
<Properties> <Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor"> <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="2"> <StringArray count="3">
<StringItem index="0" value="Buy "/> <StringItem index="0" value="Buy Limit"/>
<StringItem index="1" value="Sell"/> <StringItem index="1" value="Sell Limit"/>
<StringItem index="2" value="Sell"/>
</StringArray> </StringArray>
</Property> </Property>
</Properties> </Properties>

View File

@ -53,8 +53,8 @@ public class CreateOrderDialog extends javax.swing.JDialog {
public CreateOrderDialog(java.awt.Frame parent, boolean modal, Account account, OrderType type) { public CreateOrderDialog(java.awt.Frame parent, boolean modal, Account account, OrderType type) {
this(parent, modal); this(parent, modal);
this.account = account; this.account = account;
typeComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]{"Buy ", "Sell"})); typeComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]{"Buy Lim", "Sell Lim", "Sell"}));
typeList = new OrderType[]{OrderType.BUYLIMIT, OrderType.SELLLIMIT}; typeList = new OrderType[]{OrderType.BUYLIMIT, OrderType.SELLLIMIT, OrderType.SELL};
for (int i = 0; i < typeList.length; i++) { for (int i = 0; i < typeList.length; i++) {
if (typeList[i] == type) { if (typeList[i] == type) {
this.typeComboBox.setSelectedIndex(i); this.typeComboBox.setSelectedIndex(i);
@ -123,7 +123,7 @@ public class CreateOrderDialog extends javax.swing.JDialog {
} }
}); });
typeComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Buy ", "Sell" })); typeComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Buy Limit", "Sell Limit", "Sell" }));
limitSpinner.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, null, 0.1d)); limitSpinner.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, null, 0.1d));