Coinbase API: How to get spot-prices of all supported coins - coinbase-api

Is there an API for getting all spot-prices of supported with just one call ?
For now, it seems possible only for each currency pair e.g.) BTC-USD
However, I've found the following API to support it but it's not officially listed on the developer site
https://api.coinbase.com/v2/prices/usd/spot
Can I use this API for getting all price data of all supported coins ?
Thanks

I believe the only way to get the prices for all coins in a single request is to use the exchange-rates endpoint but it gets more than what coinbase trades and since this tells you how much you can get for 1 USD, you have to do the 1/rate math to get the price.
for example
1 ATOM = 1 / 0.04149635869452455 = $24.0985
https://api.coinbase.com/v2/exchange-rates?currency=USD
{
"data": {
"currency": "USD",
"rates": {
"AED": "3.672973",
"AFN": "97.372693",
"ALL": "107.034241",
"AMD": "490.957033",
"ANG": "1.803208",
"AOA": "564",
"ARS": "101.5085",
"AUD": "1.399191",
"AWG": "1.8",
"AZN": "1.700805",
"BAM": "1.729247",
"BBD": "2",
"BDT": "85.824273",
"BGN": "1.72742",
"BHD": "0.377048",
"BIF": "1994.142167",
"BMD": "1",
"BND": "1.366618",
"BOB": "6.898625",
"BRL": "5.552737",
"BSD": "1",
"BTN": "75.524027",
"BWP": "11.716473",
"BYN": "2.536338",
...
}}}
Otherwise you'd probably need to get all the products and get the ticker price for each product but you'd have to throttle it so you don't make to many requests per second.
loop the results from
https://api.exchange.coinbase.com/products
and use
https://api.exchange.coinbase.com/products/{product_id}/ticker
to get the price.

Related

What syntax should be used for reading the final row in an Array on the Mapping tab on the Copy Data activity in Azure Data Factory / Synapse?

I'm using the copy data activity in Azure Data Factory to copy data from an API to our data lake for alerting & reporting purposes. The API response is comprised of multiple complex nested JSON arrays with key-value pairs. The API is updated on a quarter-hourly basis and data is only held for 2 days before falling off the stack. The API adopts an oldest-to-newest record structure and so the newest addition to the array would be the final item in the array as opposed to the first.
My requirement is to copy only the most recent record from the API as opposed to the collection - so the 192th reading or item 191 of the array (with the array starting at 0.)
Due to the nature of the solution, there are times when the API isn't being updated as the sensors that collect and send over the data to the server may not be reachable.
The current solution is triggered every 15 minutes and tries a copy data activity of item 191, then 190, then 189 and so on. After 6 attempts it fails and so the record is missed.
current pipeline structure
I have used the mapping tab to specify the items in the array as follows (copy attempt 1 example):
$['meta']['params']['sensors'][*]['name']
$['meta']['sensorReadings'][*]['readings'][191]['dateTime']
$['meta']['sensorReadings'][*]['readings'][191]['value']
Instead of explicitly referencing the array number, I was wondering if it is possible to reference the last item of the array in the above code?
I understand we can use 0 for the first record however I don't understand how to reference the final item. I've tried the following using the 'last' function but am unsure of how to place it:
$['meta']['sensorReadings'][*]['readings'][last]['dateTime']
$['meta']['sensorReadings'][*]['readings']['last']['dateTime']
last['meta']['sensorReadings'][*]['readings']['dateTime']
$['meta']['sensorReadings'][*]['readings']last['dateTime']
Any help or advice on a better way to proceed would be greatly appreciated.
Can you call your API with a Web activity? If so, this pulls the API result into the data pipeline and then apply ADF functions like last to it.
A simple example calling the UK Gov Bank Holidays API:
This returns a resultset that looks like this:
{
"england-and-wales": {
"division": "england-and-wales",
"events": [
{
"title": "New Year’s Day",
"date": "2017-01-02",
"notes": "Substitute day",
"bunting": true
},
{
"title": "Good Friday",
"date": "2017-04-14",
"notes": "",
"bunting": false
},
{
"title": "Easter Monday",
"date": "2017-04-17",
"notes": "",
"bunting": true
},
... etc
You can now apply the last function to is, e.g. using a Set Variable activity:
#string(last(activity('Web1').output['england-and-wales'].events))
Which yields the last bank holiday of 2023:
{
"name": "varWorking",
"value": "{\"title\":\"Boxing Day\",\"date\":\"2023-12-26\",\"notes\":\"\",\"bunting\":true}"
}
Or
#string(last(activity('Web1').output['england-and-wales'].events).date)

How do I calculate average points scored by a team with a Firebase API resource in a React App?

I'm trying to build a React app to calculate the average points scored of the Raptors basketball team in in it's last N home games.
Assuming that I'm using fetch (url) in the componentDidMount method and I know how to list out the Raptors score when they're the home team with:
componentDidMount() {
let url = "http://localhost:4000/games?homeTeam=Raptors"
fetch(url)
.then(resp => resp.json())
.then(data => {
let myGames = data.map((game, index) => {
return (
<div key={index}>
<h3>{game.homeTeamScore}</h3>
</div>
)
})
this.setState({myGames: myGames});
})
}
and this is the JSON response for http://localhost:4000/games (I'm using json-server to mock the API response as if it was a noSQL Firebase response)
"games": [{
"id": 1,
"date": "2019-05-21",
"homeTeam": "Raptors",
"awayTeam": "Bucks",
"homeTeamPoints": 102,
"awayTeamPoints": 110,
},
{
"id": 2,
"date": "2019-05-20",
"homeTeam": "Lakers",
"awayTeam": "Bucks",
"homeTeamPoints": 102,
"awayTeamPoints": 110,
},
{
"id": 3,
"date": "2019-05-19",
"homeTeam": "Raptors",
"awayTeam": "Warriors",
"homeTeamPoints": 102,
"awayTeamPoints": 110,
}, ... and so on
],
What is the best way for me to get the average of the Raptors points scored in their last 10 home games as of today? What if I want the last 12 home games before a certain date (i.e. April 2, 2019)
Some options that I can think of but don't know how which approach is best is:
Return all Raptors home games, map only the games that I'm interested in an array then calculate the average using javascript on the client side.
Cons of this is what if I want the average of the last 1,000 Raptors home game scores. This does not seem efficient especially if I only want a certain date range of scores.
Create an API resource that allows me to pass in a start date and the number of games. The API will only return Raptors scores for N number of games before that date. This might looks something like: http://localhost.com/teams/raptors/homeGames?sinceDate=20190402&numberGames=20
Cons of this is I'm trying to use Firebase and I'm not sure if this API resource is something that Firebase can do because I don't think Firebase allows parameters to be passed to it to specify the start date or the number of games. Also, if I had /teams/raptors, I would have to have duplicate entries for games under /teams/[opponentTeams]
What's the best way to structure this data? Should I do the aggregations and averages on the client side? Is there something I can do with Google Cloud Functions that will enable more server side logic?
The right answer will be selected based on what is easiest to implement for a newbie to React and Firebase while still fulfilling the requirements above.
If you are storing the date as an timestamp in firebase, then you can use orderby and limit to get the desired result.
firebase.database().ref(endpoint)
.orderByChild('timestamp')
.startAt(Specify the date here)
.limit(100)
.on('value', function(snapshot) {
// You can get the values after the particular date and the result will be limited to first 100
}));
});
Note: date should be in timestamp format not as string. Hope this helps

