Some progress on symbol config page
This commit is contained in:
parent
245a599b52
commit
0556882f4e
5 changed files with 52 additions and 29 deletions
|
|
@ -7,7 +7,13 @@ import java.util.List;
|
||||||
public interface ExchangeMarket {
|
public interface ExchangeMarket {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a List of all symbols supported by this exchange, symbols are defined by "{baseAsset}/{quoteAsset}"
|
* @return a List of all symbol names that are supported by this exchange, symbols are defined by "{baseAsset}/{quoteAsset}"
|
||||||
*/
|
*/
|
||||||
List<Symbol> getSymbols();
|
List<String> getSymbols();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name one of the names provided by the {@link #getSymbol(String)} method.
|
||||||
|
* @return new Symbol instance representing the given symbol name on the exchange.
|
||||||
|
*/
|
||||||
|
Symbol getSymbol(String name);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ public class ExchangeEndpoint implements WSInterface {
|
||||||
|
|
||||||
Exchange exchange = Exchange.getExchange(db, exchangeId);
|
Exchange exchange = Exchange.getExchange(db, exchangeId);
|
||||||
DataNode symbols = root.set("symbols", DataNode.DataType.List);
|
DataNode symbols = root.set("symbols", DataNode.DataType.List);
|
||||||
for (Symbol symbol : exchange.getObject().getExchangeMarket().getSymbols()) {
|
for (String symbolName : exchange.getObject().getExchangeMarket().getSymbols()) {
|
||||||
symbols.add(symbol.getName());
|
symbols.add(symbolName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,18 @@ package se.koc.trader.exchange.binance;
|
||||||
import se.koc.trader.api.ExchangeMarket;
|
import se.koc.trader.api.ExchangeMarket;
|
||||||
import se.koc.trader.struct.Symbol;
|
import se.koc.trader.struct.Symbol;
|
||||||
import zutil.net.ws.rest.RESTClientFactory;
|
import zutil.net.ws.rest.RESTClientFactory;
|
||||||
|
import zutil.parser.DataNode;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BinanceMarket implements ExchangeMarket {
|
public class BinanceMarket implements ExchangeMarket {
|
||||||
|
|
||||||
private BinanceRestAPI rest;
|
private transient BinanceRestAPI rest;
|
||||||
|
|
||||||
|
private transient List<String> symbolsCache;
|
||||||
|
|
||||||
|
|
||||||
public BinanceMarket() {
|
public BinanceMarket() {
|
||||||
|
|
@ -27,10 +31,20 @@ public class BinanceMarket implements ExchangeMarket {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Symbol> getSymbols() {
|
public List<String> getSymbols() {
|
||||||
return null; // /api/v3/ticker/price
|
if (symbolsCache == null) {
|
||||||
|
symbolsCache = new ArrayList<>();
|
||||||
|
DataNode symbols = rest.getExchangeInfo().get("symbols");
|
||||||
|
|
||||||
|
for (DataNode symbol : symbols) {
|
||||||
|
symbolsCache.add(symbol.getString("symbol"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return symbolsCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Symbol getSymbol(String symbol) {
|
public Symbol getSymbol(String symbol) {
|
||||||
return null; // /api/v3/ticker/price?symbol=xxx
|
return null; // /api/v3/ticker/price?symbol=xxx
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import zutil.io.file.FileUtil;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
import zutil.parser.Templator;
|
import zutil.parser.Templator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
@ -37,7 +38,9 @@ public class SymbolConfigPage extends TraderPage {
|
||||||
|
|
||||||
// Save new input
|
// Save new input
|
||||||
if (request.containsKey("action")) {
|
if (request.containsKey("action")) {
|
||||||
|
int exchangeId = (ObjectUtil.isEmpty(request.get("exchange-id")) ? -1 : Integer.parseInt(request.get("exchange-id")));
|
||||||
int id = (ObjectUtil.isEmpty(request.get("id")) ? -1 : Integer.parseInt(request.get("id")));
|
int id = (ObjectUtil.isEmpty(request.get("id")) ? -1 : Integer.parseInt(request.get("id")));
|
||||||
|
Exchange exchange = Exchange.getExchange(db, exchangeId);
|
||||||
Symbol symbol = null;
|
Symbol symbol = null;
|
||||||
|
|
||||||
if (id >= 0)
|
if (id >= 0)
|
||||||
|
|
@ -46,22 +49,11 @@ public class SymbolConfigPage extends TraderPage {
|
||||||
switch(request.get("action")) {
|
switch(request.get("action")) {
|
||||||
case "create_symbol":
|
case "create_symbol":
|
||||||
logger.info("Creating symbol: " + request.get("name"));
|
logger.info("Creating symbol: " + request.get("name"));
|
||||||
symbol = new Symbol();
|
symbol = exchange.getObject().getExchangeMarket().getSymbol(request.get("symbol-name"));
|
||||||
/* FALLTHROUGH */
|
symbol.save(db);
|
||||||
case "modify_symbol":
|
|
||||||
if (symbol != null) {
|
|
||||||
logger.info("Modifying sensor: " + symbol.getName());
|
|
||||||
symbol.setName(request.get("name"));
|
|
||||||
symbol.save(db);
|
|
||||||
|
|
||||||
TraderContext.getMessageManager().add(new UserMessage(
|
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(
|
|
||||||
MessageLevel.ERROR, "Unknown sensor id: " + id, MessageTTL.ONE_VIEW));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "remove_symbol":
|
case "remove_symbol":
|
||||||
if (symbol != null) {
|
if (symbol != null) {
|
||||||
|
|
@ -81,11 +73,10 @@ public class SymbolConfigPage extends TraderPage {
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
|
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
|
||||||
tmpl.set("exchanges", Exchange.getExchanges(db));
|
|
||||||
tmpl.set("symbols", Symbol.getSymbols(db));
|
tmpl.set("symbols", Symbol.getSymbols(db));
|
||||||
|
tmpl.set("exchanges", Exchange.getExchanges(db));
|
||||||
|
|
||||||
return tmpl;
|
return tmpl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,23 @@
|
||||||
|
|
||||||
<!------------- MODALS --------------->
|
<!------------- MODALS --------------->
|
||||||
<script>
|
<script>
|
||||||
|
var exchangeSymbols = {
|
||||||
|
{{#exchanges}}
|
||||||
|
{{.getId()}}: [
|
||||||
|
{{#.getObject().getExchangeMarket().getSymbols()}}"{{.}}",{{/.getObject().getExchangeMarket().getSymbols()}}
|
||||||
|
],
|
||||||
|
{{/exchanges}}
|
||||||
|
};
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
initDynamicModalForm("symbolModal");
|
initDynamicModalForm("symbolModal");
|
||||||
|
|
||||||
$("#exchange").change(function() {
|
$("#exchange").change(function() {
|
||||||
alert(this.value);
|
var options = $("#symbol-name");
|
||||||
|
options.empty();
|
||||||
|
$.each(exchangeSymbols[this.value], function(index, value) {
|
||||||
|
options.append($("<option />").val(value).text(value));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -85,8 +97,8 @@
|
||||||
<input type="hidden" id="id" name="id">
|
<input type="hidden" id="id" name="id">
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="control-label" for="exchange">Exchange:</label>
|
<label class="control-label" for="exchange-id">Exchange:</label>
|
||||||
<select id="exchange" name="exchange" class="form-control">
|
<select id="exchange-id" name="exchange-id" class="form-control">
|
||||||
<option></option>
|
<option></option>
|
||||||
{{#exchanges}}
|
{{#exchanges}}
|
||||||
<option value="{{.getId()}}">{{.getName()}}</option>
|
<option value="{{.getId()}}">{{.getName()}}</option>
|
||||||
|
|
@ -95,8 +107,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="control-label" for="symbol">Symbol:</label>
|
<label class="control-label" for="symbol-name">Symbol:</label>
|
||||||
<select id="symbol" name="symbol" class="form-control">
|
<select id="symbol-name" name="symbol-name" class="form-control">
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue