Search in sources :

Example 11 with OTAPI_Func

use of com.moneychanger.core.util.OTAPI_Func in project otapij by FellowTraveler.

the class CashPurseAccount method exchangeCashPurse.

public boolean exchangeCashPurse(String serverID, String assetID, String nymID, String oldPurse, ArrayList selectedTokens) throws InterruptedException {
    Helpers.setObj(null);
    System.out.println(" Cash Purse exchange starts, selectedTokens:" + selectedTokens);
    String newPurse = processCashPurse(serverID, assetID, nymID, oldPurse, selectedTokens, nymID);
    if (!Utility.VerifyStringVal(newPurse)) {
        System.out.println("exchangeCashPurse: Before server OT_API_exchangePurse call, new Purse is empty.. returning false ");
        return false;
    }
    // ------------------------
    OTAPI_Func theRequest = new OTAPI_Func(OTAPI_Func.FT.EXCHANGE_CASH, serverID, nymID, assetID, newPurse);
    // <========================
    String strResponse = OTAPI_Func.SendTransaction(theRequest, "EXCHANGE_CASH");
    if (!Utility.VerifyStringVal(strResponse)) {
        System.out.println("IN exchangeCashPurse: OTAPI_Func.SendTransaction(() failed. (I give up.) ");
        // -------------------
        boolean importStatus = otapiJNI.OTAPI_Basic_Wallet_ImportPurse(serverID, assetID, nymID, newPurse);
        System.out.println("Since failure in exchangeCashPurse, OT_API_Wallet_ImportPurse called, status of import:" + importStatus);
        if (!importStatus) {
            Helpers.setObj(newPurse);
        }
        return false;
    }
    // ---------------------------------------        
    System.out.println("exchangeCashPurse ends, status: success.");
    return true;
}
Also used : OTAPI_Func(com.moneychanger.core.util.OTAPI_Func)

Example 12 with OTAPI_Func

use of com.moneychanger.core.util.OTAPI_Func in project otapij by FellowTraveler.

the class CashPurseAccount method depositCashPurse.

public boolean depositCashPurse(String serverID, String assetID, String nymID, String oldPurse, ArrayList selectedTokens, String accountID) {
    Helpers.setObj(null);
    System.out.println("depositCashPurse starts, selectedTokens:" + selectedTokens);
    String recepientNymID = otapiJNI.OTAPI_Basic_GetAccountWallet_NymID(accountID);
    String newPurse = processCashPurse(serverID, assetID, nymID, oldPurse, selectedTokens, recepientNymID);
    if (!Utility.VerifyStringVal(newPurse)) {
        System.out.println("Before server OT_API_exchangePurse call, new Purse is emtpty.. returning false ");
        return false;
    }
    // ----------------------------------------
    OTAPI_Func theRequest = new OTAPI_Func(OTAPI_Func.FT.DEPOSIT_CASH, serverID, recepientNymID, accountID, newPurse);
    // <========================
    String strResponse = OTAPI_Func.SendTransaction(theRequest, "DEPOSIT_CASH");
    if (!Utility.VerifyStringVal(strResponse)) {
        System.out.println("IN depositCashPurse: OTAPI_Func.SendTransaction(() failed. (I give up.) ");
        // -------------------
        boolean importStatus = otapiJNI.OTAPI_Basic_Wallet_ImportPurse(serverID, assetID, recepientNymID, newPurse);
        System.out.println("Since failure in depositCashPurse, OT_API_Wallet_ImportPurse called, status of import:" + importStatus);
        if (!importStatus) {
            Helpers.setObj(newPurse);
        }
        return false;
    }
    // ---------------------------------------        
    System.out.println("depositCashPurse ends, status: success.");
    return true;
}
Also used : OTAPI_Func(com.moneychanger.core.util.OTAPI_Func)

Example 13 with OTAPI_Func

use of com.moneychanger.core.util.OTAPI_Func in project otapij by FellowTraveler.

the class Market method loadMarketList.