Here Maps route : get crossed cities

Hello guys!
I'm actually using Here to provide Maps. I'm actually using the routing calculate to calculate de distance between, duration and cities crossed two points. The problem is that the results don't contain any pieces of information about the crossed places.
My Question:
How can I get the crossed Cities / Districts / Countries?
Here is an example:
I made this request here:
https://route.api.here.com/routing/7.2/calculateroute.json?app_id={app_id}&app_code={app_code}&mode=balanced;car;traffic:disabled&waypoint0=geo!48.13642,11.57755&waypoint1=geo!49.45435,11.0735&departure=2018-11-21T10:59:30.640Z&alternatives=5&routeAttributes=routeId&language=fr
And the result was showing something with 26 legs in the route.
Ideas:
One idea was to go through all the Legs and find out which cities they belong to using another API, as those Legs contains Maneuver, which contains Position which is coordinate, but for me, it's too many resources used.
Another Idea was to find out a way of adding metadata about it directly from the request but I didn't find anything about it in the documentation.
So I don't know yet what to do. Any help would be great!
Thanks for reading.
There is no direct way to request this from the Routing service. But there are different possibilities to request further deatails around the route itself:
routeAttributes - Defines which attributes are included in the response as part of the data representation of the route.
legAttributes - Defines which attributes are included in the response as part of the data representation of the route legs.
maneuverAttributes - Defines which attributes are included in the response as part of the data representation of the route
maneuvers.
linkAttributes - Defines which attributes are included in the response as part of the data representation of the route links.
See also here https://developer.here.com/documentation/routing/topics/resource-calculate-route.html
Maybe you can find here the right combination for your use case.
In anyway the Router offers the a summary by country:
&routeattributes=sc
For example (I extended a bit your example to cross a country border):
"summary": {
"distance": 365910,
"trafficTime": 15369,
"baseTime": 14261,
"flags": ["dirtRoad", "tollroad", "noThroughRoad", "tunnel", "motorway", "builtUpArea", "park"],
"text": "Distance du trajet: 366 km, durée: 3h58.",
"travelTime": 14261,
"_type": "RouteSummaryType"
},
"summaryByCountry": [{
"distance": 107955,
"trafficTime": 5821,
"baseTime": 5347,
"flags": ["dirtRoad", "tollroad", "noThroughRoad", "tunnel", "motorway", "builtUpArea"],
"text": "Distance du trajet: 108 km, durée: 1h29.",
"travelTime": 5347,
"country": "AUT",
"tollRoadDistance": 94321,
"_type": "RouteSummaryByCountryType"
}, {
"distance": 257955,
"trafficTime": 9548,
"baseTime": 8914,
"flags": ["motorway", "builtUpArea", "park"],
"text": "Distance du trajet: 258 km, durée: 2h29.",
"travelTime": 8914,
"country": "DEU",
"_type": "RouteSummaryByCountryType"
}]

