Search in sources :

Example 1 with TradeListNym

use of org.opentransactions.otapi.TradeListNym in project otapij by FellowTraveler.

the class Helpers method getNYMTrades.

public static TradeListNym getNYMTrades(String serverID, String nymID) {
    TradeListNym tradeListNym = null;
    Storable storable = null;
    if (otapi.Exists("nyms", "trades", serverID, nymID)) {
        storable = otapi.QueryObject(StoredObjectType.STORED_OBJ_TRADE_LIST_NYM, "nyms", "trades", serverID, nymID);
        if (storable == null) {
            return null;
        }
        tradeListNym = TradeListNym.ot_dynamic_cast(storable);
    } else {
        storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_TRADE_LIST_NYM);
        if (storable == null) {
            return null;
        }
        tradeListNym = TradeListNym.ot_dynamic_cast(storable);
    }
    return tradeListNym;
}
Also used : TradeListNym(org.opentransactions.otapi.TradeListNym) Storable(org.opentransactions.otapi.Storable)

Example 2 with TradeListNym

use of org.opentransactions.otapi.TradeListNym in project otapij by FellowTraveler.

the class Market method getNymTrades.

public static Map getNymTrades(String serverID, String nymID) {
    Map tradeNymData = new HashMap();
    TradeListNym tradeListNym = Helpers.getNYMTrades(serverID, nymID);
    if (tradeListNym == null) {
        System.out.println("getNymTrades - tradeListNym returns null");
        return null;
    }
    for (int j = 0; j < tradeListNym.GetTradeDataNymCount(); j++) {
        TradeDataNym tradeDataNym = tradeListNym.GetTradeDataNym(j);
        if (tradeDataNym == null) {
            continue;
        }
        String[] tradeDataRow = new String[5];
        tradeDataRow[0] = !Utility.VerifyStringVal(tradeDataNym.getTransaction_id()) ? "" : tradeDataNym.getTransaction_id();
        tradeDataRow[1] = !Utility.VerifyStringVal(tradeDataNym.getPrice()) ? "" : tradeDataNym.getPrice();
        tradeDataRow[2] = !Utility.VerifyStringVal(tradeDataNym.getAmount_sold()) ? "" : tradeDataNym.getAmount_sold();
        tradeDataRow[3] = !Utility.VerifyStringVal(tradeDataNym.getCompleted_count()) ? "" : tradeDataNym.getCompleted_count();
        tradeDataRow[4] = !Utility.VerifyStringVal(tradeDataNym.getDate()) ? "" : tradeDataNym.getDate();
        if (!tradeDataRow[4].equals("")) {
            try {
                tradeDataRow[4] = String.valueOf(new Date(Long.parseLong(tradeDataRow[4]) * 1000));
            } catch (NumberFormatException nfe) {
                nfe.printStackTrace();
                System.out.println("Invalid number returned by timestmp:" + tradeDataRow[4]);
                tradeDataRow[4] = "";
            }
        }
        tradeNymData.put(tradeDataNym.getTransaction_id(), tradeDataRow);
    }
    return tradeNymData;
}
Also used : TradeDataNym(org.opentransactions.otapi.TradeDataNym) HashMap(java.util.HashMap) TradeListNym(org.opentransactions.otapi.TradeListNym) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date)

Aggregations

TradeListNym (org.opentransactions.otapi.TradeListNym)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Storable (org.opentransactions.otapi.Storable)1 TradeDataNym (org.opentransactions.otapi.TradeDataNym)1