package se.koc.trader.endpoint;

import se.koc.trader.TraderContext;
import se.koc.trader.struct.Exchange;
import se.koc.trader.struct.Symbol;
import zutil.db.DBConnection;
import zutil.net.ws.WSInterface;
import zutil.parser.DataNode;

import java.sql.SQLException;


public class ExchangeEndpoint implements WSInterface {
    public static final String API_PATH = "/api/exchange";


    @WSPath(API_PATH + "/symbols")
    public DataNode getAllSymbols(int exchangeId) throws SQLException {
        DBConnection db = TraderContext.getDB();
        DataNode root = new DataNode(DataNode.DataType.Map);

        Exchange exchange = Exchange.getExchange(db, exchangeId);
        DataNode symbols = root.set("symbols", DataNode.DataType.List);
        for (String symbolName : exchange.getObject().getExchangeMarket().getSymbols()) {
            symbols.add(symbolName);
        }

        return root;
    }
}
