Working with API – Part 1

Working with API has been a tremendous steep learning curve so far. This is to document the How to work with API.

The example that is shown below is from Gemini API. Part 1 will be the usage of the public API. The Public API does not require authentication to the Gemini Server which means that you will not need to create an API key for this tutorial.

What is an API

There is a comprehensive article on API on medium below.

What is an API

What is REST

There is a comprehensive article on what is REST on medium below.

What is REST

If you TLDR :  Just know that it is simply just an architecture which is stateless,  meaning that the server does not need to know anything about what state the client is in and vice versa. In this way, both the server and the client can understand any message received, even without seeing previous messages.

There are other architecture such as SOAP or GraphQL which some crypto exchanges are using.

Why API?

Why is there a need for an API. Let us go into an example.

  1. When you go into the website : browser knows that you are requesting for this page from and there will be a request to get the page from stackoverflow.
  2. Now go to right click on the web page and click on view page source. The page is rendered like this with the proper alignment etc so the viewer can view the page in human readable format.

browser http request

3. However even though it is in human readable format, for the programmer, or program, there are too many extra things such as the alignment of buttons etc which we do not need if we want to program a software to do automation. These extra stuff are the things which are making it difficult for us to Parse the whole HTML document.

4. So here comes API to the rescue. API is merely something coded at the back end by the server owner to open up some resources back to the querier in machine readable format such as XML or JSON.


5. To start navigating APIs, you will need to know what is the endpoint. Using gemini exchange as an example, You can browse to this link below.

What this means is that Gemini have coded a method that if you tell the computer browser / program to access this end point, it will return the computer some machine readable data.


Let’s try this example. The browser returns back a JSON file which can be easily parsed by a JSON parser program. The Sandbox means it is a test environment for people to play around before deployment to production.

api return JSON


6. For another example, if I want to create an arbitrage bot which checks Gemini for its bid and ask spread. I will need to browse to Gemini API documentation on current book order. I know that the end point is

based on the documentation. However when we try we get a error. The API replies us with the supplied symbol is not a valid symbol. We then know that :symbol is a variable which we need to change to access the correct order book.



7. Let us change the :symbol to ethusd, as we wish to arbitrage eth usd. The program then returns a JSON file which the square brackets is being encapsulated by the Bids are all buy orders. The square brackets encapsulating the Asks are all sell orders. We can then parse this JSON file in our program to create our arbitrage bot.


I will be using Python 3.6 to program the Gemini API connectors etc

The connection to the respective API are created in my Gists. This is just bare connection codes to the respective exchanges, Coinut and Gemini





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s