Unlimited sell order works now
This commit is contained in:
parent
eb2b6844bd
commit
17f033df24
@ -774,23 +774,33 @@ public class Exchange {
|
||||
double volume_total = 0;
|
||||
double money_total = 0;
|
||||
|
||||
// Match unlimited sell orders against unlimited buy orders
|
||||
while (!ul_sell.isEmpty() && !ul_buy.isEmpty()) {
|
||||
System.out.printf("Cannot match two unlimited orders!\n");
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
while (true) {
|
||||
|
||||
// Match unlimited sell orders against limited buy orders
|
||||
while (!ul_sell.isEmpty() && !bid.isEmpty()) {
|
||||
Order b = bid.first();
|
||||
Order a = ul_sell.first();
|
||||
double price = b.limit;
|
||||
double volume = b.volume >= a.volume ? a.volume : b.volume;
|
||||
// Match unlimited sell orders against unlimited buy orders
|
||||
while (!ul_sell.isEmpty() && !ul_buy.isEmpty()) {
|
||||
System.out.printf("Cannot match two unlimited orders!\n");
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Match unlimited sell orders against limited buy orders
|
||||
while (!ul_sell.isEmpty() && !bid.isEmpty()) {
|
||||
Order b = bid.first();
|
||||
Order a = ul_sell.first();
|
||||
double price = b.limit;
|
||||
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 a = ask.first();
|
||||
|
||||
@ -803,7 +813,6 @@ public class Exchange {
|
||||
double volume = b.volume >= a.volume ? a.volume : b.volume;
|
||||
|
||||
finishTrade(b, a, price, volume);
|
||||
|
||||
volume_total += volume;
|
||||
money_total += price * volume;
|
||||
|
||||
@ -812,7 +821,7 @@ public class Exchange {
|
||||
this.checkSLOrders(price);
|
||||
|
||||
}
|
||||
//System.out.print("Volume total is "+volume_total+"\n");
|
||||
|
||||
if (volume_total == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -91,9 +91,10 @@
|
||||
<Component class="javax.swing.JComboBox" name="typeComboBox">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="2">
|
||||
<StringItem index="0" value="Buy "/>
|
||||
<StringItem index="1" value="Sell"/>
|
||||
<StringArray count="3">
|
||||
<StringItem index="0" value="Buy Limit"/>
|
||||
<StringItem index="1" value="Sell Limit"/>
|
||||
<StringItem index="2" value="Sell"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
@ -53,8 +53,8 @@ public class CreateOrderDialog extends javax.swing.JDialog {
|
||||
public CreateOrderDialog(java.awt.Frame parent, boolean modal, Account account, OrderType type) {
|
||||
this(parent, modal);
|
||||
this.account = account;
|
||||
typeComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]{"Buy ", "Sell"}));
|
||||
typeList = new OrderType[]{OrderType.BUYLIMIT, OrderType.SELLLIMIT};
|
||||
typeComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]{"Buy Lim", "Sell Lim", "Sell"}));
|
||||
typeList = new OrderType[]{OrderType.BUYLIMIT, OrderType.SELLLIMIT, OrderType.SELL};
|
||||
for (int i = 0; i < typeList.length; i++) {
|
||||
if (typeList[i] == type) {
|
||||
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));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user