private static void loadPositionsFromCSV()

in src/main/java/deltix/ember/sample/PositionLoadFromCSV.java [62:108]


    private static void loadPositionsFromCSV(File limitFile, List<MutablePositionSnapshot> result) throws IOException {
        CSVXReader csv = new CSVXReader(limitFile, ',');

        csv.readHeaders();
        List<ProjectionKey> projectionKeys = parseHeader(csv.getHeaders());

        MutablePositionSnapshot request = null;
        AsciiStringBuilder projectionPath = new AsciiStringBuilder();
        while (csv.nextLine()) {
            if (csv.getLine().trim().isEmpty())
                continue;
            int cellIndex = 0;


            // Position projection path (e.g. "Source[FIXTRADER1]/Account[GOLD]"). Empty for root level.
            projectionPath.clear();
            while (cellIndex < projectionKeys.size()) {
                if (cellIndex > 0)
                    projectionPath.append('/');
                projectionPath.append(projectionKeys.get(cellIndex));
                projectionPath.append('[');
                projectionPath.append(csv.getString(cellIndex).trim());
                projectionPath.append(']');

                cellIndex++;
            }

            request = new MutablePositionSnapshot();
            request.setSourceId(CLIENT_SOURCE_ID);
            request.setTimestamp(System.currentTimeMillis());
            request.setRelative(false);
            request.setProjectionPath(projectionPath.toString()); // clone it

            //TODO: read averageCost and realizedPnL ?

            String size = csv.getString(cellIndex).trim();
            request.setSize(Decimal64Utils.parse(size));

            result.add(request);

        }

        if (request != null)
            request.setLast(true);

        csv.close();
    }