Work on manual trading

This commit is contained in:
7u83
2017-02-13 00:07:50 +01:00
parent 4090947001
commit 6039c95d6a
34 changed files with 699 additions and 316 deletions

View File

@ -27,19 +27,21 @@ package traders.ManTrader;
import gui.Globals;
import gui.OrdersList;
import javax.swing.JDialog;
import org.json.JSONObject;
import sesim.AutoTrader;
import sesim.AutoTraderBase;
import sesim.AutoTraderConfigBase;
import sesim.AutoTraderConfig;
import sesim.AutoTraderGui;
import sesim.Exchange;
import sesim.Exchange.AccountListener;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class ManTrader extends AutoTraderBase {
public class ManTrader extends AutoTraderBase implements AccountListener{
public ManTrader(Exchange se, long id, String name, double money, double shares, AutoTraderConfig config) {
// super(se, id, name, money, shares, null);
@ -47,9 +49,14 @@ public class ManTrader extends AutoTraderBase {
}
public ManTrader() {
super();
}
public void init(Exchange se, long id, String name, double money, double shares, JSONObject cfg){
super.init(se, id, name, money, shares, cfg);
getAccount().setListener(this);
}
ManTraderConsoleDialog consoleDialog;
@Override
@ -68,17 +75,13 @@ public class ManTrader extends AutoTraderBase {
@Override
public long timerTask() {
OrdersList ol = this.consoleDialog.getConsole().getOrderListPanel();
ol.updateModel();
return 1000;
}
/* @Override
public AutoTrader createTrader(Exchange se, JSONObject cfg, long id, String name, double money, double shares) {
return null;
}
*/
@Override
public String getDisplayName() {
@ -106,4 +109,17 @@ public class ManTrader extends AutoTraderBase {
return true;
}
@Override
public JDialog getGuiConsole() {
return this.consoleDialog;
}
@Override
public void accountUpdated(Exchange.Account a, Exchange.Order o) {
//this.consoleDialog.cons
System.out.printf("AccountListener called\n");
this.consoleDialog.getConsole().getOrderListPanel().updateModel();
}
}

View File

@ -1,79 +0,0 @@
/*
* Copyright (c) 2017, 7u83 <7u83@mail.ru>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package traders.ManTrader;
import org.json.JSONObject;
import sesim.AutoTrader;
import sesim.AutoTraderBase;
import sesim.AutoTraderConfigBase;
import sesim.AutoTraderGui;
import sesim.Exchange;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class ManTraderConfig extends AutoTraderBase{
@Override
public void start() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public long timerTask() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getDisplayName() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public AutoTraderGui getGui() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public JSONObject getConfig() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void putConfig(JSONObject cfg) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean getDevelStatus() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -19,7 +19,7 @@
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="ordersList1" max="32767" attributes="0"/>
<Component id="ordersList" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" alignment="0" attributes="0">
@ -56,7 +56,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="ordersList1" min="-2" pref="148" max="-2" attributes="0"/>
<Component id="ordersList" min="-2" pref="148" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
@ -141,7 +141,7 @@
<Property name="text" type="java.lang.String" value="jLabel4"/>
</Properties>
</Component>
<Component class="gui.OrdersList" name="ordersList1">
<Component class="gui.OrdersList" name="ordersList">
</Component>
<Component class="javax.swing.JButton" name="stopLossButton">
<Properties>

View File

@ -26,9 +26,7 @@
package traders.ManTrader;
import gui.OrdersList;
import javax.swing.JTable;
import sesim.AutoTrader;
import sesim.AutoTraderInterface;
import sesim.Exchange;
/**
@ -40,7 +38,8 @@ public class ManTraderConsole extends javax.swing.JPanel {
public ManTrader trader;
public OrdersList getOrderListPanel(){
return this.ordersList1;
return this.ordersList;
}
/**
@ -48,6 +47,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
*/
public ManTraderConsole() {
initComponents();
// this.ordersList1.account=trader.getAccount();
}
@ -68,7 +68,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
sellButton = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
moneyText = new javax.swing.JLabel();
ordersList1 = new gui.OrdersList();
ordersList = new gui.OrdersList();
stopLossButton = new javax.swing.JButton();
limitSpinner.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, null, 1.0d));
@ -111,7 +111,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(ordersList1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(ordersList, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
@ -139,7 +139,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(ordersList1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ordersList, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
@ -174,6 +174,9 @@ public class ManTraderConsole extends javax.swing.JPanel {
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(), Exchange.OrderType.BUYLIMIT, volume, limit);
System.out.printf("The retval is %d",createOrder);
this.ordersList.account=this.trader.getAccount();
this.ordersList.updateModel();
}//GEN-LAST:event_buyButtonActionPerformed
@ -205,7 +208,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
private javax.swing.JLabel jLabel3;
private javax.swing.JSpinner limitSpinner;
private javax.swing.JLabel moneyText;
private gui.OrdersList ordersList1;
private gui.OrdersList ordersList;
private javax.swing.JButton sellButton;
private javax.swing.JButton stopLossButton;
private javax.swing.JSpinner volumeSpinner;

View File

@ -34,7 +34,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="console" pref="280" max="32767" attributes="0"/>
<Component id="console" pref="328" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>

View File

@ -67,14 +67,14 @@ public class ManTraderConsoleDialog extends javax.swing.JDialog {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(console, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
.addComponent(console, javax.swing.GroupLayout.PREFERRED_SIZE, 383, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(console, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
.addComponent(console, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
.addContainerGap())
);

View File

@ -31,10 +31,11 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import javax.swing.JDialog;
import org.json.JSONArray;
import org.json.JSONObject;
//import sesim.AccountData;
import sesim.AutoTrader;
import sesim.AutoTraderBase;
import sesim.AutoTraderConfig;
import sesim.AutoTraderGui;
@ -178,6 +179,11 @@ public class RandomTraderA extends AutoTraderBase {
}
@Override
public JDialog getGuiConsole() {
return null;
}
protected enum Action {
BUY, SELL, RANDOM
}
@ -276,18 +282,21 @@ public class RandomTraderA extends AutoTraderBase {
// how much money we ant to invest?
double money = getRandomAmmount(ad.getMoney(), buy_volume);
money = se.roundMoney(money);
Quote q = se.getCurrentPrice();
double lp = q == null ? getStart() : q.price;
double limit;
limit = lp + getRandomAmmount(lp, buy_limit);
limit = se.roundMoney(limit);
double volume = money / limit;
volume = se.roundShares(volume);
// System.out.printf("Volume : %f", volume);
limit = se.roundMoney(limit);
volume = se.roundShares(volume);
if (volume <= 0 || money <= 0) {
return false;
}

View File

@ -25,16 +25,15 @@
*/
package traders;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;
import org.json.JSONArray;
import org.json.JSONObject;
import sesim.AutoTrader;
import sesim.AutoTraderConfigBase;
import sesim.AutoTraderConfig;
import sesim.AutoTraderGui;
import sesim.Exchange;
import sesim.OldAutoTrader;
/**
*
@ -53,7 +52,7 @@ public class RandomTraderConfig extends AutoTraderConfigBase implements AutoTrad
public Long[] wait_after_buy = {10L, 30L};
@Override
public AutoTrader createTrader(Exchange se, JSONObject cfg, long id, String name, double money, double shares) {
public OldAutoTrader createTrader(Exchange se, JSONObject cfg, long id, String name, double money, double shares) {
if (cfg != null) {
this.putConfig(cfg);
}

View File

@ -296,28 +296,28 @@
<Component class="javax.swing.JSpinner" name="waitAfterBuyMin">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1000" type="number"/>
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Long" stepSize="1000" type="number"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JSpinner" name="waitAfterSellMin">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1000" type="number"/>
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Long" stepSize="1000" type="number"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JSpinner" name="waitAfterSellMax">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1000" type="number"/>
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Long" stepSize="1000" type="number"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JSpinner" name="waitAfterBuyMax">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1000" type="number"/>
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Long" stepSize="1000" type="number"/>
</Property>
</Properties>
</Component>

View File

@ -46,29 +46,32 @@ public class RandomTraderGuiA extends AutoTraderGui {
JDialog d;
this.initialDelayMin.setValue(cfg.initial_delay[0]);
this.initialDelayMax.setValue(cfg.initial_delay[1]);
try {
this.initialDelayMin.setValue(cfg.initial_delay[0]);
this.initialDelayMax.setValue(cfg.initial_delay[1]);
this.buyVolMin.setValue(cfg.buy_volume[0]);
this.buyVolMax.setValue(cfg.buy_volume[1]);
this.sellVolMin.setValue(cfg.sell_volume[0]);
this.sellVolMax.setValue(cfg.sell_volume[1]);
this.buyLimitMin.setValue(cfg.buy_limit[0]);
this.buyLimitMax.setValue(cfg.buy_limit[1]);
this.sellLimitMin.setValue(cfg.sell_limit[0]);
this.sellLimitMax.setValue(cfg.sell_limit[1]);
this.buyVolMin.setValue(cfg.buy_volume[0]);
this.buyVolMax.setValue(cfg.buy_volume[1]);
this.sellVolMin.setValue(cfg.sell_volume[0]);
this.sellVolMax.setValue(cfg.sell_volume[1]);
this.buyLimitMin.setValue(cfg.buy_limit[0]);
this.buyLimitMax.setValue(cfg.buy_limit[1]);
this.sellLimitMin.setValue(cfg.sell_limit[0]);
this.sellLimitMax.setValue(cfg.sell_limit[1]);
this.buyWaitMin.setValue(cfg.buy_wait[0]);
this.buyWaitMax.setValue(cfg.buy_wait[1]);
this.sellWaitMin.setValue(cfg.sell_wait[0]);
this.sellWaitMax.setValue(cfg.sell_wait[1]);
this.buyWaitMin.setValue(cfg.buy_wait[0]);
this.buyWaitMax.setValue(cfg.buy_wait[1]);
this.sellWaitMin.setValue(cfg.sell_wait[0]);
this.sellWaitMax.setValue(cfg.sell_wait[1]);
this.waitAfterBuyMin.setValue(cfg.wait_after_buy[0]);
this.waitAfterBuyMax.setValue(cfg.wait_after_buy[1]);
this.waitAfterBuyMin.setValue(cfg.wait_after_buy[0]);
this.waitAfterBuyMax.setValue(cfg.wait_after_buy[1]);
this.waitAfterSellMin.setValue(cfg.wait_after_sell[0]);
this.waitAfterSellMax.setValue(cfg.wait_after_sell[1]);
this.waitAfterSellMin.setValue(cfg.wait_after_sell[0]);
this.waitAfterSellMax.setValue(cfg.wait_after_sell[1]);
} catch (Exception e) {
}
}
@Override
@ -179,13 +182,13 @@ public class RandomTraderGuiA extends AutoTraderGui {
sellLimitMin.setModel(new javax.swing.SpinnerNumberModel(0.0f, -100.0f, null, 1.0f));
waitAfterBuyMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1000));
waitAfterBuyMin.setModel(new javax.swing.SpinnerNumberModel(0L, 0L, null, 1000L));
waitAfterSellMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1000));
waitAfterSellMin.setModel(new javax.swing.SpinnerNumberModel(0L, 0L, null, 1000L));
waitAfterSellMax.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1000));
waitAfterSellMax.setModel(new javax.swing.SpinnerNumberModel(0L, 0L, null, 1000L));
waitAfterBuyMax.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1000));
waitAfterBuyMax.setModel(new javax.swing.SpinnerNumberModel(0L, 0L, null, 1000L));
buyVolMin.setModel(new javax.swing.SpinnerNumberModel(Float.valueOf(0.0f), Float.valueOf(0.0f), Float.valueOf(100.0f), Float.valueOf(1.0f)));