I'll like to get only the BTC pairs of Binance. I use this code to get all currencies current prices
List<TickerPrice> allPrices = client.getAllPrices();
System.out.println(allPrices);
How do I turn only BTC pairs? Thank, experts in the house.
try and catch BinanceAPIException around .. example of grabbing a pair
BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance();
BinanceApiRestClient client = factory.newRestClient();
// BinanceApiAsyncRestClient client = factory.newAsyncRestClient();
// Test connectivity
client.ping();
long serverTime = client.getServerTime();
out.println("<p> Time of ticker from Binance - its Servertime : " + serverTime + "</p>");
TickerStatistics tickerStatistics = client.get24HrPriceStatistics("NEOETH");
out.println("<p> NEO ETH : " + tickerStatistics.getLastPrice() + "</p>");
String price = tickerStatistics.getLastPrice().toString();
out.println("<p> as string .. " + price + "</p>");
TickerStatistics tickerStatistics2 = client.get24HrPriceStatistics("HBARUSDT");
out.println("<p> HBAR USDT : " + tickerStatistics2.getLastPrice() + "</p>");
Related
This could be a duplicate question, but I couldn't find my solution anywhere. Hence, posting it.
I am trying to simply POST a request for a Student account Creation Scenario. I do have a JSON file which comprises all the "Keys:Values", required for Student account creation.
This is how the file student_Profile.json looks like:
{
"FirstName":"APi1-Stud-FN",
"MiddleInitial":"Q",
"LastName":"APi1-Stud-LN",
"UserAlternateEmail":"",
"SecretQuestionId":12,
"SecretQuestionAnswer":"Scot",
"UserName":"APi1-stud#xyz.com",
"VerifyUserName":"APi1-stud#xyz.com",
"Password":"A123456",
"VerifyPassword":"A123456",
"YKey":"123xyz",
"YId":6,
"Status":false,
"KeyCode":"",
"SsoUserName":"APi1-stud#xyz.com",
"SsoPassword":"",
"BirthYear":2001
}
So everything on Posting the request from "Rest Assured" point of view looks fine, it's just that I want to update a few values from the above JSON body using JAVA so that I can create a new Student profile every time I run my function and don't have to manually change the Body.
For Every POST Student Account Creation scenario, I need to update the value for
the following keys so that a new test student user account can be created:
First Name
Last Name and
Username // "VerifyUserName" and "SSO UserName" will remain same as user name
I modified the answer to get random values and pass them to json body. random value generation was taken from the accepted answer of this question.
public void testMethod() {
List<String> randomValueList = new ArrayList<>();
for (int i = 0; i < 3; i++) {
String SALTCHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
StringBuilder salt = new StringBuilder();
Random rnd = new Random();
while (salt.length() < 18) { // length of the random string.
int index = (int) (rnd.nextFloat() * SALTCHARS.length());
salt.append(SALTCHARS.charAt(index));
}
randomValueList.add(salt.toString());
}
String jsonBody = "{\n" +
" \"FirstName\":\"" + randomValueList.remove(0) + "\",\n" +
" \"MiddleInitial\":\"Q\",\n" +
" \"LastName\":\"" + randomValueList.remove(0) + "\",\n" +
" \"UserAlternateEmail\":\"\",\n" +
" \"SecretQuestionId\":12,\n" +
" \"SecretQuestionAnswer\":\"Scot\",\n" +
" \"UserName\":\"" + randomValueList.remove(0) + " \",\n" +
" \"VerifyUserName\":\"APi1-stud#xyz.com\",\n" +
" \"Password\":\"A123456\",\n" +
" \"VerifyPassword\":\"A123456\",\n" +
" \"YKey\":\"123xyz\",\n" +
" \"YId\":6,\n" +
" \"Status\":false,\n" +
" \"KeyCode\":\"\",\n" +
" \"SsoUserName\":\"APi1-stud#xyz.com\",\n" +
" \"SsoPassword\":\"\",\n" +
" \"BirthYear\":2001\n" +
"}";
Response response = RestAssured
.given()
.body(jsonBody)
.when()
.post("api_url")
.then()
.extract()
.response();
// Do what you need to do with the response body
}
We can used pojo based approach to do certain things very easily . No matter how complex is the payload , serialization and dieselization is the best answer . I have created a framework template for api automation that can we used by putting required POJO's in path :
https://github.com/tanuj-vishnoi/pojo_api_automation
To create pojo, I also have ready to eat food for you :
https://github.com/tanuj-vishnoi/pojo_generator_using_jsonschema2pojo
for the above problem you can refer to the JsonPath lib https://github.com/json-path/JsonPath and use this code:
String mypayload = "{\n" +
" \"FirstName\":\"APi1-Stud-FN\",\n" +
" \"MiddleInitial\":\"Q\",\n" +
" \"LastName\":\"APi1-Stud-LN\"}";
Map map = JsonPath.parse(mypayload).read("$",Map.class);
System.out.println(list);
once the payload converted into map you can change only required values as per the requirement
To generate random strings you can refer to lib org.apache.commons.lang3.RandomStringUtils;
public static String generateUniqueString(int lenghtOfString){
return
RandomStringUtils.randomAlphabetic(lenghtOfString).toLowerCase();
}
I recommend to store payload in a separate file and load it at runtime.
I don't get it why it says it cannot find symbol append.
do i need to use Stringbuffer? i got this code on a tutorial for receipts from youtube, and the uploader disabled comments so I can't ask him directly. please help me. Im still an amateur at java.
Tell me if I need to post my whole code or what code would you want to see to see errors. thanks in adv.
Calendar timer = Calendar.getInstance();
timer.getTime();
SimpleDateFormat tTime = new SimpleDateFormat("HH:mm:ss");
tTime.format(timer.getTime());
SimpleDateFormat Tdate = new SimpleDateFormat("dd-MMM-yyyy");
Tdate.format(timer.getTime());
jtxtReceipt.append("\ Water Station Receipt:\n" +
"Reference:\t\t\t" + refs +
"\n=========================================\n" +
"Mineral:\t\t\t" + jtxtMineral.getText() + "\n\n" +
"Purified:\t\t\t" + jtxtPurified.getText() + "\n\n" +
"Travel:\t\t\t" + jtxtTravel.getText() + "\n\n" +
"VAT:\t\t\t" + jtxtVat.getText() + "\n"+
"\n========================================\n" + "\n" +
"Tax:\t\t\t" + jtxtTax2.getText() + "\n" +
"Subtotal:\t\t\t" + jtxtSubTotal.getText() + "\n" +
"Total:\t\t\t" + jtxtTotal.getText() + "\n" +
"===========================================" +
"\nDate:" + Tdate.format(timer.getTime()) +
"\ntTime:" + tTime.format(timer.getTime()) +
"\n\t\tThank you ");
The append method doesn't exist in the String class. You can either user a StringBuilder to do the job, or if it's a light concatenation, just use the + operator
The append method doesn't work on TextField Palette. So, if You're on TextField Palette, replacing that with TextArea Palette should solve the problem.
I am writing a Java parser that get ASANA APP data from ASANA server and parse it and then save it to local DB for customized reports. I have issue with the time needed to execute this Java utility.
I have this sub part of the Java parser. When I run this, it takes approximately 10 seconds to execute. If this code executes in 10 sec than one line this is given below:
JSONObject Project_jsonObject = (JSONObject) Project_jsonParser.parse(Project_br);
This line execute in 9 seconds out of total 10 seconds. How I can reduce this time. Any technique or tip or alternate to reduce time.Please help me I am waiting
static File workDir = new File("C:/cygwin64/bin");
static Runtime systemShell = Runtime.getRuntime();
String project_request="curl -u 4cKDgv4O.L8Th7N8l7jADg3HRU44abmT: https://app.asana.com/api/1.0/projects/"+id_Project+"?opt_pretty";
String project_cmd = project_request;
project_cmd += " | grep 'OBJECT'";
Process ProjectshellOutput = systemShell.exec(workDir+"/"+project_cmd, null,workDir);
InputStreamReader Project_isr = new InputStreamReader(ProjectshellOutput.getInputStream());
BufferedReader Project_br = new BufferedReader (Project_isr);
JSONParser Project_jsonParser = new JSONParser();
JSONObject Project_jsonObject = (JSONObject) Project_jsonParser.parse(Project_br);
JSONObject projectdataObject= (JSONObject)Project_jsonObject.get("data");
Long project_id = (Long) projectdataObject.get("id");
System.out.println("project id is: " + project_id);
String project_created_at_dt = (String) projectdataObject.get("created_at");
System.out.println("The project created at is: " + project_created_at_dt);
String project_modified_at_dt = (String) projectdataObject.get("modified_at");
System.out.println("The project modified at is: " + project_modified_at_dt);
boolean project_public_status = (boolean) projectdataObject.get("public");
System.out.println("project public status: " + project_public_status);
String project_name = (String) projectdataObject.get("name");
System.out.println("project name is: " + project_name);
String project_notes = (String) projectdataObject.get("notes");
System.out.println("project Notes are: " + project_notes);
boolean project_archived_status = (boolean) projectdataObject.get("archived");
System.out.println("project archived status: " + project_archived_status);
JSONObject workspaceObj = (JSONObject) projectdataObject.get("workspace");
Long workspace_id = (Long) workspaceObj.get("id");
String workspace_name = (String) workspaceObj.get("name");
System.out.println("Workspace id " + workspace_id + " with workspace name " + workspace_name);
String color = (String) projectdataObject.get("color");
System.out.println("color : " + color);
JSONObject teamObj = (JSONObject) projectdataObject.get("team");
Long team_id = (Long) teamObj.get("id");
String team_name = (String) teamObj.get("name");
System.out.println("team id " + team_id + " with team name " + team_name);
It looks like you're using the JSON.simple library. According to this test, JSON.simple parsed a 190 MB file in about 140 seconds. That's in line with taking 9 seconds to parse a 15 MB file. Jackson is faster, but only just barely. So I doubt there's anything you can do to significantly improve performance.
What I'm trying to do is to obtain a Directory Number from CUCM, using the AXL API from Cisco. Here's the relevant Code:
private void getNumber(){
AXLAPIService axlService = new AXLAPIService();
AXLPort axlPort = axlService.getAXLPort();
String validatorUrl = "https://mycucm:8443/axl/";
((BindingProvider) axlPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, validatorUrl);
((BindingProvider) axlPort).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, Demo.ucAdmin);
((BindingProvider) axlPort).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, Demo.ucPswd);
GetLineReq axlParams = new GetLineReq();
axlParams.setPattern("7491817");
axlParams.setUuid("{48a6ff28-cea7-fc3e-3d82-8cc245ed4ea3}");
GetLineRes getLineResponse = axlPort.getLine(axlParams);
Demo.informUser("Line Information: \n"
+ "Alerting Name: " + getLineResponse.getReturn().getLine().getAlertingName() + "\n"
+ "Dial Number: " + getLineResponse.getReturn().getLine().getPattern() + "\n"
+ "Description: " + getLineResponse.getReturn().getLine().getDescription() + "\n"
+ " " + getLineResponse.getReturn().getLine().getShareLineAppearanceCssName());
}
As you can tell from this diagram it is only necessary to specify either the uuid or the pattern of the number:
But the code only works, if I specify the uuid, which is not, what I'm trying to achieve. The only thing i have given, is the pattern, which I want to use, to get all the other information. I Already examined this site from Cisco: How to ... Create an AXL Java Client using JAX-WS
When I leave out the uuid I get this Error:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Item not valid: The specified Line was not found
I also checked, how the Directory Number is stored inside the CUCM Database using the AXLSqlToolkit:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Header/><SOAP-ENV:Body><axl:executeSQLQueryResponse xmlns:axl="http://www.cisco.com/AXL/API/7.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" sequence="1405672933992"><return><row><dnorpattern>7491817</dnorpattern><pkid>48a6ff28-cea7-fc3e-3d82-8cc245ed4ea3</pkid></row></return></axl:executeSQLQueryResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
Does anyone know, how I can obtain the Directory Number, only by using the pattern-value?
I figured it out myself. The routePartitionName is also a mandatory parameter, which had to be specified. Here's the working code of my method:
private void getNumber(){
AXLAPIService axlService = new AXLAPIService();
AXLPort axlPort = axlService.getAXLPort();
String validatorUrl = "https://mycucm:8443/axl/";
((BindingProvider) axlPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, validatorUrl);
((BindingProvider) axlPort).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, Demo.ucAdmin);
((BindingProvider) axlPort).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, Demo.ucPswd);
GetLineReq axlParams = new GetLineReq();
ObjectFactory objectFactory = new ObjectFactory(); //This is new
XFkType routePartition = new XFkType();
routePartition.setValue("PHONES"); // This is where you specify your route partition name
axlParams.setPattern("7491817");
axlParams.setRoutePartitionName(objectFactory.createGetLineReqRoutePartitionName(routePartition));
GetLineRes getLineResponse = axlPort.getLine(axlParams);
Demo.informUser("Line Information: \n"
+ "Alerting Name: " + getLineResponse.getReturn().getLine().getAlertingName() + "\n"
+ "Dial Number: " + getLineResponse.getReturn().getLine().getPattern() + "\n"
+ "Description: " + getLineResponse.getReturn().getLine().getDescription() + "\n"
+ " " + getLineResponse.getReturn().getLine().getShareLineAppearanceCssName());
}
I have created an html string in which I need to set the background image.
protected void onPostExecute(HashMap<String,String> hPlaceDetails){
String backgroundImage = ??????
String name = hPlaceDetails.get("name");
String icon = hPlaceDetails.get("icon");
String vicinity = hPlaceDetails.get("vicinity");
String lat = hPlaceDetails.get("lat");
String lng = hPlaceDetails.get("lng");
String formatted_address = hPlaceDetails.get("formatted_address");
String formatted_phone = hPlaceDetails.get("formatted_phone");
String website = hPlaceDetails.get("website");
String rating = hPlaceDetails.get("rating");
String international_phone_number = hPlaceDetails.get("international_phone_number");
String url = hPlaceDetails.get("url");
String mimeType = "text/html";
String encoding = "utf-8";
String data = "<html>"+
"<body background="+backgroundImage+"><img style='float:left' src="+icon+" /><h1><center>"+name+"</center></h1>" +
"<br style='clear:both' />" +
"<hr />"+
"<p>Vicinity : " + vicinity + "</p>" +
"<p>Location : " + lat + "," + lng + "</p>" +
"<p>Address : " + formatted_address + "</p>" +
"<p>Phone : " + formatted_phone + "</p>" +
"<p>Website : " + website + "</p>" +
"<p>Rating : " + rating + "</p>" +
"<p>International Phone : " + international_phone_number + "</p>" +
"<p>URL : <a href='" + url + "'>" + url + "</p>" +
"</body></html>";
// Setting the data in WebView
mWvPlaceDetails.loadDataWithBaseURL("", data, mimeType, encoding, "");
}
Note: I have my background image (background9.png) in the location MyProject/res/drawable-xhdpi. Please suggest how I need to set
<body background="+backgroundImage+">
Instead of using \res\drawable-xhdp\background9.png as the path as you mentioned in your comment, you should use:
<body background='file:///android_res/drawable/background9.png'>
I've just tested this and it works perfectly.
Please add a tag for android to clarify your question.
Anyway, you need to get a reference for your parent layout, by using findViewById(R.id.yourActivitysParentLayout)
You need then to set it's background using a ResourceManager. From the top of my head, the method name you will need is yourparent.setBackgroungDrawable(drawable). The drawable can be obtained from a resource manager instance.
This can all be avoided by setting it's background in the xml if possible by using android:background="#drawable/background9" //sorry not sure if .png is needed. xhdp is not though.