Coinbase API call to get crypto spot prices - coinbase-api

Just started exploring CoinBase APIs.
I found that
there is a new set of APIs under the umbrella of Coinbase Cloud: https://www.coinbase.com/cloud
there is an older(legacy?) set of APIs known as Coinbase Digital API: https://developers.coinbase.com/
I need to programmatically fetch current spot price for certain cryptocurrencies, I found an endpoint for this in the old API: https://api.coinbase.com/v2/prices/
Is this the correct API call to get the prices?
Is there an equivalent endpoint in one of the new Coinbase Cloud APIs?

you can use the spot price api
https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices#get-spot-price
example: https://api.coinbase.com/v2/prices/BTC-USD/spot
or you can use the ticker api (I think this is the better option)
https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductticker
example: https://api.pro.coinbase.com/products/BTC-USD/ticker

Related

react-geocode - get address from lat/lng with referrer restricted API?

I am trying to use react-geocode to get a user's address from their lat/lng coordinates, but unfortunately I am getting the error API keys with referrer restrictions cannot be used with this API. Is it possible to get react-geocode to use a different API which does allow referrer restrictions? Otherwise how would I go about doing this, as I cannot remove the referrer restrictions for my API key. Is there a way to reverse geocode lat/lng coordinates using the Google Maps API which I am already using to display my map anyway?
import Geocode from "react-geocode";
Geocode.setApiKey("AIzaSyDsb7F-VyBJn7r4LilYH_lRHBpPfgyUga8");
Geocode.enableDebug();
Geocode.fromLatLng("48.8583701", "2.2922926").then(
response => {
const address = response.results[0].formatted_address;
console.log(address);
},
error => {
console.error(error);
}
);
CodeSandbox
If you want to switch to Google Maps, their (reverse) geocoding is pretty straight forward. Obviously you want to get a Google Maps API Key (get it here) to write a GET request:
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY
Parsing the results should be easy. :)
Sources:
https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding
https://developers.google.com/maps/documentation/geocoding/intro#reverse-example
It means Google has blocked access from referrer-restricted API key, and it's very unlikely that Google has two versions of same API with different API restrictions, so you can't use Geocoding API with your restricted key. But you can create other API key with other restrictions applied, i.e. IP restriction.
Did you consider using reverse proxy function of web server? for nginx, you can set it the same to the restricted website configured in your google geo api with command proxy_set_header.
However you have to change the GOOGLE_API to your own webserver here in react-geocode .
Since you've placed a referrer restriction on your API key, it will be limited to executing on the browser with the web service APIs, including the Geocoding API. It didn't work for me even when manually setting the referrer in the request headers. You can find the other web service APIs on this page: https://developers.google.com/maps/web-services/
Important: If you are using any of the web service APIs with an API key that has referer restictions, your requests will fail with the error message: "API keys cannot have referer restrictions when used with this API." You should switch to using a server restriction.
You'll want to create a separate key to use server-side. You can change your restriction from a browser restriction to a server restriction by using IP addresses to restrict access, instead of browser referrers.
Alternatively, you can continue using a browser key and geocode client-side (JavaScript), then return the result to the backend.
You have to add Geocoding API
to your google maps library, and then you can add to your API restrictions for your API key.

Coinbase API keys required for non-auth endpoints?

Using the coinbase API (in Python) to try and get price information for currency pairs. supposedly this endpoint does not require authentication and sure you can get the information from a http request. But if you want to use the Client from coinbase.wallet.client as in the examples, you are forced to provide API keys.
1. Is there another class that can be used to retrieve price data without providing API keys?
2. If you must create an API key for your account, what is the absolute minimum permissions you need to enable on the API key to allow getting price data for currency pairs
For data endpoints in the API, not requiring auth, turns out you can simply pass any string as the api key and the request will succeed.

How can I get media from instagram API?

I'm using the instagram API to get some images related to an specific hastag but when I call the API I get a message saying the API is deprecated.
I'm calling this endpoint
https://api.instagram.com/v1/tags/{tag-name}/media/recent?access_token=ACCESS-TOKEN
Any idea on what call I need to make to return the list of images with the requested hastag?
So I figure out why this is happening. Because the application is still in sandbox mode I can only get hashtag from the accounts that have access. Once the application is approved it will be able to pull the data from the API.

Google Contacts API + API Key + OAuth = 401 Client error