public static Map loadMarketList(String serverID, String nymID) throws InterruptedException {
    //DEBUGGING 3rd step of debugging.
    Map marketListMap = new HashMap();
    // ----------------------------------------------------------
    OTAPI_Func theRequest = new OTAPI_Func(OTAPI_Func.FT.GET_MARKET_LIST, serverID, nymID);
    String strResponse = OTAPI_Func.SendRequest(theRequest, "GET_MARKET_LIST");
    if (!Utility.VerifyStringVal(strResponse)) {
        System.out.println("IN loadMarketList: OTAPI_Func.SendRequest(() failed. (I give up.) ");
        return null;
    }
    if (otapiJNI.OTAPI_Basic_Message_GetDepth(strResponse) == 0) {
        System.out.println("loadMarketList - marketList returns with a OT_API_Message_GetDepth() of 0 elements.");
        return marketListMap;
    }
    MarketList marketList = Helpers.getMarketList(serverID);
    if (marketList == null) {
        System.out.println("loadMarketList - marketList returns null");
        return null;
    }
    int count = (int) marketList.GetMarketDataCount();
    if (0 >= count) {
        System.out.println("loadMarketList - marketList returns with a size of 0 elements.");
        return null;
    }
    for (int i = 0; i < count; i++) {
        MarketData marketData = marketList.GetMarketData(i);
        if (marketData == null) {
            continue;
        }
        if ("ALL".equalsIgnoreCase(serverID) || serverID.equals(marketData.getServer_id())) {
            String[] data = new String[2];
            if (Utility.VerifyStringVal(marketData.getAsset_type_id()) && Utility.VerifyStringVal(marketData.getCurrency_type_id())) {
                String assetName = otapiJNI.OTAPI_Basic_GetAssetType_Name(marketData.getAsset_type_id());
                String currencyName = otapiJNI.OTAPI_Basic_GetAssetType_Name(marketData.getCurrency_type_id());
                if (Utility.VerifyStringVal(assetName) && Utility.VerifyStringVal(currencyName)) {
                    data[0] = assetName + "-" + currencyName;
                }
            } else {
                data[0] = !Utility.VerifyStringVal(marketData.getMarket_id()) ? "" : marketData.getMarket_id();
            }
            //data[0] = !Utility.VerifyStringVal(marketData.getGui_label()) ? "" : marketData.getGui_label();
            data[1] = !Utility.VerifyStringVal(marketData.getMarket_id()) ? "" : marketData.getMarket_id();
            marketListMap.put(data[1], data);
        }
    }
    return marketListMap;
}
Also used : MarketData(org.opentransactions.otapi.MarketData) HashMap(java.util.HashMap) OTAPI_Func(com.moneychanger.core.util.OTAPI_Func) MarketList(org.opentransactions.otapi.MarketList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with OTAPI_Func

use of com.moneychanger.core.util.OTAPI_Func in project otapij by FellowTraveler.

the class Market method getTicker.

public static MarketTicker getTicker(String marketID, String serverID, String nymID) {
    // ----------------------------------------------------------
    OTAPI_Func theRequest = new OTAPI_Func(OTAPI_Func.FT.GET_MARKET_LIST, serverID, nymID);
    String strResponse = OTAPI_Func.SendRequest(theRequest, "GET_MARKET_LIST");
    if (!Utility.VerifyStringVal(strResponse)) {
        System.out.println("IN getTicker: OTAPI_Func.SendRequest(() failed. (I give up.) ");
        return null;
    }
    if (otapiJNI.OTAPI_Basic_Message_GetDepth(strResponse) == 0) {
        System.out.println("getTicker: OT_API_Message_GetDepth returned zero");
        return null;
    }
    MarketList marketList = Helpers.getMarketList(serverID);
    if (marketList == null) {
        System.out.println("getTicker - marketList returns null");
        return null;
    }
    int nMarketDataCount = (int) marketList.GetMarketDataCount();
    for (int i = 0; i < nMarketDataCount; i++) {
        MarketData marketData = marketList.GetMarketData(i);
        if (marketData == null) {
            continue;
        }
        if (!Utility.VerifyStringVal(marketID) || (Utility.VerifyStringVal(marketID) && marketID.equals(marketData.getMarket_id()))) {
            MarketTicker marketTicker = new MarketTicker();
            marketTicker.setLastPrice(marketData.getLast_sale_price());
            marketTicker.setHighestBid(marketData.getCurrent_bid());
            marketTicker.setLowestAsk(marketData.getCurrent_ask());
            marketTicker.setHighPrice(marketData.getRecent_highest_bid());
            marketTicker.setLowPrice(marketData.getRecent_lowest_ask());
            return marketTicker;
        }
    }
    return null;
}
Also used : MarketData(org.opentransactions.otapi.MarketData) OTAPI_Func(com.moneychanger.core.util.OTAPI_Func) MarketTicker(com.moneychanger.core.dataobjects.MarketTicker) MarketList(org.opentransactions.otapi.MarketList)

Example 15 with OTAPI_Func

use of com.moneychanger.core.util.OTAPI_Func in project otapij by FellowTraveler.

the class Market method cancelOrder.

public static boolean cancelOrder(String serverID, String nymID, String assetAccountID, String transactionID) {
    // ----------------------------------------
    System.out.println(serverID + " .. " + nymID + " .. " + assetAccountID + " .. " + transactionID);
    OTAPI_Func theRequest = new OTAPI_Func(OTAPI_Func.FT.CANCEL_MARKET_OFFER, serverID, nymID, assetAccountID, transactionID);
    String strResponse = OTAPI_Func.SendTransaction(theRequest, "CANCEL_MARKET_OFFER");
    if (!Utility.VerifyStringVal(strResponse)) {
        System.out.println("IN cancelOrder: OTAPI_Func.SendTransaction(() failed. (I give up.) ");
        return false;
    }
    return true;
}
Also used : OTAPI_Func(com.moneychanger.core.util.OTAPI_Func)

Aggregations

OTAPI_Func (com.moneychanger.core.util.OTAPI_Func)30 HashMap (java.util.HashMap)3 Map (java.util.Map)3 MarketData (org.opentransactions.otapi.MarketData)3 MarketList (org.opentransactions.otapi.MarketList)3 MarketTicker (com.moneychanger.core.dataobjects.MarketTicker)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 OfferDataNym (org.opentransactions.otapi.OfferDataNym)2 OfferListNym (org.opentransactions.otapi.OfferListNym)2 MarketDetails (com.moneychanger.core.dataobjects.MarketDetails)1 Date (java.util.Date)1 AskData (org.opentransactions.otapi.AskData)1 BidData (org.opentransactions.otapi.BidData)1 OfferListMarket (org.opentransactions.otapi.OfferListMarket)1 Storable (org.opentransactions.otapi.Storable)1 StringMap (org.opentransactions.otapi.StringMap)1 TradeDataMarket (org.opentransactions.otapi.TradeDataMarket)1 TradeListMarket (org.opentransactions.otapi.TradeListMarket)1 Utility (org.opentransactions.otjavalib.util.Utility)1