HNT exchange rates are broken - coinbase-api

I would like to obtain the HNT/Helium price via the API. Getting the rates through https://api.coinbase.com/v2/exchange-rates?currency=HNT seems to work like with any other currency, but the rates are completely off.
I noticed that on the website, there actually are two tokens called HNT: Helium and Hento (with Helium definitely being the main one, I had not heard of the other one). However, the rates provided by the API don't correspond to either.
The current results:
API result
0.02013283 = $49.67
HNT - Helium (https://www.coinbase.com/price/helium)
$38.92
HNT - Hinto (https://www.coinbase.com/price/hinto)
$0.0669

That's pretty awesome.
Searching for HINTO on CB comes back with no results but you can get to it directly with the link you provided. Searching for HNT only returns Helium. Yet the API returns the un-searchable results for Hinto when using HNT...
But to answer your question, in case you haven't discovered the solution yet, you can simply change the currency to HELIUM
https://api.coinbase.com/v2/exchange-rates?currency=HELIUM
repsonse:
{"data":{"currency":"HELIUM","rates": [...] {"USD":"30.096511279999998"} [...] }}

From a cell, you could call this function:
"colon separated parameters"
=INDEX( SPLIT( INDEX ( SPLIT( IMPORTDATA("https://api.coinbase.com/v2/exchange-rates?currency=HELIUM", "|", ","), ":"), 0, 48), ","), 0, 1)
"semi colon separated parameters"
=INDEX( SPLIT( INDEX ( SPLIT( IMPORTDATA("https://api.coinbase.com/v2/exchange-rates?currency=HELIUM"; "|"; ","); ":"); 0; 48); ","); 0; 1)
This will get you quoted value: "22.87244131153848"
IMPORTDATA will get the JSon, I use the "|" separator so it comes alltogether
{"data":{"currency":"HELIUM","rates":{"AED":"92.539849932...
SPLIT will separate values on every ":"
col 1. {"data"
col 2. {"currency"
col n. ...
INDEX will get the column where the price of Helium is (the FJD is the next element)
"22.87244131153848","FJD"
SPLIT will separate again the value on the ","
col 1: "22.87244131153848"
col 2: "FJD"
INDEX will finally get the resultant value
"22.87244131153848"

Related

How can I use an array as input for FILTER function in Google Spreadsheet?

So this might be trivial, but it's kinda hard to ask. I'd like to FILTER a range based other FILTER results.
I'll try to explain from inside out (related to image below):
I use filter to find all names for given id (the results are joined in column B). This works fine and returns an array of values. This is the inner FILTER.
I want to use this array of names to find all values for them using another outer FILTER.
In other words: Find maximum value for all names for given id.
Here is what I've figured:
=MAX(FILTER(J:J, CONTAINS???(FILTER(G:G, F:F = A2), I:I)))
^--- imaginary function returning TRUE for every value in I
that is contained in the array
=MAX(FILTER(J:J, I:I = FILTER(G:G, F:F = A2)))
^--- equal does not work here when filter returns more than 1 value
=MAX(FILTER(J:J, REGEXMATCH(JOIN(",", FILTER(G:G, F:F = A2)), I:I)))
^--- this approach WORKS but is ineffective and slow on 10k+ cells
https://docs.google.com/spreadsheets/d/1k5lOUYMLebkmU7X2SLmzWGiDAVR3u3CSAF3dYZ_VnKE
I hope to find better CONTAINS function then the REGEXMATCH/JOIN combo, or to do the task using other approach.
try this in A2 cell (after you delete everything in A2:C range):
=SORTN(SORT({INDIRECT("F2:F"&COUNTA(F2:F)+1),
TRANSPOSE(SUBSTITUTE(TRIM(QUERY(QUERY(QUERY({F2:G},
"select max(Col2) group by Col2 pivot Col1"), "offset 1"),,999^99)), " ", ",")),
VLOOKUP(INDIRECT("G2:G"&COUNTA(F2:F)+1), I2:J, 2, 0)}, 1, 1, 3, 0), 999^99, 2, 1, 1)

Anychart tables: How to include thousand separators?

How can I put the text "100.000" in a table in Anychart? When I try to get the string "100.000" in, it is modified to "100".
For a working example see https://jsfiddle.net/Republiq/xcemvm9L/
table = anychart.standalones.table(2,2);
table.getCell(0,0).content("100.000");
table.container("container").draw();
If you want to use such number formatting for the whole table you can define numberLocale in the beginning. If the actual number is 100 and '.' - is a decimal separator and you want to show 3 zeros as decimals, put the following lines before creating the table:
anychart.format.locales.default.numberLocale.decimalsCount = 3;
anychart.format.locales.default.numberLocale.zeroFillDecimals = true;
And then put in the number as:
table.getCell(0,0).content(100);
If '.' - is a group separator and the actual number is 100000, put the following line:
anychart.format.locales.default.numberLocale.groupsSeparator = '.';
And then put in the number as:
table.getCell(0,0).content(100000);
If you want to use special format only for a single cell, we recommend you to use number formatter, which helps to configure all these options only for a single number. For example, it may looks like:
table = anychart.standalones.table(5,5);
table.getCell(0,0).content(anychart.format.number(100000, 3, ".", ","));
table.container("container").draw();
Also, you may learn more about this useful method and find examples in this article

MATLAB Extract all rows between two variables with a threshold

I have a cell array called BodyData in MATLAB that has around 139 columns and 3500 odd rows of skeletal tracking data.
I need to extract all rows between two string values (these are timestamps when an event happened) that I have
e.g.
BodyData{}=
Column 1 2 3
'10:15:15.332' 'BASE05' ...
...
'10:17:33:230' 'BASE05' ...
The two timestamps should match a value in the array but might also be within a few ms of those in the array e.g.
TimeStamp1 = '10:15:15.560'
TimeStamp2 = '10:17:33.233'
I have several questions!
How can I return an array for all the data between the two string values plus or minus a small threshold of say .100ms?
Also can I also add another condition to say that all str values in column2 must also be the same, otherwise ignore? For example, only return the timestamps between A and B only if 'BASE02'
Many thanks,
The best approach to the first part of your problem is probably to change from strings to numeric date values. In Matlab this can be done quite painlessly with datenum.
For the second part you can just use logical indexing... this is were you put a condition (i.e. that second columns is BASE02) within the indexing expression.
A self-contained example:
% some example data:
BodyData = {'10:15:15.332', 'BASE05', 'foo';...
'10:15:16.332', 'BASE02', 'bar';...
'10:15:17.332', 'BASE05', 'foo';...
'10:15:18.332', 'BASE02', 'foo';...
'10:15:19.332', 'BASE05', 'bar'};
% create column vector of numeric times, and define start/end times
dateValues = datenum(BodyData(:, 1), 'HH:MM:SS.FFF');
startTime = datenum('10:15:16.100', 'HH:MM:SS.FFF');
endTime = datenum('10:15:18.500', 'HH:MM:SS.FFF');
% select data in range, and where second column is 'BASE02'
BodyData(dateValues > startTime & dateValues < endTime & strcmp(BodyData(:, 2), 'BASE02'), :)
Returns:
ans =
'10:15:16.332' 'BASE02' 'bar'
'10:15:18.332' 'BASE02' 'foo'
References: datenum manual page, matlab help page on logical indexing.

even two string are same but when compare result are coming false

I am comparing two string.I am reading String 1 i.e expectedResult from excelsheet and String 2 i.e actualResult i am getting from web page by using " getElementByXPath("errorMsg_userPass").getText();
but when i equate two string even though they are same result of comparison are coming false i.e they are not same.
enter image description here
I don't know why it is happening like this .Please Help
use trim() to remove leading and trailing spaces!!
I recommend you looking at the exact bytes of the actual and expected strings. There might be for instance an unbreakable space instead of a regular space and then they will look the same but won't be the same for equals.
You can see the difference by running the following snippet:
String a = new String("a\u00A0b");
String b = new String ("a b");
System.out.println(a + "|" + Arrays.toString(a.getBytes()));
System.out.println(b + "|" + Arrays.toString(b.getBytes()));
Which will output:
a b|[97, -62, -96, 98]
a b|[97, 32, 98]

How do I match a substring of variable length?

I am importing data into my SQL database from an Excel spreadsheet.
The imp table is the imported data, the app table is the existing database table.
app.ReceiptId is formatted as "A" followed by some numbers. Formerly it was 4 digits, but now it may be 4 or 5 digits.
Examples:
A1234
A9876
A10001
imp.ref is a free-text reference field from Excel. It consists of some arbitrary length description, then the ReceiptId, followed by an irrelevant reference number in the format " - BZ-0987654321" (which is sometimes cropped short, or even missing entirely).
Examples:
SHORT DESC A1234 - BZ-0987654321
LONGER DESCRIPTION A9876 - BZ-123
REALLY LONG DESCRIPTION A2345 - B
REALLY REALLY LONG DESCRIPTION A23456
The code below works for a 4-digit ReceiptId, but will not correctly capture a 5-digit one.
UPDATE app
SET
[...]
FROM imp
INNER JOIN app
ON app.ReceiptId = right(right(rtrim(replace(replace(imp.ref,'-',''),'B','')),5)
+ rtrim(left(imp.ref,charindex(' - BZ-',imp.ref))),5)
How can I change the code so it captures either 4 (A1234) or 5 (A12345) digits?
As ughai rightfully wrote in his comment, it's not recommended to use anything other then columns in the on clause of a join.
The reason for that is that using functions prevents sql server for using any indexes on the columns that it might use without the functions.
Therefor, I would suggest adding another column to imp table that will hold the actual ReceiptId and be calculated during the import process itself.
I think the best way of extracting the ReceiptId from the ref column is using substring with patindex, as demonstrated in this fiddle:
SELECT ref,
RTRIM(SUBSTRING(ref, PATINDEX('%A[0-9][0-9][0-9][0-9]%', ref), 6)) As ReceiptId
FROM imp
Update
After the conversation with t-clausen-dk in the comments, I came up with this:
SELECT ref,
CASE WHEN PATINDEX('%[ ]A[0-9][0-9][0-9][0-9][0-9| ]%', ref) > 0
OR PATINDEX('A[0-9][0-9][0-9][0-9][0-9| ]%', ref) = 1 THEN
SUBSTRING(ref, PATINDEX('%A[0-9][0-9][0-9][0-9][0-9| ]%', ref), 6)
ELSE
NULL
END As ReceiptId
FROM imp
fiddle here
This will return null if there is no match,
when a match is a sub string that contains A followed by 4 or 5 digits, separated by spaces from the rest of the string, and can be found at the start, middle or end of the string.
Try this, it will remove all characters before the A[number][number][number][number] and take the first 6 characters after that:
UPDATE app
SET
[...]
FROM imp
INNER JOIN app
ON app.ReceiptId in
(
left(stuff(ref,1, patindex('%A[0-9][0-9][0-9][0-9][ ]%', imp.ref + ' ') - 1, ''), 5),
left(stuff(ref,1, patindex('%A[0-9][0-9][0-9][0-9][0-9][ ]%', imp.ref + ' ') - 1, ''), 6)
)
When using equal, the spaces after is not evaluated

Resources