I have an app using Google Contacts API
https://developers.google.com/google-apps/contacts/v3/ through gdata to access user
contacts.
I'm using the gdata library to access it and OpenID+OAuth1 to login and
request authorisation.
Google recently made some changes and now states:
Warning: Due to enhanced security measures we've added to our
infrastructure, all developers using the Contacts API must register their
projects in the API Console <https://code.google.com/apis/console> and
ensure the Contacts API is activated in the API Console.
If your application has certain unusual authorization requirements, such aslogging
in at the same time as requesting data access (hybrid<http://code.google.com/apis/accounts/docs/OpenID.html#oauth>
) or domain-wide delegation of authority (2LO<http://code.google.com/apis/accounts/docs/OAuth.html#GoogleAppsOAuth>
), then you cannot currently use OAuth 2.0 tokens.
In such cases, you must instead use OAuth 1.0 tokens and an API key<http://code.google.com/apis/console-help/#WhatIsKey>
. You can find your application's API key in the GoogleAPI Console<https://code.google.com/apis/console#access>,
in the Simple API Access section of the API Access pane.
How do you set the API key along side the gdata request? (Assuming that the oAuth tokens are all taken care of)?
I've tried:
query = gdata.contacts.service.ContactsQuery(params={'key':'MY_API_KEY'})
query.max_results = 200
feed = googleintegration.contacts_service.GetContactsFeed(query.ToUri())
But I always get back a 401 Client error.
I strongly recommend you get out of OAuth 1 hell and switch over to OAuth 2.0. OAuth 1 is deprecated, for good reasons.

Cloud Endpoints HTTP Cookies

I am implementing Cloud Endpoints with a Python app that uses custom authentication (GAE Sessions) instead of Google Accounts. I need to authenticate the requests coming from the Javascript client, so I would like to have access to the cookie information.
Reading this other question leads me to believe that it is possible, but perhaps not documented. I'm not familiar with the Java side of App Engine, so I'm not quite sure how to translate that snippet into Python. Here is an example of one of my methods:
class EndpointsAPI(remote.Service):
#endpoints.method(Query_In, Donations_Out, path='get/donations',
http_method='GET', name='get.donations')
def get_donations(self, req):
#Authenticate request via cookie
where Query_In and Donations_Out are both ProtoRPC messages (messages.Message). The parameter req in the function is just an instance of Query_In and I didn't find any properties related to HTTP data, however I could be wrong.
First, I would encourage you to try to use OAuth 2.0 from your client as is done in the Tic Tac Toe sample.
Cookies are sent to the server in the Cookie Header and these values are typically set in the WSGI environment with the keys 'HTTP_...' where ... corresponds to the header name:
http = {key: value for key, value in os.environ.iteritems()
if key.lower().startswith('http')}
For cookies, os.getenv('HTTP_COOKIE') will give you the header value you seek. Unfortunately, this doesn't get passed along through Google's API Infrastructure by default.
UPDATE: This has been enabled for Python applications as of version 1.8.0. To send cookies through, specify the following:
from google.appengine.ext.endpoints import api_config
AUTH_CONFIG = api_config.ApiAuth(allow_cookie_auth=True)
#endpoints.api(name='myapi', version='v1', auth=AUTH_CONFIG, ...)
class MyApi(remote.service):
...
This is a (not necessarily comprehensive list) of headers that make it through:
HTTP_AUTHORIZATION
HTTP_REFERER
HTTP_X_APPENGINE_COUNTRY
HTTP_X_APPENGINE_CITYLATLONG
HTTP_ORIGIN
HTTP_ACCEPT_CHARSET
HTTP_ORIGINALMETHOD
HTTP_X_APPENGINE_REGION
HTTP_X_ORIGIN
HTTP_X_REFERER
HTTP_X_JAVASCRIPT_USER_AGENT
HTTP_METHOD
HTTP_HOST
HTTP_CONTENT_TYPE
HTTP_CONTENT_LENGTH
HTTP_X_APPENGINE_PEER
HTTP_ACCEPT
HTTP_USER_AGENT
HTTP_X_APPENGINE_CITY
HTTP_X_CLIENTDETAILS
HTTP_ACCEPT_LANGUAGE
For the Java people who land here. You need to add the following annotation in order to use cookies in endpoints:
#Api(auth = #ApiAuth(allowCookieAuth = AnnotationBoolean.TRUE))
source
(Without that it will work on the local dev server but not on the real GAE instance.)

Resources