Yahoo Finance API value to 5 decimals - api

Hi i'm trying to get Currey Pairs Values of foreign from the Yahoo Finance API ,
I've consulted the following answer
FinanceAPI
and i've choosed the yahoo finance api, I've created a sailsjs project and have used request module to get the Current pair value, my function to get get current currency pair value is
/*TradeService.js*/
var request = require('request')
module.exports = {
getPairValService: function(req, res, pair, callbacl) {
getPairVal(pair, function(err, data) {
if (data) {
callbacl(null, data);
}
})
}
};
function getPairVal(pair, pairValue) {
var yahoodefaultapisquery = 'http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("EURUSD", "USDJPY", "USDBGN", "USDCZK", "USDDKK", "USDGBP", "USDHUF", "USDLTL", "USDLVL", "USDPLN", "USDRON", "USDSEK", "USDCHF", "USDNOK", "USDHRK", "USDRUB", "USDTRY", "USDAUD", "USDBRL", "USDCAD", "USDCNY", "USDHKD", "USDIDR", "USDILS", "USDINR", "USDKRW", "USDMXN", "USDMYR", "USDNZD", "USDPHP", "USDSGD", "USDTHB", "USDZAR", "USDISK")&format=json&env=store://datatables.org/alltableswithkeys';
var yahoocustomapisquery = 'http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("' + pair + '")&format=json&env=store://datatables.org/alltableswithkeys'
var yahooapisquery = pair == '' ? yahoodefaultapisquery : yahoocustomapisquery;
request(yahooapisquery, function(error, response, body) {
if (error && response.statusCode != 200) {
sails.log.error(error) // Show the HTML for the Google homepage.
pairValue(error, null);
} else if (!error && response.statusCode == 200) {
sails.log.info(body);
pairValue(null, body);
}
})
}
and the response i receive from Yahoo Finance is something like
"query": {
"count": 2,
"created": "2015-07-20T11:24:14Z",
"lang": "en-US",
"diagnostics": {
"url": [{
"execution-start-time": "1",
"execution-stop-time": "3",
"execution-time": "2",
"content": "http://www.datatables.org/yahoo/finance/yahoo.finance.xchange.xml"
}, {
"execution-start-time": "12",
"execution-stop-time": "15",
"execution-time": "3",
"content": "http://download.finance.yahoo.com/d/quotes.csv?s=USDMXN=X&f=snl1d1t1ab"
}, {
"execution-start-time": "12",
"execution-stop-time": "16",
"execution-time": "4",
"content": "http://download.finance.yahoo.com/d/quotes.csv?s=USDCHF=X&f=snl1d1t1ab"
}],
"publiclyCallable": "true",
"cache": [{
"execution-start-time": "10",
"execution-stop-time": "11",
"execution-time": "1",
"method": "GET",
"type": "MEMCACHED",
"content": "8bb0e407e3bb00d83b039c07d63130d0"
}, {
"execution-start-time": "11",
"execution-stop-time": "12",
"execution-time": "1",
"method": "GET",
"type": "MEMCACHED",
"content": "d69f38521719d58f343c9657edf0ad59"
}],
"query": [{
"execution-start-time": "12",
"execution-stop-time": "16",
"execution-time": "4",
"content": "select * from csv where url='http://download.finance.yahoo.com/d/quotes.csv?s=USDCHF=X&f=snl1d1t1ab' and columns='Symbol,Name,Rate,Date,Time,Ask,Bid'"
}, {
"execution-start-time": "12",
"execution-stop-time": "16",
"execution-time": "4",
"content": "select * from csv where url='http://download.finance.yahoo.com/d/quotes.csv?s=USDMXN=X&f=snl1d1t1ab' and columns='Symbol,Name,Rate,Date,Time,Ask,Bid'"
}],
"javascript": [{
"execution-start-time": "10",
"execution-stop-time": "17",
"execution-time": "6",
"instructions-used": "37334",
"table-name": "yahoo.finance.xchange"
}, {
"execution-start-time": "10",
"execution-stop-time": "17",
"execution-time": "7",
"instructions-used": "37334",
"table-name": "yahoo.finance.xchange"
}],
"user-time": "18",
"service-time": "11",
"build-version": "0.2.154"
},
"results": {
"rate": [{
"id": "USDMXN",
"Name": "USD/MXN",
"Rate": "15.9260",
"Date": "7/20/2015",
"Time": "12:24pm",
"Ask": "15.9270",
"Bid": "15.9260"
}, {
"id": "USDCHF",
"Name": "USD/CHF",
"Rate": "0.9626",
"Date": "7/20/2015",
"Time": "12:24pm",
"Ask": "0.9628",
"Bid": "0.9626"
}]
}
}
}
Now that I've compare the pair values with MT4 software of different brokers I've came to see there is a lot of difference in yahoo figures and the MT4 figures of, and also i want the rate, ask and bib object to be five decimals like currently the value is 1.2584 i want it to be like 1.25849
Now that I've two big problems with it Please suggest how can i achieve my objectives of getting five decimal values and bigger difference using YAHOO API or do i need to use some one else ? because the major problem with others are limited hits per month or day.
Please Suggest and help me out.
Thanks in advance ;)

