This repository has been archived by the owner on Dec 20, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return back some of graphenej lib hardcoded models
- Loading branch information
1 parent
5593847
commit 0685cc1
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/src/main/java/de/bitsharesmunich/graphenej/models/Market.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package de.bitsharesmunich.graphenej.models; | ||
|
||
/** | ||
* | ||
* @author hvarona 12/12/16 | ||
*/ | ||
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; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
app/src/main/java/de/bitsharesmunich/graphenej/models/api/GetLimitOrders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package de.bitsharesmunich.graphenej.models.api; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.reflect.TypeToken; | ||
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; | ||
|
||
import de.bitsharesmunich.graphenej.RPC; | ||
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; | ||
import de.bitsharesmunich.graphenej.models.ApiCall; | ||
import de.bitsharesmunich.graphenej.models.BaseResponse; | ||
import de.bitsharesmunich.graphenej.models.Market; | ||
import de.bitsharesmunich.graphenej.models.WitnessResponse; | ||
|
||
/** | ||
* Created by hvarona on 12/12/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<String, List<String>> headers) throws Exception { | ||
ArrayList<Serializable> 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<WitnessResponse<ArrayList<Market>>>() { | ||
}.getType(); | ||
WitnessResponse<ArrayList<Market>> 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(); | ||
} | ||
} |