package se.koc.trader.daemon;

import se.koc.trader.TraderContext;
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;

import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * This manager will pull updates from all configured exchanges.
 */
public class TraderMarketUpdateManager implements Runnable {
    private static final Logger logger = LogUtil.getLogger();

    private static final int MARKET_UPDATE_INTERVAL = 60 * 1000; // in milliseconds


    public void initialize(ScheduledExecutorService scheduler) {
        scheduler.scheduleAtFixedRate(this, 10_000, MARKET_UPDATE_INTERVAL, TimeUnit.MILLISECONDS);
    }

    @Override
    public void run() {
        try {
            DBConnection db = TraderContext.getDB();
            List<Symbol> symbols = Symbol.getSymbols(db);

            for (Symbol symbol : symbols) {
                ExchangeConfig exchange = symbol.getExchangeConfig();
                ExchangeMarket market = exchange.getExchangeMarket();


            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Trader market updated thread has crashed during update.", e);
        }
    }
}