Related

Setting up Continuous export of API data to csv for Racing lap times

Have access to an API that provides data for racing, including driver names, and their last lap, best lap.. etc. Completely new to coding but learning the ropes. This is an example of an output from the API.
"Successful": true,
"Session": {
"RunNumber": "47",
"SessionName": "KART DRIVERS - EXPERIENCE / PROVA 11 22:30",
"TrackName": "KGV RACE TRACKS - CIRCUITO 109",
"TrackLength": "0.725",
"CurrentTime": "23:05:24",
"SessionTime": "00:13:27",
"TimeToGo": "00:04:32",
"LapsToGo": "9999",
"FlagStatus": "Green",
"SortMode": "race",
"Classes": {
"1": {
"ClassID": "1",
"Description": "RENTAL"
}
},
"Competitors": {
"018": {
"RacerID": "018",
"Number": "018",
"Transponder": "02",
"FirstName": "LR",
"LastName": "",
"Nationality": "",
"AdditionalData": "",
"ClassID": "1",
"Position": "28",
"Laps": "8",
"TotalTime": "00:12:34.376",
"BestPosition": "26",
"BestLap": "8",
"BestLapTime": "00:01:09.158",
"LastLapTime": "00:01:09.158"
},
"043": {
"RacerID": "043",
"Number": "043",
"Transponder": "48",
"FirstName": "LORENZO",
"LastName": "",
"Nationality": "",
"AdditionalData": "",
"ClassID": "1",
"Position": "32",
"Laps": "5",
"TotalTime": "00:12:54.095",
"BestPosition": "32",
"BestLap": "4",
"BestLapTime": "00:01:38.740",
"LastLapTime": "00:02:39.277"
How would I go about reading data from this api every 30 seconds to 1 minute, and exporting that data into a CSV to put on excel?

Low-Fare endpoint returning JSON with missing operating.carrierCode

The Low-fare endpoint just recently started returning JSON with some flight segments missing a key-value pair for operating.carrierCode, for example:
"operating": {
"number": “5898"
This was the second flight segment of the first result (data[0].offerItems[0].services[0].segments[1].flightSegment) when yesterday I searched:
https://test.api.amadeus.com/v1/shopping/flight-offers?origin=LON&destination=PAE&departureDate=2019-10-29&returnDate=2019-11-13&adults=1&nonStop=false&max=50
Here it is in context:
{
"data": [
{
"type": "flight-offer",
"id": "1564934270644-1482530186",
"offerItems": [
{
"services": [
{
"segments": [
{
"flightSegment": {
"departure": {
"iataCode": "LHR",
"terminal": "2",
"at": "2019-10-29T09:20:00Z"
},
"arrival": {
"iataCode": "SFO",
"terminal": "I",
"at": "2019-10-29T13:30:00-07:00"
},
"carrierCode": "SN",
"number": "9101",
"aircraft": {
"code": "777"
},
"operating": {
"carrierCode": "UA",
"number": "9101"
},
"duration": "0DT11H10M"
},
"pricingDetailPerAdult": {
"travelClass": "ECONOMY",
"fareClass": "K",
"availability": 4,
"fareBasis": "KLP5ULGT"
}
},
{
"flightSegment": {
"departure": {
"iataCode": "SFO",
"terminal": "3",
"at": "2019-10-29T16:15:00-07:00"
},
"arrival": {
"iataCode": "PAE",
"at": "2019-10-29T18:32:00-07:00"
},
"carrierCode": "UA",
"number": "5898",
"aircraft": {
"code": "E7W"
},
"operating": {
"number": “5898”
},
"duration": "0DT2H17M"
},
"pricingDetailPerAdult": {
"travelClass": "ECONOMY",
"fareClass": "K",
"availability": 9,
"fareBasis": "KLP5ULGT"
}
}
]
…
Is this a known bug? It was pretty easy to write a workaround, but I was surprised that this data was missing since it had been working correctly for months.
This is a common issue with the operating carrier even in cryptic mode
FLT/DATE RTNG CKIN TM DEP ARR TM EQP ML DURA DIST
UA5898 Y 29OCT SFOPAE 3 415P 632P E7W G 2:17 711
SFOPAE OPERATED BY SKYWEST DBA UNITED EXPRES
>
Whilst at shopping using enterprise apis you can use the same text describing the schedule data resumed by flight number.
Dont know of any parameter to get it in the api response too.

Issue when sending Query with Arabic characters through API

I can't send Query with Arabic characters through API. I am trying to send the query from CS-Cart to Quickbooks Online.
I tried to send the query using the arabic letters as the following:
select * from Customer Where DisplayName = 'احمد عبدالعزيز'
it returns:
{
"responseHeader": {
"status": 400,
"message": "Bad Request",
"intuitTid": "2dbec1fd-5dc1-3a14-4a12-7c338db0ee2a",
"realmID": "123146420719144"
},
"response": {
"Fault": {
"Error": [
{
"Message": "Error parsing query",
"Detail": "QueryParserError: Invalid content. Lexical error at line 1, column 45. Encountered: \"\\u0627\" (1575), after : \"\\'\"",
"code": "4000"
}
],
"type": "ValidationFault"
},
"time": "2019-07-04T07:09:03.026-07:00"
}
}
And if I try it after encoding the name and send the query as the following:
select * from Customer Where DisplayName = '%D8%A7%D8%AD%D9%85%D8%AF+%D8%B9%D8%A8%D8%AF%D8%A7%D9%84%D8%B9%D8%B2%D9%8A%D8%B2'
it returns nothing:
{
"QueryResponse": {},
"time": "2019-07-04T07:09:42.698-07:00"
}
I am expecting to get like:
{
"QueryResponse": {
"Customer": [
{
"Taxable": false,
"BillAddr": {
"Id": "924",
"Country": "Saudi Arabia"
},
"ShipAddr": {
"Id": "925",
"Country": "Saudi Arabia"
},
"Job": false,
"BillWithParent": false,
"Balance": 157.5,
"BalanceWithJobs": 157.5,
"CurrencyRef": {
"value": "SAR",
"name": "Saudi Riyal"
},
"PreferredDeliveryMethod": "None",
"IsProject": false,
"domain": "QBO",
"sparse": false,
"Id": "577",
"SyncToken": "0",
"MetaData": {
"CreateTime": "2019-07-01T06:37:32-07:00",
"LastUpdatedTime": "2019-07-01T06:37:33-07:00"
},
"GivenName": "Ramil",
"FamilyName": "Gilaev",
"FullyQualifiedName": "Ramil Gilaev",
"DisplayName": "Ramil Gilaev",
"PrintOnCheckName": "Ramil Gilaev",
"Active": true,
"PrimaryPhone": {
"FreeFormNumber": "123456789"
}
}
],
"startPosition": 1,
"maxResults": 1
},
"time": "2019-07-05T02:12:35.562-07:00"
}
Also I noticed even if the Query is in English name, it results the same.
select * from Customer Where DisplayName = 'Ahmed Al-Khuraisir'
it results:
{
"QueryResponse": {},
"time": "2019-07-05T03:31:11.149-07:00"
}
Please check attached images.
Screenshot 1
Screenshot 2

How to process payments with service fee being deducted in Visa Cybersource Payments API?

I have an app that I would like to add payment processing similar to Amazon payment processing into it where sub-merchants get paid by customers with service fee being deducted, I can see in https://developer.visa.com/capabilities/cybersource/reference#cybersource__cybs_payments_v2__v2__process_a_payment the following request body but there is no field in request body to specify a service fee:
{
"clientReferenceInformation": {
"code": "TC588171_3"
},
"processingInformation": {
"commerceIndicator": "internet"
},
"aggregatorInformation": {
"subMerchant": {
"cardAcceptorID": "1234567890",
"country": "US",
"phoneNumber": "650-432-0000",
"address1": "900 Metro Center",
"postalCode": "94404-2775",
"locality": "Foster City",
"name": "Visa Inc",
"administrativeArea": "CA",
"region": "PEN",
"email": "test#cybs.com"
},
"name": "V-Internatio",
"aggregatorID": "123456789"
},
"orderInformation": {
"billTo": {
"country": "US",
"lastName": "VDP",
"address2": "Address 2",
"address1": "201 S. Division St.",
"postalCode": "48104-2201",
"locality": "Ann Arbor",
"administrativeArea": "MI",
"firstName": "RTS",
"phoneNumber": "999999999",
"district": "MI",
"buildingNumber": "123",
"company": "Visa",
"email": "test#cybs.com"
},
"amountDetails": {
"totalAmount": "102.21",
"currency": "USD"
}
},
"paymentInformation": {
"card": {
"expirationYear": "2031",
"number": "5555555555554444",
"securityCode": "123",
"expirationMonth": "12",
"type": "002"
}
}
}
Is there a way or a workaround to get a service fee deducted?
Service fees go in the orderInformation block. Like this:
"orderInformation": {
"amountDetails": {
"totalAmount": "102.21",
"currency": "USD",
"serviceFeeAmount": "3.00"
},
There are a few prerequisites to using service fees. One of which you must be using First Data as your processor. For more details check this documentation.

how to write a query in oracle to get a single value as string from the json list?

I have a json string containing list of data, I want to write a query to get a single value based on the condition. but it is returning list of values. please help me to write a valid query in oracle database.
My json string looks like
[
{
"Key": [
{
"obj": {
"xyz":"cdf"
},
"Info": [
{
"Code": "",
"tax": "",
"rate": "",
"taxAmount": {
"formattedAmount": "",
"Amount": ""
}
},
{
"Code": "qwer",
"tax": "ggs",
"rate": "0",
"taxAmount": {
"formattedAmount": "10.00",
"Amount": "10.00"
},
"key": "qwer"
},
{
"Code": "poiu",
"tax": "ggs",
"rate": "0",
"taxAmount": {
"formattedAmount": "20.00",
"Amount": "20.00"
},
"key": "poiu"
},
{
"coverageCode": "zxcv",
"tax": "ggs",
"rate": "0",
"taxAmount": {
"formattedAmount": "30.00",
"Amount": "30.00"
},
"key": "zxcv"
}
]
},
{
"status": "S"
}
]
}
]
I want to get formattedAmount value "10.00". Written a query like
SELECT json_query(details, '$.Info.taxAmount.formattedAmount' WITH WRAPPER)
FROM details_table where json_query(details, '$.Info.Code' WITH WRAPPER) = 'qwer';
returns no value. without where clause i'll get all the formattedAmont in list [,"10.00","20.00","30.00"]