GetLimitOrders adjusts
This commit is contained in:
parent
ca3ae3019b
commit
2059093be4
7 changed files with 87 additions and 33 deletions
14
src/main/java/de/bitsharesmunich/graphenej/LimitOrder.java
Normal file
14
src/main/java/de/bitsharesmunich/graphenej/LimitOrder.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package de.bitsharesmunich.graphenej;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author henry
|
||||
*/
|
||||
public class LimitOrder {
|
||||
public String id;
|
||||
public String expiration;
|
||||
public UserAccount seller;
|
||||
public long for_sale;
|
||||
public long deferred_fee;
|
||||
public Price sell_price;
|
||||
}
|
|
@ -57,7 +57,7 @@ public class Main {
|
|||
// test.testingInvoiceGeneration();
|
||||
// test.testCompression();
|
||||
// test.testAccountUpdateSerialization();
|
||||
test.testAccountUpdateOperationBroadcast();
|
||||
// test.testAccountUpdateOperationBroadcast();
|
||||
// test.testCreateBinFile();
|
||||
// test.testImportBinFile();
|
||||
// test.testLookupAccounts();
|
||||
|
@ -66,5 +66,6 @@ public class Main {
|
|||
// test.testGetRelativeAccountHistory();
|
||||
// test.testLookupAssetSymbols();
|
||||
// test.testGetBlockHeader();
|
||||
test.testGetLimitOrders();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package de.bitsharesmunich.graphenej;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
9
src/main/java/de/bitsharesmunich/graphenej/Price.java
Normal file
9
src/main/java/de/bitsharesmunich/graphenej/Price.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package de.bitsharesmunich.graphenej;
|
||||
|
||||
/**
|
||||
* Created by nelson on 12/16/16.
|
||||
*/
|
||||
public class Price {
|
||||
public AssetAmount base;
|
||||
public AssetAmount quote;
|
||||
}
|
|
@ -38,7 +38,7 @@ public class Test {
|
|||
|
||||
private Transaction transaction;
|
||||
|
||||
public Transaction getTransaction() {
|
||||
public Transaction GetTransaction() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
|
@ -884,4 +884,47 @@ public class Test {
|
|||
System.out.println("IOException. Msg: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
void testGetLimitOrders() {
|
||||
SSLContext context = null;
|
||||
try {
|
||||
context = NaiveSSLContext.getInstance("TLS");
|
||||
WebSocketFactory factory = new WebSocketFactory();
|
||||
|
||||
// Set the custom SSL context.
|
||||
factory.setSSLContext(context);
|
||||
|
||||
WebSocket mWebSocket = factory.createSocket(BLOCK_PAY_DE);
|
||||
|
||||
mWebSocket.addListener(new GetLimitOrders("1.3.0", "1.3.562", 100, new WitnessResponseListener() {
|
||||
@Override
|
||||
public void onSuccess(WitnessResponse response) {
|
||||
List<LimitOrder> orders = (List<LimitOrder>) response.result;
|
||||
for(LimitOrder order : orders){
|
||||
double price = (((double) order.sell_price.base.getAmount().longValue()) / ((double) order.sell_price.quote.getAmount().longValue())) / 10;
|
||||
System.out.println(String.format("Selling %s for %s at %f %s/%s, expiration: %s",
|
||||
order.sell_price.base.getAsset().getObjectId(),
|
||||
order.sell_price.quote.getAsset().getObjectId(),
|
||||
price,
|
||||
order.sell_price.base.getAsset().getObjectId(),
|
||||
order.sell_price.quote.getAsset().getObjectId(),
|
||||
order.expiration));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(BaseResponse.Error error) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
}));
|
||||
mWebSocket.connect();
|
||||
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
System.out.println("NoSuchAlgorithmException. Msg: " + e.getMessage());
|
||||
} catch (WebSocketException e) {
|
||||
System.out.println("WebSocketException. Msg: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
System.out.println("IOException. Msg: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,6 @@ public class UserAccount extends GrapheneObject implements ByteSerializable, Jso
|
|||
@Override
|
||||
public UserAccount deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
String id = json.getAsString();
|
||||
System.out.println("id: "+id);
|
||||
return new UserAccount(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
package de.bitsharesmunich.graphenej.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
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 de.bitsharesmunich.graphenej.Market;
|
||||
import de.bitsharesmunich.graphenej.AssetAmount;
|
||||
import de.bitsharesmunich.graphenej.LimitOrder;
|
||||
import de.bitsharesmunich.graphenej.RPC;
|
||||
import de.bitsharesmunich.graphenej.UserAccount;
|
||||
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
|
||||
import de.bitsharesmunich.graphenej.models.ApiCall;
|
||||
import de.bitsharesmunich.graphenej.models.BaseResponse;
|
||||
|
@ -48,12 +51,16 @@ public class GetLimitOrders extends WebSocketAdapter {
|
|||
|
||||
@Override
|
||||
public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
|
||||
if(frame.isTextFrame())
|
||||
System.out.println("<<< "+frame.getPayloadText());
|
||||
try {
|
||||
String response = frame.getPayloadText();
|
||||
Gson gson = new Gson();
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
|
||||
Type GetLimitiOrdersResponse = new TypeToken<WitnessResponse<ArrayList<Market>>>() {}.getType();
|
||||
WitnessResponse<ArrayList<Market>> witnessResponse = gson.fromJson(response, GetLimitiOrdersResponse);
|
||||
Type GetLimitOrdersResponse = new TypeToken<WitnessResponse<List<LimitOrder>>>() {}.getType();
|
||||
builder.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetDeserializer());
|
||||
builder.registerTypeAdapter(UserAccount.class, new UserAccount.UserAccountSimpleDeserializer());
|
||||
WitnessResponse<List<LimitOrder>> witnessResponse = builder.create().fromJson(response, GetLimitOrdersResponse);
|
||||
if (witnessResponse.error != null) {
|
||||
this.mListener.onError(witnessResponse.error);
|
||||
} else {
|
||||
|
@ -65,6 +72,13 @@ public class GetLimitOrders extends WebSocketAdapter {
|
|||
websocket.disconnect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception {
|
||||
if(frame.isTextFrame()){
|
||||
System.out.println(">>> "+frame.getPayloadText());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(WebSocket websocket, WebSocketException cause) throws Exception {
|
||||
mListener.onError(new BaseResponse.Error(cause.getMessage()));
|
||||
|
|
Loading…
Reference in a new issue