All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.fair_acc.sample.financial.dos.OrderContainer Maven / Gradle / Ivy

Go to download

Small sample applications to showcase the features of the chart-fx library.

The newest version!
package io.fair_acc.sample.financial.dos;

import java.util.*;

/**
 * @author afischer
 */
public class OrderContainer {
    private final Map orders = new LinkedHashMap<>();
    private final HashSet openedOrders = new LinkedHashSet<>();

    public void addOrder(Order order) {
        openedOrders.add(order);
        orders.put(order.getInternalOrderId(), order);
    }

    public Order removeOrder(Order order) {
        openedOrders.remove(order);
        return orders.remove(order.getInternalOrderId());
    }

    public boolean removeOpenedOrder(Order order) {
        return openedOrders.remove(order);
    }

    public Collection getOrders() {
        return orders.values();
    }

    @SuppressWarnings("unchecked")
    public Collection getOpenedOrders() {
        return (LinkedHashSet) openedOrders.clone();
    }

    public Set getOpenedAndFilledOrders() {
        Set openOrders = new LinkedHashSet<>();
        for (Order order : getOrders()) {
            if (Order.OrderStatus.OPENED == order.getStatus() || Order.OrderStatus.FILLED == order.getStatus()) {
                openOrders.add(order);
            }
        }
        return openOrders;
    }

    public Set getOpenedAndFilledOrdersByMarket(String symbol) {
        Set marketOrders = new LinkedHashSet<>();
        if (symbol != null) {
            for (Order order : getOpenedAndFilledOrders()) {
                if (order.getSymbol().equals(symbol)) {
                    marketOrders.add(order);
                }
            }
        }
        return marketOrders;
    }

    public Order getOrderById(int internalOrderId) {
        return orders.get(internalOrderId);
    }

    public void clear() {
        orders.clear();
    }

    public boolean contains(Order order) {
        return orders.containsKey(order.getInternalOrderId());
    }

    @Override
    public String toString() {
        return "OrderContainer [orders=" + orders + "]";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy