All About Gemini API: A Complete Guide For Beginners


Source Link: https://algotrading101.com/learn/gemini-api-guide/

Gemini is a regulated cryptocurrency exchange platform that allows users to buy, sell, and store cryptocurrency. If you are into cryptocurrency and want to know more about Gemini and Gemini API, this article is for you.

Gemini API: The Basics

Before digging into how to use the Gemini API, let’s learn the basics first. This section will cover all the basic information about Gemini and the pros and cons of using the API.

What is Gemini and Gemini Dollar?

Gemini is a reliable US-based cryptocurrency exchange platform that lets you buy and sell cryptocurrency. It also allows users to create portfolios around crypto. 

This cryptocurrency platform was founded in 2014 by the Winklevoss twins. Many users admired that platform because it is user-friendly and great for beginners. Users can enjoy Gemini on the web and through mobile apps.

So, what is Gemini Dollar (GUSD)? It is a regulated stablecoin designed for spending, trading, and lending. The Gemini Dollar is also supported by the US dollars held at State Street Bank and Trust Company. So, it can be transferred back to US dollars at a 1:1 rate, anytime.

What is Gemini API?

Gemini API refers to the method where users automatically trade cryptocurrencies on Gemini using codes.

Available clients for the Gemini API are the following:

  • Python
  • JavaScript
  • Java
  • Ruby
  • TypeScript
  • C#
  • Go
  • PHP
Can I use Gemini API for free?

Creating an account is free, but fee schedules are implemented depending on the platform you use. Examples of the fee schedules are the following:

  • Less than $10 – $0.99 fee
  • $10.01 to $25 – $1.49 fee
  • $25.01 to $50 – $1.99 fee
  • $50.01 to $200 – $2.99 fee
  • Over $200 – $1.49% of the total order value

A convenience fee of 0.50% of the current market price of the coin you are buying is also implemented in addition to the transaction fee.

You can also access Gemini’s fee schedule on their website to better understand the fees.

Reasons to use Gemini

Here are the reasons why you should use Gemini:

  • Beginner-friendly; easy to use
  • High-security protocols
  • Provides many platforms
  • Available educational resources
  • Has sandbox for API testing
  • Mobile app available
  • Pay directly using your crypto
Reasons NOT to use Gemini

Here are the reasons why you should NOT use Gemini:

  • Not available in all countries
  • High fees
  • Limited account funding methods
How To Get Started: CoinMarketCap API Guide
Sign-up an Account

To get started, you need to sign up for an account in the Gemini website

Click on the “Get Started” icon and do the sign-up process. Provide all the information needed.

You will be required to provide your phone number for verification purposes. Enter the SMS code and you will see this:

Create API Key

On the Account menu, go to settings.

Click the “Create A New API Key” button. You will receive a key to your phone via SMS. Enter the information and specify what kind of API Key you want.

You can either pick Master API Key or Primary API Key. Choosing Master API Key means you have more options in terms of regulation between your accounts.

You will then get your API keys. Make sure to keep them safe because you won’t get to see the keys again. 

Don’t forget to name your API Key and give it permission in the API Key Settings.

Install Gemini API

Install the library for Gemini APIl using this command:

Gemini’s Public APIs

Here are the public APIs offered by Gemini:

  • Symbols
  • Tickers
  • Candles
  • Price feed
  • Current Order Books
  • Current auction
  • Trade History
  • Auction history
Symbols

To import relevant libraries and get the list of all the symbols that the Gemini API offers, here’s how you do it:

Now, we will create a base for the URL that will remain the same for some of the public API endpoints. Then, we will build a response by adding the symbols specification to the end of the main URL.

In this example, BTC-USD is used.

Ticker

Using the ticker endpoint, check the information related to the recent trading activity.

To get the V2 ticker, do this:

Candle

So, if you want to get the 15-min time interval data, here’s how you do it:

Make sure to change the parameters. You can then arrange the data into a pandas data frame. You can indicate a name for each column of the response.

Next, convert the unix timestamp to normal date and pass it as an index value. Arrange and sort the data accordingly.

Now, calculate the 20 Simple Moving Average (SMA) with this code:

With pandas,

With btalib,

To save the data into a csv format, do this:

Now, using Plotly, create interactive charts. Just specify the type of graph and its components that build the main graph figure.

Current Order Book

To obtain the current order book as two arrays, here’s how you do it:

You can also clean up the data by creating a data frame for each and then merging them.

Merging will be like this:

Trade History

If you want to obtain trade history, remember that the call without a specified timestamp will return the most recent trades. The timestamps are dates that go back to 1970-01-01, and each request can show up to 500 records.

Here are the responses:

  • timestamp – the time that the trade was executed
  • timestamps – the time that the trade was executed in ms
  • tid – trade id number
  • price – the price the trade was executed at
  • amount –    the amount that was traded
  • exchange – always Gemini
  • type – the type of trade (buy, sell, auction, block)
  • broken – broken trades aren’t included in a default call

Make a request following this:

Current Auction

To get the current auction for a symbol, follow this:

Auction History

For auction history, do this:

Price Feed

For price feed, use this:

How to Place Orders with Gemini API

Here is how to properly and securely launch orders with Gemini API. We will launch a trade on ETH when BTC hits a certain price.

The platform has a “nonce” feature, a number that must not be repeated and must be increased between order requests. Here is how you set up a nonce.

So, we will buy 5 ETH when BTC reaches $37900.00. You need to specify the order payload that will carry the main order requirement.

Gemini does not support direct market orders, so users should go around this using the “immediate-or-cancel” execution option and an aggressive limit price.

Here’s how to encode the payload and set up the signature:

Then, set up the headers for the order.

Add it all together and look for the specified BTC price in dollars. So, if the price is reached, the order will launch. If otherwise, the loop will continue.

For the next example, we will execute an ETH trade when BTC moves 5% in the last 5 minutes. So, if it hits less than 5%, the program will sleep for 5 minutes and recalculate.  The trade will execute if the percentage change is equal to or more than 5%.

Here is the loop:

How to Cancel Orders

You can cancel orders by doing this:

To cancel all sessions, write this:

To cancel all active orders, do this:

How to Order Execution Options
  • make-or-cancel – This order only adds liquidity to the order book. If something is not provided immediately, the order will be canceled.
  • immediate-or-cancel – This will remove liquidity from the order book. It will fill whatever part of the order it can immediately and cancel the remaining amount. This will prevent the order from being added to another book.
  • fill-or-kill – It removes liquidity from the order book. It will fill the entire order immediately or cancel the order.
  • auction-only – It will be added to the auction-only book for the next auction.
  • indication-of-interest – It is a request for liquidity from block trading market-makers for a specified symbol.
How to Get Notional and Trade Volumes

Here’s how you code the notional volume request:

To get the trade volumes, follow this:

How to Use the Gemini Clearing Orders

With Gemini clearing endpoint allows two parties to conduct a trade-off. The initiator enters the trade details for a specified symbol and creates a trade_id.

Remember, only the counterparty can confirm the order if a counterparty_id is supplied. If not supplied, the ticket will generate a trade_id, and any counterparty can fill it in.

Here is how to use Gemini clearing orders:

How to Use Fund Management APIs

Here is how to use Fund Management APIs from Gemini:

To withdraw your funds, do this:

Heartbeat Function from Gemini API

The heartbeat function prevents a session from timing out and canceling orders if the required heartbeat flag has bet properly set. To set up the heartbeat, change the payload to:

Note: Access the full code from this GitHub link.

want to learn how to algo trade so you can remove all emotions from trading and automate it 100%? click below to join the free discord and then join the bootcamp to get started today.


Leave a Reply

Your email address will not be published. Required fields are marked *