Working on Exchange config
This commit is contained in:
parent
b7e35731c8
commit
4db1f866f3
16 changed files with 226 additions and 28 deletions
|
|
@ -1,4 +1,4 @@
|
|||
package se.koc.trader.exchange;
|
||||
package se.koc.trader.api;
|
||||
|
||||
import zutil.db.bean.DBBean;
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ public abstract class ExchangeConfig extends DBBean {
|
|||
|
||||
public abstract ExchangeMarket getExchangeMarket();
|
||||
|
||||
public abstract ExchangeOrder getExchangeOrder();
|
||||
public abstract ExchangeWallet getExchangeOrder();
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Common logic
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package se.koc.trader.exchange;
|
||||
package se.koc.trader.api;
|
||||
|
||||
import se.koc.trader.struct.Symbol;
|
||||
|
||||
4
src/main/java/se/koc/trader/api/ExchangeWallet.java
Normal file
4
src/main/java/se/koc/trader/api/ExchangeWallet.java
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
package se.koc.trader.api;
|
||||
|
||||
public interface ExchangeWallet {
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package se.koc.trader.daemon;
|
||||
|
||||
import se.koc.trader.TraderContext;
|
||||
import se.koc.trader.exchange.ExchangeConfig;
|
||||
import se.koc.trader.exchange.ExchangeMarket;
|
||||
import se.koc.trader.api.ExchangeConfig;
|
||||
import se.koc.trader.api.ExchangeMarket;
|
||||
import se.koc.trader.struct.Symbol;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.log.LogUtil;
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
package se.koc.trader.exchange;
|
||||
|
||||
public interface ExchangeOrder {
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package se.koc.trader.exchange.binance;
|
||||
|
||||
import se.koc.trader.exchange.ExchangeConfig;
|
||||
import se.koc.trader.exchange.ExchangeMarket;
|
||||
import se.koc.trader.exchange.ExchangeOrder;
|
||||
import se.koc.trader.api.ExchangeConfig;
|
||||
import se.koc.trader.api.ExchangeMarket;
|
||||
import se.koc.trader.api.ExchangeWallet;
|
||||
|
||||
public class BinanceExchange extends ExchangeConfig {
|
||||
private BinanceMarket market;
|
||||
|
|
@ -15,7 +15,7 @@ public class BinanceExchange extends ExchangeConfig {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ExchangeOrder getExchangeOrder() {
|
||||
public ExchangeWallet getExchangeOrder() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package se.koc.trader.exchange.binance;
|
||||
|
||||
import se.koc.trader.exchange.ExchangeMarket;
|
||||
import se.koc.trader.api.ExchangeMarket;
|
||||
import se.koc.trader.struct.Symbol;
|
||||
import zutil.net.ws.rest.RESTClientFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@
|
|||
"name": "Exchange-Binance",
|
||||
"description": "Plugin contains core Binance connectivity.",
|
||||
"interfaces": [
|
||||
{"se.koc.trader.exchange.ExchangeConfig": "se.koc.trader.exchange.binance.BinanceExchange"}
|
||||
{"se.koc.trader.api.ExchangeConfig": "se.koc.trader.exchange.binance.BinanceExchange"}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package se.koc.trader.page;
|
|||
|
||||
import se.koc.trader.TraderContext;
|
||||
import se.koc.trader.api.TraderPage;
|
||||
import se.koc.trader.struct.Exchange;
|
||||
import se.koc.trader.struct.Symbol;
|
||||
import zutil.ObjectUtil;
|
||||
import zutil.db.DBConnection;
|
||||
|
|
@ -34,6 +35,50 @@ public class ExchangeConfigPage extends TraderPage {
|
|||
|
||||
DBConnection db = TraderContext.getDB();
|
||||
|
||||
if (request.containsKey("action")) {
|
||||
int id = (ObjectUtil.isEmpty(request.get("id")) ? -1 : Integer.parseInt(request.get("id")));
|
||||
Exchange exchange = null;
|
||||
|
||||
if (id >= 0)
|
||||
exchange = Exchange.getExchange(db, id);
|
||||
|
||||
switch(request.get("action")) {
|
||||
case "create_exchange":
|
||||
logger.info("Creating symbol: " + request.get("name"));
|
||||
exchange = new Exchange();
|
||||
/* FALLTHROUGH */
|
||||
case "modify_exchange":
|
||||
if (exchange != null) {
|
||||
logger.info("Modifying exchange: " + exchange.getName());
|
||||
exchange.setName(request.get("name"));
|
||||
exchange.getObjectConfigurator().setValues(request).applyConfiguration();
|
||||
exchange.save(db);
|
||||
|
||||
TraderContext.getMessageManager().add(new UserMessage(
|
||||
MessageLevel.SUCCESS, "Successfully saved exchange: " + exchange.getName(), MessageTTL.ONE_VIEW));
|
||||
} else {
|
||||
logger.warning("Unknown exchange id: " + id);
|
||||
TraderContext.getMessageManager().add(new UserMessage(
|
||||
MessageLevel.ERROR, "Unknown exchange id: " + id, MessageTTL.ONE_VIEW));
|
||||
}
|
||||
break;
|
||||
|
||||
case "remove_exchange":
|
||||
if (exchange != null) {
|
||||
logger.warning("Removing exchange: " + exchange.getName());
|
||||
exchange.delete(db);
|
||||
|
||||
TraderContext.getMessageManager().add(new UserMessage(
|
||||
MessageLevel.SUCCESS, "Successfully removed exchange: " + exchange.getName(), MessageTTL.ONE_VIEW));
|
||||
} else {
|
||||
logger.warning("Unknown exchange id: " + id);
|
||||
TraderContext.getMessageManager().add(new UserMessage(
|
||||
MessageLevel.ERROR, "Unknown exchange id: " + id, MessageTTL.ONE_VIEW));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Output
|
||||
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
|
||||
tmpl.set("exchanges", Symbol.getSymbols(db));
|
||||
|
|
|
|||
|
|
@ -43,11 +43,10 @@ public class SymbolConfigPage extends TraderPage {
|
|||
symbol = Symbol.getSymbol(db, id);
|
||||
|
||||
switch(request.get("action")) {
|
||||
// Local Sensors
|
||||
case "create_symbol":
|
||||
logger.info("Creating symbol: " + request.get("name"));
|
||||
symbol = new Symbol();
|
||||
|
||||
/* FALLTHROUGH */
|
||||
case "modify_symbol":
|
||||
if (symbol != null) {
|
||||
logger.info("Modifying sensor: " + symbol.getName());
|
||||
|
|
@ -55,7 +54,7 @@ public class SymbolConfigPage extends TraderPage {
|
|||
symbol.save(db);
|
||||
|
||||
TraderContext.getMessageManager().add(new UserMessage(
|
||||
MessageLevel.SUCCESS, "Successfully saved symbol: "+symbol.getName(), MessageTTL.ONE_VIEW));
|
||||
MessageLevel.SUCCESS, "Successfully saved symbol: " + symbol.getName(), MessageTTL.ONE_VIEW));
|
||||
} else {
|
||||
logger.warning("Unknown sensor id: " + id);
|
||||
TraderContext.getMessageManager().add(new UserMessage(
|
||||
|
|
|
|||
36
src/main/java/se/koc/trader/struct/Exchange.java
Normal file
36
src/main/java/se/koc/trader/struct/Exchange.java
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package se.koc.trader.struct;
|
||||
|
||||
import se.koc.trader.api.ExchangeConfig;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.db.bean.DBBean;
|
||||
import zutil.db.bean.DBBeanObjectDSO;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Object representing a single exchange endpoint.
|
||||
*/
|
||||
@DBBean.DBTable(value = "exchange", superBean = true)
|
||||
public class Exchange extends DBBeanObjectDSO<ExchangeConfig> {
|
||||
|
||||
private String name;
|
||||
|
||||
|
||||
public static Exchange getExchange(DBConnection db, long id) throws SQLException {
|
||||
return DBBean.load(db, Exchange.class, id);
|
||||
}
|
||||
|
||||
|
||||
public Exchange() { }
|
||||
public Exchange(ExchangeConfig exchangeConfig) {
|
||||
this.setObject(exchangeConfig);
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
package se.koc.trader.struct;
|
||||
|
||||
import se.koc.trader.exchange.ExchangeConfig;
|
||||
import se.koc.trader.api.ExchangeConfig;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.db.bean.DBBean;
|
||||
import zutil.db.bean.DBBeanObjectDSO;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
|
|
|||
Binary file not shown.
98
src/main/resources/web/exchange_config.tmpl
Normal file
98
src/main/resources/web/exchange_config.tmpl
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<div class="col-md-12 d-flex">
|
||||
|
||||
<div class="card flex-fill w-100">
|
||||
<div class="card-header">
|
||||
<div class="card-actions float-end">
|
||||
<div class="btn-group float-end" role="group">
|
||||
<button type="button" class="btn btn-success"
|
||||
data-toggle="modal" data-target="#exchangeModal" data-action="create_exchange">
|
||||
<i class="bi bi-plus-square"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<h5 class="card-title mb-0">Exchange Instances</h5>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Configuration</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#exchanges}}
|
||||
<tr>
|
||||
<td>{{.getName()}}</td>
|
||||
<td>{{.getClass().getSimpleName()}}</td>
|
||||
<td>{{.getDeviceConfig()}}</td>
|
||||
<td>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="id" value="{{.getId()}}">
|
||||
|
||||
<div class="btn-toolbar pull-right">
|
||||
<button type="button" class="btn btn-default btn-xs" data-toggle="modal"
|
||||
data-target="#exchangeModal"
|
||||
data-action="modify_exchange"
|
||||
data-id="{{.getId()}}"
|
||||
data-name="{{.getName()}}"
|
||||
data-type="{{.getType()}}"
|
||||
{{#.getDeviceConfigurator().getConfiguration()}}
|
||||
data-{{.getName()}}="{{.getString()}}"
|
||||
{{/.getDeviceConfigurator().getConfiguration()}}
|
||||
>
|
||||
<span class="glyphicon glyphicon-pencil"></span>
|
||||
</button>
|
||||
|
||||
<button type="submit" class="btn btn-danger btn-xs" name="action" value="remove_exchange">
|
||||
<span class="glyphicon glyphicon-trash"></span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{{/exchanges}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!------------- MODALS --------------->
|
||||
<script>
|
||||
$(function(){
|
||||
initDynamicModalForm("exchangeModal");
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="modal fade" id="exchangeModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><span>×</span></button>
|
||||
<h4 class="modal-title">Exchange</h4>
|
||||
</div>
|
||||
<form method="POST">
|
||||
<div class="modal-body">
|
||||
<input type="hidden" id="action" name="action">
|
||||
<input type="hidden" id="id" name="id">
|
||||
<div class="form-group">
|
||||
<label class="control-label">Name:</label>
|
||||
<input type="text" class="form-control" name="name">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="reset" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -1,12 +1,27 @@
|
|||
<h1 class="page-header">Symbol Configuration</h1>
|
||||
<div class="col-md-12 d-flex">
|
||||
<div class="card flex-fill w-100">
|
||||
<div class="card-header">
|
||||
<div class="card-actions float-end">
|
||||
<div class="dropdown show">
|
||||
<a href="#" data-bs-toggle="dropdown" data-bs-display="static">
|
||||
<i class="align-middle" data-feather="more-horizontal"></i>
|
||||
</a>
|
||||
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default drop-shadow">
|
||||
<div class="panel-heading"></div>
|
||||
<div class="panel-body">
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<a class="dropdown-item" href="#">Action</a>
|
||||
<a class="dropdown-item" href="#">Another action</a>
|
||||
<a class="dropdown-item" href="#">Something else here</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h5 class="card-title mb-0">Recent Movement</h5>
|
||||
</div>
|
||||
|
||||
<table class="table table-hover table-condensed">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Configuration</th>
|
||||
|
|
@ -17,7 +32,9 @@
|
|||
<span class="glyphicon glyphicon-plus"></span>
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#symbols}}
|
||||
<tr>
|
||||
<td>{{.getName()}}</td>
|
||||
|
|
@ -37,8 +54,8 @@
|
|||
{{#.getDeviceConfigurator().getConfiguration()}}
|
||||
data-{{.getName()}}="{{.getString()}}"
|
||||
{{/.getDeviceConfigurator().getConfiguration()}}
|
||||
>
|
||||
<span class="glyphicon glyphicon-pencil"></span>
|
||||
>
|
||||
<span class="glyphicon glyphicon-pencil"></span>
|
||||
</button>
|
||||
|
||||
<button type="submit" class="btn btn-danger btn-xs" name="action" value="remove_symbol">
|
||||
|
|
@ -49,11 +66,12 @@
|
|||
</td>
|
||||
</tr>
|
||||
{{/symbols}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!------------- MODALS --------------->
|
||||
<script>
|
||||
|
|
|
|||
|
|
@ -43,4 +43,5 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue