Trading Cryptocurrencies through APIs

So you’re an advanced cryptocurrency trader or maybe an app developer who wants to seamlessly plug into every major exchange. You have a general understanding of the API landscape, but might not have known the power of using Shrimpy to manage all of your exchange API connections. Keep reading!

In this article, we’ll be showing you how to set up cryptocurrency trading using APIs. This process can be repeated for every major exchange due to the universal developer tools provided by Shrimpy. The alternative being libraries like CCXT, which require you to write custom code for every exchange, manage infrastructure, and scale a farm of servers which executes trades and collects data across every exchange.

Shrimpy vs CCXT: The Case for Centralization in a Decentralized Ecosystem

Create & Connect your API Key

Before we guide you through the steps of API trading, you will need to create exchange API Keys. Detailed instructions on how to generate exchange API keys can be found here.

Linking Bittrex API Keys [Tutorial]

Shrimpy Crypto Trading API

The Shrimpy Universal Crypto Exchange APIs connect to every major exchange. This provides a unified interface to interact with exchanges. Instead of learning the quirks and unique issues of every individual exchange, the Shrimpy Developer APIs can be used to prevent these irregularities.

Instead of managing user API keys and connections to every exchange, developers can directly store API Keys with Shrimpy and even trade on top of Shrimpy’s unified interface.

Our journey begins at the Shrimpy developer APIs.

Shrimpy | Crypto Trading APIs for Developers

Register for your Developer Account

Using the Shrimpy Universal Crypto Exchange API requires you to first register with the Shrimpy developer platform here. It’s free to sign up and everyone gets 10 free credits, which is enough for 10 months of testing the developer APIs.

Create Master API Keys

You will first have to create a new API Master Key to use the Shrimpy API. You must also have Multi-Factor Authentication enabled in Settings.

In the developer dashboard, select Create API Master Key. Verify your account by submitting an API Key request to your email. Complete the email request verification and return to the developer dashboard.

Under API Keys, you should now see a new set of private/public API Keys. These keys communicate with Shrimpy to create users, authorize subscriptions, and execute trades. For security reasons, you will have to verify your account through 2FA again to view the Private API Key. Copy and save both the Public Key and Private Key.

Note: Keep your public and private key secure! The master keys should never be shared with anyone. If you would like users to be able to trade on their own devices, the master keys can be used to generate user keys. The user keys are intended to be shared with users. We will discuss this in more detail in the next sections.

Within your Master API Key Settings, you will be able to add IP Whitelists and enable specific API Key functions, separated into User, Account, and Trade. Let’s go over these functions in detail.

User Settings (Create a User/User API Key)

Create a User

Before you can start trading, we need to create a user who can interact with the exchange. This is easy to do with Shrimpy!

Note: These requests are signed with the master API keys.

Request

POST https://dev-api.shrimpy.io/v1/users

Request Body

{
"name": "customnameforthisuser"
}

Response

{
"id": "701e0d16-1e9e-42c9-b6a1-4cada1f395b8"
}

Create a User API Key

User API Keys can also be created for each user. Unlike Master API Keys, User API Keys are specifically designed to manage an individual user and can be shared with the associated user. This allows them to manage their own personal account with these keys by directly sending requests to Shrimpy.

Multiple exchange accounts can be linked to a single user API key. Therefore allowing one user to manage countless exchange accounts with a single user API key. This user API key can execute trades, collecting account information, or accessing full order book data across every connected exchange.

Note: These requests are signed with the master API keys

Request

POST https://dev-api.shrimpy.io/v1/users/<userId>/keys

Request Example:

POST https://dev-api.shrimpy.io/v1/users/701e0d16-1e9e-42c9-b6a1-4cada1f395b8/keys

Response:

{
"publicKey": "51ac18b7d208f59b3c88acbb1ecefe6ba6be6ea4edc07e7a2450307ddc27ab80",
"privateKey": "85c977ef4070f1deee70192ba7fd5a6caf534f891e4918cfffec11cd6b625e77db4f80347cb436bcaa8882231bacb02f0798a696f101fdd1ef268d66fc63c213"
}

Account Settings

In order to complete setup for trading, we also need to link an exchange account that we’ll be using to trade. Similar to our earlier example, we’ll be using Bittrex as the exchange we want to link.

Note: These requests can be signed with the user API keys.

Connect an Exchange Account

Request

POST https://dev-api.shrimpy.io/v1/users/<userId>/accounts

Request Example

POST https://dev-api.shrimpy.io/v1/users/701e0d16-1e9e-42c9-b6a1-4cada1f395b8/accounts