Obtaining order book information from gdax api

I am trying to obtain order book (buy, sell, volume, price) info from GDAX.
I am familiar with the Bittrex api - specifically this call:
https://bittrex.com/api/v1.1/public/getmarketsummary?market=usdt-eth
which produces the following response:
{
success: true,
message: "",
result: [
{
MarketName: "USDT-ETH",
High: 770,
Low: 729.70000005,
Volume: 12847.90985907,
Last: 752,
BaseVolume: 9641897.74525487,
TimeStamp: "2017-12-27T13:49:29.463",
Bid: 751.99999999,
Ask: 752.9999,
OpenBuyOrders: 2072,
OpenSellOrders: 1933,
PrevDay: 738.99899999,
Created: "2017-04-20T17:26:37.647"
}
]
}
Does anyone know what the equivalent call would be in the gdax api ?
I am using Python and tried out Client.get_product_order_book('ETH-USD')
but its output is limited and the order book seems rather thin.
In [54]: client.get_product_order_book('ETH-USD')
Out[54]:
{'asks': [['756.97', '168.24847073', 8]],
'bids': [['756.96', '77.74495889', 14]],
'sequence': 1810832728}
Based on the docs the call above with level=1 corresponds to the inside
(i.e. best bid and ask prices)
But the output from the Bittrex api seems to be the best bid and ask prices as
well. So does anyone know the difference ?
Does anyone know what the equivalent call would be in the gdax api ?
If you want something similar, a better try would be:
>> client.get_product_24hr_stats('ETH-USD')
>> {
"open": "416.11000000",
"high": "433.83000000",
"low": "410.11000000",
"volume": "91763.71115699",
"last": "432.79000000",
"volume_30day": "4011593.85194549"
}
I am using Python and tried out Client.get_product_order_book('ETH-USD') but its output is limited and the order book seems rather thin.
Level Description
1 Only the best bid and ask
2 Top 50 bids and asks (aggregated)
3 Full order book (non aggregated)
You are calling it with the default level of 1 so you are only getting the lowest ask and the highest bid, only 2, so yes, it's thin. If you need more info, consider calling it with level 2 or 3 according to the snippet above taken from the GDAX official docs. More here.
But the output from the Bittrex api seems to be the best bid and ask prices as well. So does anyone know the difference ?
The difference is that Bittrex only gives you the best bid and ask price while GDAX api gives you the bid/ask price, the total size of all the orders, and the number of orders.

Gmail API how to get labels ThreadsUnread

how can i to get labels ThreadsUnread when excuting LabelsResource.ListRequest?
trying to get the ThreadsUnread property when i'm excuting the Google.Apis.Gmail.v1.UsersResource.LabelsResource.ListRequest
but it comes with null value.
This is my code:
Google.Apis.Gmail.v1.UsersResource.LabelsResource.ListRequest labelReq = service.Users.Labels.List("me");
IList<Google.Apis.Gmail.v1.Data.Label> labels = labelReq.Execute().Labels;
what do i need to ask in the request the ThreadsUnread or MessagesUnread value?
There is a property in the request that called "fields".
it can be set with a string. but where can i find what is the options of that string?
At the time of writing (March, 2019), you cannot get counts when doing a list. You have to subsequently request the details of each label to get the detail. Very slow, costly and frankly unnecessary. The equivalent Microsoft Graph API doesn't have this limitation.
Use the Users.labels.get. In the try-it section do this:
GET https://www.googleapis.com/gmail/v1/users/userId/labels/id
userId:
me
id:
INBOX
and execute, the response would looke something like:
{
"id": "INBOX",
"name": "INBOX",
"messageListVisibility": "hide",
"labelListVisibility": "labelShow",
"type": "system",
"messagesTotal": 1808,
"messagesUnread": 1610,
"threadsTotal": 454,
"threadsUnread": 323
}
and there's the "threadsUnread": 323 you're looking for.

Resources