diff --git a/src/main/java/de/bitsharesmunich/graphenej/Market.java b/src/main/java/de/bitsharesmunich/graphenej/Market.java new file mode 100644 index 0000000..90179f9 --- /dev/null +++ b/src/main/java/de/bitsharesmunich/graphenej/Market.java @@ -0,0 +1,28 @@ +package com.luminiasoft.bitshares; + + +/** + * + * @author henry + */ +public class Market { + + public String id; + public String expiration; + public String seller; + public long for_sale; + public long deferred_fee; + public Price sell_price; + + public class Price { + + public AmountPrice base; + public AmountPrice quote; + } + + public class AmountPrice { + + public String asset_id; + public long amount; + } +} diff --git a/src/main/java/de/bitsharesmunich/graphenej/api/GetAsset.java b/src/main/java/de/bitsharesmunich/graphenej/api/GetAsset.java new file mode 100644 index 0000000..f16d5df --- /dev/null +++ b/src/main/java/de/bitsharesmunich/graphenej/api/GetAsset.java @@ -0,0 +1,87 @@ +package com.luminiasoft.bitshares.ws; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; +import com.luminiasoft.bitshares.Asset; +import com.luminiasoft.bitshares.RPC; +import com.luminiasoft.bitshares.interfaces.JsonSerializable; +import com.luminiasoft.bitshares.interfaces.WitnessResponseListener; +import com.luminiasoft.bitshares.models.AccountProperties; +import com.luminiasoft.bitshares.models.ApiCall; +import com.luminiasoft.bitshares.models.BaseResponse; +import com.luminiasoft.bitshares.models.WitnessResponse; +import com.neovisionaries.ws.client.WebSocket; +import com.neovisionaries.ws.client.WebSocketAdapter; +import com.neovisionaries.ws.client.WebSocketException; +import com.neovisionaries.ws.client.WebSocketFrame; + +import java.io.Serializable; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Created by nelson on 11/15/16. + */ +public class GetAsset extends WebSocketAdapter { + + private String assetName; + private WitnessResponseListener mListener; + + public GetAsset(String assetName, WitnessResponseListener listener){ + this.assetName = assetName; + this.mListener = listener; + } + + @Override + public void onConnected(WebSocket websocket, Map> headers) throws Exception { + ArrayList accountParams = new ArrayList<>(); + ArrayList assetList = new ArrayList(); + assetList.add(new JsonSerializable() { + @Override + public String toJsonString() { + return assetName; + } + + @Override + public JsonElement toJsonObject() { + return new JsonParser().parse(assetName); + } + }); + accountParams.add(assetList); + ApiCall getAccountByName = new ApiCall(0, RPC.CALL_GET_ASSET, accountParams, "2.0", 1); + websocket.sendText(getAccountByName.toJsonString()); + } + + @Override + public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception { + String response = frame.getPayloadText(); + Gson gson = new Gson(); + + Type getAssetResponse = new TypeToken>>(){}.getType(); + WitnessResponse> witnessResponse = gson.fromJson(response, getAssetResponse); + + if(witnessResponse.error != null){ + this.mListener.onError(witnessResponse.error); + }else{ + this.mListener.onSuccess(witnessResponse); + } + + websocket.disconnect(); + } + + @Override + public void onError(WebSocket websocket, WebSocketException cause) throws Exception { + mListener.onError(new BaseResponse.Error(cause.getMessage())); + websocket.disconnect(); + } + + @Override + public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception { + mListener.onError(new BaseResponse.Error(cause.getMessage())); + websocket.disconnect(); + } +} diff --git a/src/main/java/de/bitsharesmunich/graphenej/api/GetLimitOrders.java b/src/main/java/de/bitsharesmunich/graphenej/api/GetLimitOrders.java new file mode 100644 index 0000000..a418dd2 --- /dev/null +++ b/src/main/java/de/bitsharesmunich/graphenej/api/GetLimitOrders.java @@ -0,0 +1,81 @@ +package com.luminiasoft.bitshares.ws; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.luminiasoft.bitshares.Market; +import com.luminiasoft.bitshares.RPC; +import com.luminiasoft.bitshares.interfaces.WitnessResponseListener; +import com.luminiasoft.bitshares.models.AccountProperties; +import com.luminiasoft.bitshares.models.ApiCall; +import com.luminiasoft.bitshares.models.BaseResponse; +import com.luminiasoft.bitshares.models.WitnessResponse; +import com.neovisionaries.ws.client.WebSocket; +import com.neovisionaries.ws.client.WebSocketAdapter; +import com.neovisionaries.ws.client.WebSocketException; +import com.neovisionaries.ws.client.WebSocketFrame; + +import java.io.Serializable; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Created by nelson on 11/15/16. + */ +public class getLimitOrders extends WebSocketAdapter { + + private String a; + private String b; + private int limit; + private WitnessResponseListener mListener; + + public getLimitOrders(String a, String b, int limit, WitnessResponseListener mListener) { + this.a = a; + this.b = b; + this.limit = limit; + this.mListener = mListener; + } + + @Override + public void onConnected(WebSocket websocket, Map> headers) throws Exception { + ArrayList accountParams = new ArrayList<>(); + accountParams.add(this.a); + accountParams.add(this.b); + accountParams.add(this.limit); + ApiCall getAccountByName = new ApiCall(0, RPC.CALL_GET_LIMIT_ORDERS, accountParams, "2.0", 1); + websocket.sendText(getAccountByName.toJsonString()); + } + + @Override + public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception { + try { + String response = frame.getPayloadText(); + Gson gson = new Gson(); + + Type GetLimitiOrdersResponse = new TypeToken>>() { + }.getType(); + WitnessResponse> witnessResponse = gson.fromJson(response, GetLimitiOrdersResponse); + if (witnessResponse.error != null) { + this.mListener.onError(witnessResponse.error); + } else { + this.mListener.onSuccess(witnessResponse); + } + } catch (Exception e) { + e.printStackTrace(); + } + websocket.disconnect(); + } + + @Override + public void onError(WebSocket websocket, WebSocketException cause) throws Exception { + mListener.onError(new BaseResponse.Error(cause.getMessage())); + websocket.disconnect(); + } + + @Override + public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception { + mListener.onError(new BaseResponse.Error(cause.getMessage())); + websocket.disconnect(); + } +}