Add GetMarketHistory, GetObjects and GetRelativeAccountHistory API tests
This commit is contained in:
parent
158c9604b8
commit
cadcca0230
2 changed files with 124 additions and 14 deletions
|
@ -54,8 +54,8 @@ public class GetMarketHistory extends BaseGrapheneHandler {
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
*
|
*
|
||||||
* @param base asset which history is desired
|
* @param base asset which history is desired
|
||||||
* @param quote asset which the base price asset will be compared to
|
* @param quote asset which the base price asset will be compared to
|
||||||
* @param bucket the time interval (in seconds) for each point should be (analog to
|
* @param bucket the time interval (in seconds) for each point should be (analog to
|
||||||
* candles on a candle stick graph).
|
* candles on a candle stick graph).
|
||||||
* Note: The bucket value is discrete and node dependent. The default value
|
* Note: The bucket value is discrete and node dependent. The default value
|
||||||
|
@ -84,8 +84,8 @@ public class GetMarketHistory extends BaseGrapheneHandler {
|
||||||
/**
|
/**
|
||||||
* Using this constructor the WebSocket connection closes after the response.
|
* Using this constructor the WebSocket connection closes after the response.
|
||||||
*
|
*
|
||||||
* @param base asset which history is desired
|
* @param base asset which history is desired
|
||||||
* @param quote asset which the base price asset will be compared to
|
* @param quote asset which the base price asset will be compared to
|
||||||
* @param bucket the time interval (in seconds) for each point should be (analog to
|
* @param bucket the time interval (in seconds) for each point should be (analog to
|
||||||
* candles on a candle stick graph).
|
* candles on a candle stick graph).
|
||||||
* Note: The bucket value is discrete and node dependent. The default value
|
* Note: The bucket value is discrete and node dependent. The default value
|
||||||
|
|
|
@ -3,6 +3,7 @@ package de.bitsharesmunich.graphenej.api.android;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
@ -17,6 +18,9 @@ import de.bitsharesmunich.graphenej.api.GetAllAssetHolders;
|
||||||
import de.bitsharesmunich.graphenej.api.GetBlockHeader;
|
import de.bitsharesmunich.graphenej.api.GetBlockHeader;
|
||||||
import de.bitsharesmunich.graphenej.api.GetKeyReferences;
|
import de.bitsharesmunich.graphenej.api.GetKeyReferences;
|
||||||
import de.bitsharesmunich.graphenej.api.GetLimitOrders;
|
import de.bitsharesmunich.graphenej.api.GetLimitOrders;
|
||||||
|
import de.bitsharesmunich.graphenej.api.GetMarketHistory;
|
||||||
|
import de.bitsharesmunich.graphenej.api.GetObjects;
|
||||||
|
import de.bitsharesmunich.graphenej.api.GetRelativeAccountHistory;
|
||||||
import de.bitsharesmunich.graphenej.api.GetRequiredFees;
|
import de.bitsharesmunich.graphenej.api.GetRequiredFees;
|
||||||
import de.bitsharesmunich.graphenej.api.GetTradeHistory;
|
import de.bitsharesmunich.graphenej.api.GetTradeHistory;
|
||||||
import de.bitsharesmunich.graphenej.errors.RepeatedRequestIdException;
|
import de.bitsharesmunich.graphenej.errors.RepeatedRequestIdException;
|
||||||
|
@ -495,11 +499,11 @@ public class NodeConnectionTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for GetMarketHistory Handler.
|
* Test for GetMarketHistory Handler.
|
||||||
*
|
*
|
||||||
* Request for a valid account block header (Need to setup the BlOCK_TEST_NUMBER env with desired
|
* Request for market history of a base asset compared to a quote asset.
|
||||||
* block height)
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetMarketHistoryRequest(){
|
public void testGetMarketHistoryRequest(){
|
||||||
|
@ -507,18 +511,124 @@ public class NodeConnectionTest {
|
||||||
nodeConnection.addNodeUrl(NODE_URL_1);
|
nodeConnection.addNodeUrl(NODE_URL_1);
|
||||||
nodeConnection.connect("", "", false, mErrorListener);
|
nodeConnection.connect("", "", false, mErrorListener);
|
||||||
|
|
||||||
|
Asset asset_base = BLOCKPAY;
|
||||||
|
Asset asset_quote = BTS;
|
||||||
|
//the time interval of the bucket in seconds
|
||||||
|
long bucket = 3600;
|
||||||
|
|
||||||
System.out.println("Adding GetBlockHeader request");
|
//datetime of of the most recent operation to retrieve
|
||||||
|
Date start = new Date();
|
||||||
|
//datetime of the the earliest operation to retrieve
|
||||||
|
//07/16/2017 1:33pm
|
||||||
|
Date end = new Date(1500211991);
|
||||||
|
|
||||||
|
System.out.println("Adding GetMarketHistory request");
|
||||||
try{
|
try{
|
||||||
nodeConnection.addRequestHandler(new GetBlockHeader(BlOCK_TEST_NUMBER, true, new WitnessResponseListener(){
|
nodeConnection.addRequestHandler(new GetMarketHistory(asset_base, asset_quote, bucket, start, end, true, new WitnessResponseListener(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WitnessResponse response) {
|
public void onSuccess(WitnessResponse response) {
|
||||||
System.out.println("GetBlockHeader.onSuccess");
|
System.out.println("GetMarketHistory.onSuccess");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(BaseResponse.Error error) {
|
public void onError(BaseResponse.Error error) {
|
||||||
System.out.println("GetBlockHeader.onError. Msg: "+ error.message);
|
System.out.println("GetMarketHistory.onError. Msg: "+ error.message);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}catch(RepeatedRequestIdException e){
|
||||||
|
System.out.println("RepeatedRequestIdException. Msg: "+e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try{
|
||||||
|
// Holding this thread while we get update notifications
|
||||||
|
synchronized (this){
|
||||||
|
wait();
|
||||||
|
}
|
||||||
|
}catch(InterruptedException e){
|
||||||
|
System.out.println("InterruptedException. Msg: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for GetObjects Handler.
|
||||||
|
*
|
||||||
|
* Request for a limit orders between two assets
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetObjectsRequest(){
|
||||||
|
nodeConnection = NodeConnection.getInstance();
|
||||||
|
nodeConnection.addNodeUrl(NODE_URL_1);
|
||||||
|
nodeConnection.connect("", "", false, mErrorListener);
|
||||||
|
|
||||||
|
String asset_sold_id = BLOCKPAY.getBitassetId();
|
||||||
|
String asset_purchased_id = BTS.getBitassetId();
|
||||||
|
int limit = 10;
|
||||||
|
|
||||||
|
ArrayList<String> objectList = new ArrayList<String>(){{
|
||||||
|
add(BLOCKPAY.getBitassetId());
|
||||||
|
add(BTS.getBitassetId());
|
||||||
|
add(BITEURO.getBitassetId());
|
||||||
|
}};
|
||||||
|
|
||||||
|
System.out.println("Adding GetObjects request");
|
||||||
|
try{
|
||||||
|
nodeConnection.addRequestHandler(new GetObjects(objectList, true, new WitnessResponseListener(){
|
||||||
|
@Override
|
||||||
|
public void onSuccess(WitnessResponse response) {
|
||||||
|
System.out.println("GetObjects.onSuccess");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(BaseResponse.Error error) {
|
||||||
|
System.out.println("GetObjects.onError. Msg: "+ error.message);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}catch(RepeatedRequestIdException e){
|
||||||
|
System.out.println("RepeatedRequestIdException. Msg: "+e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try{
|
||||||
|
// Holding this thread while we get update notifications
|
||||||
|
synchronized (this){
|
||||||
|
wait();
|
||||||
|
}
|
||||||
|
}catch(InterruptedException e){
|
||||||
|
System.out.println("InterruptedException. Msg: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for GetRelativeAccount Handler.
|
||||||
|
*
|
||||||
|
* Request for the transaction history of a user account.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetRelativeAccountHistoryRequest(){
|
||||||
|
nodeConnection = NodeConnection.getInstance();
|
||||||
|
nodeConnection.addNodeUrl(NODE_URL_1);
|
||||||
|
nodeConnection.connect("", "", false, mErrorListener);
|
||||||
|
|
||||||
|
UserAccount userAccount = new UserAccount(ACCOUNT_ID_1);
|
||||||
|
|
||||||
|
//Sequence number of earliest operation
|
||||||
|
int stop = 10;
|
||||||
|
int limit = 50;
|
||||||
|
//Sequence number of the most recent operation to retrieve
|
||||||
|
int start = 50;
|
||||||
|
|
||||||
|
System.out.println("Adding GetRelativeAccountHistory request");
|
||||||
|
try{
|
||||||
|
nodeConnection.addRequestHandler(new GetRelativeAccountHistory(userAccount, stop, limit, start, true, new WitnessResponseListener(){
|
||||||
|
@Override
|
||||||
|
public void onSuccess(WitnessResponse response) {
|
||||||
|
System.out.println("GetRelativeAccountHistory.onSuccess");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(BaseResponse.Error error) {
|
||||||
|
System.out.println("GetRelativeAccountHistory.onError. Msg: "+ error.message);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}catch(RepeatedRequestIdException e){
|
}catch(RepeatedRequestIdException e){
|
||||||
|
@ -588,7 +698,7 @@ public class NodeConnectionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for GetRequiredFees Handler.
|
* Test for GetTradeHistory Handler.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
|
@ -605,17 +715,17 @@ public class NodeConnectionTest {
|
||||||
String asset_purchased_id = BTS.getBitassetId();
|
String asset_purchased_id = BTS.getBitassetId();
|
||||||
int limit = 10;
|
int limit = 10;
|
||||||
|
|
||||||
System.out.println("Adding GetRequiredFees request");
|
System.out.println("Adding GetTradeHistory request");
|
||||||
try{
|
try{
|
||||||
nodeConnection.addRequestHandler(new GetTradeHistory(asset_sold_id, asset_purchased_id, "", "", limit, true, new WitnessResponseListener(){
|
nodeConnection.addRequestHandler(new GetTradeHistory(asset_sold_id, asset_purchased_id, "", "", limit, true, new WitnessResponseListener(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WitnessResponse response) {
|
public void onSuccess(WitnessResponse response) {
|
||||||
System.out.println("GetRequiredFees.onSuccess");
|
System.out.println("GetTradeHistory.onSuccess");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(BaseResponse.Error error) {
|
public void onError(BaseResponse.Error error) {
|
||||||
System.out.println("GetRequiredFees.onError. Msg: "+ error.message);
|
System.out.println("GetTradeHistory.onError. Msg: "+ error.message);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}catch(RepeatedRequestIdException e){
|
}catch(RepeatedRequestIdException e){
|
||||||
|
|
Loading…
Reference in a new issue