Request Body

 {
"exchange": "bittrex",
"publicKey": "GOelL5FT6TklPxAzICIQK25aqct52T2lHoKvtcwsFla5sbVXmeePqVJaoXmXI6Qd",
"privateKey": "SelUuFq1sF2zGd97Lmfbb4ghITeziKo9IvM5NltjEdffatRN1N5vfHXIU6dsqRQw",
}

Response

{
"id": 1234
}

Perfect! Now we have our user all set up. Let’s start trading!

Trading

Account Balances

In order to know which assets an account is holding on an exchange, we need to collect balance data. This can be done easily with Shrimpy.

Note: These requests can be signed with user API keys.

Request

GET https://dev-api.shrimpy.io/v1/users/<userId>/accounts/<exchangeAccountId>/balance

Request Example

GET https://dev-api.shrimpy.io/v1/users/701e0d16-1e9e-42c9-b6a1-4cada1f395b8/accounts/123/balance

Response

{
"retrievedAt": "2019-01-09T19:17:33.000Z",
"balances": [
{
"symbol": "KCS",
"nativeValue": 2306,
"btcValue": 0.33486579,
"usdValue": 1327.8775274784
},
{
"symbol": "ETH",
"nativeValue": 4.0e-8,
"btcValue": 1.4960564e-9,
"usdValue": 5.9324652822859e-6
}
]
}

Awesome! It was that simple to get the balances for our exchange account.

Execute Trades

Let’s see how easy it is to perform a trade with Shrimpy. We will use the following endpoint:

Request

POST https://dev-api.shrimpy.io/v1/users/<userId>/accounts/<exchangeAccountId>/trades

This endpoint provides a simple method to execute a single trade through the Shrimpy APIs. All we will need to do is specify the “from” asset, the “to” asset, and the “amount”. With this information, Shrimpy will intelligently route your trades through quote currencies (if necessary) to accomplish the trade.

Note: These requests can be signed with the user API keys.

Request Example

POST https://dev-api.shrimpy.io/v1/users/701e0d16-1e9e-42c9-b6a1-4cada1f395b8/accounts/123/trades

Request Body

{
"fromSymbol": "BTC",
"toSymbol": "ETH",
"amount": "0.01",
}

That’s it! You have now successfully submitted a trade through Shrimpy’s Trading API. Wasn’t that a piece of cake?

Now that we’ve gone through the process to execute a trade, let’s explore some other useful endpoints that are available.

Market Data

Now, you might be wondering how you can execute a trading strategy based on market data. Shrimpy can collect market data based on the complete order book or the ticker. In this example, we will look at the ticker. For order book data, please refer to our API documentation.

Request

GET https://dev-api.shrimpy.io/v1/exchanges/<exchange>/ticker

Request Example

GET https://dev-api.shrimpy.io/v1/exchanges/kucoin/ticker

Response

[
{
"name": "Bitcoin",
"symbol": "BTC",
"priceUsd": "3700.0089335",
"priceBtc": "1",
"percentChange24hUsd": "4.191224354581092",
"lastUpdated": "2018-12-19T22:51:13.000Z"
},
{
"name": "Ethereum",
"symbol": "ETH",
"priceUsd": "100.114205389399",
"priceBtc": "0.027057825",
"percentChange24hUsd": "5.432113558652999",
"lastUpdated": "2018-12-19T22:51:13.000Z"
},
...
]

Start Building

These endpoints should be enough to start building many applications. If you have other features you need, check out the Shrimpy APIs for additional functionality. We support limit orders, open orders, full order book data, and much more. Each of these endpoints have different use cases.

To condense and simplify all of the steps above, we created a flowchart for Shrimpy’s Crypto Trading API below.

Summary

Let’s quickly walk through the steps we took to execute our first trade with Shrimpy.

  • Created a master key through the Shrimpy UI here.
  • Created a user.
  • Created user keys.
  • Linked an exchange.
  • Executed a trade.

Shrimpy API

Shrimpy | Crypto Trading APIs for Developers

Shrimpy offers the most advanced APIs for developers looking to integrate scalable crypto exchange trading functionality into their app.

Shrimpy’s Crypto Trading API was created as a cloud-based solution to address several crypto developer roadblocks including Exchange Trading, Product Scalability, and User Management. With Shrimpy’s API in hand, developers can focus on creating the next era of groundbreaking products that will shape the future of crypto.

Shrimpy’s API is readily compatible with the following exchanges and API endpoints: Binance API, CoinbasePro API, Bittrex API, Kraken API, Gemini API, Poloniex API, Huobi API, KuCoin API, Bibox API, BitMart API, and HitBTC API.

Traders and developers can leverage Shrimpy’s existing trading infrastructure for trading platform/app development instead of having to manage connections to each and every exchange.

Originally posted on blog.shrimpy.io

https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href


Trading Cryptocurrencies through APIs was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.

You may also like...

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: