Sitemap

Injective API Demo Trading Bot

9 min readJan 31, 2022

Intro

Before I begin, please allow me to introduce myself, I am a loyal Injective community member whose sole purpose in writing these articles is to help educate my fellow #nINJa bros. So, although I do want everyone to gain from API trading, please note that nothing stated here is financial advice! Do your own research before APIng into any of the demo bots with real funds.

Injective is a custom interoperable layer one protocol for building powerful exchange, DeFi, derivatives & Web3 applications. Injective was created using the Cosmos SDK and is able to achieve instant transaction finality while sustaining lightning fast speeds. INJ is the native deflationary scarce asset that powers the Injective Protocol and its rapidly growing ecosystem. Injective is incubated by Binance and is backed by Pantera Capital.

To put simply (in my opinion), the Injective exchange is the decentralised version of Binance. We have all heard of the recycled phase “Not your keys, not your wallet”, well, Injective gives users the option to trade derivatives and spot markets on their exchange directly from their own wallets with no KYC (know your customer) verification required.

In this article, I’ll be going through the Injective API Demo bot which was a really fun learning experience. I was able to edit the bot to perform different strategies while also being able to open my eyes to how API traders can have the competitive edge in such volatile, fast paced market. Some of these advantages include:

  1. Conditional trading strategies which provides plenty of opportunities
  2. 40% exchange fee refunds.

Please note when trading through a relayer such as Injective Pro, the relayer covers your gas fees where as trading via API means you will have to have INJ tokens to pay for your gas fees in every transaction. 1–2 INJ is more than enough for a week’s worth of trading.

Trade and Earn (T&E) Update

Trade and Earn is an incentives programme designed to reward traders on the Injective exchange for providing liquidity. Every epoch, traders are rewarded in INJ tokens based on how much exchange fees they have paid.

With the new and improved distribution mechanisms, wash trading has been substantially reduced meaning more rewards available for organic traders.

I’ve been trading on the exchange since the incentives have been available, averaging 1.16 points per dollar in fees paid when trading on a relayer and ~2 points per dollar in fees paid (due to the 40% fee refund) by trading through API. Below is an example of T&E reward distributions to a trader who paid $100 in fees before and after the anti wash trading measures were put in place:

Estimate results before and after anti-wash procedures

You can clearly see with the new anti wash trading procedures, the trader now receives ~3.5x more rewards compared to before. Also note that for a $100 in fees paid they now receive between $266.26 and $372.76 dependent on which method you use to trade (Trading via relayer vs API). Please also note that this is dependent on the types of orders you execute (maker vs taker) and the market you trade on. The image below shows the current reward boosters for each market.

Current T&E reward boosters.

As a quick summary, the calculations above are only a simple estimate using data from my own experience whilst trading. As volume grows on the Injective exchange, less rewards will be distributed per point. So, knowing this, now seems to be a greater time than ever to begin trading on the Injective exchange considering more INJ distributed per point earned. Not only are the rewards a great incentives to trade, they also provide you the opportunity to take riskier positions as more times than not, you will recover what you lost through T&E rewards (please don’t take this out of context! This only applies to small losses such as 1–2%)

Now that is out the way, let’s go through the 3 available Injective API demo bots.

Injective API Demo Bot

The Injective API Demo can be run on Python or Go. It’s quick and easy to set up! But, if you do get any errors whilst installing then feel free to head over to the Injective API Telegram chat (Injective API TG). Here is the repository link: https://github.com/InjectiveLabs/injective-api-demo

Before running any of the 3 API demo bots, I strongly advise you to use an alternative trading account to test the bot on testnet.injective.exchange. So, let’s begin going through each bot and what it does:

Pure Market Making

This bot executes a simple perpetual market making strategy by placing a bid and ask price dependent on the spread the trader chooses.

Pure perp MM demo configs for demo below

So far, this is the only bot I have tested with real funds and even though I ended up losing some of my initial margin through losing trades and exchange fees, the T&E rewards made up for the loss plus an additional 30% profit! This was due to the bot executing plenty of maker orders whilst running (2.2x rewards on maker orders for perp markets).

Below is a video (GIF) of the Pure Perp Market Making bot in action:

Pure Perp bot running on Mainnet

You can edit this bot to perform different strategies but please only do this if you’re comfortable with coding as it is very easy to do the wrong thing and lose your funds!

Summary:

Pros: Maker orders getting filled leading to greater T&E rewards.

Cons: After running the bot for a week, I’ve noticed it tends to accumulate positions against the direction of the market. So, if the market is going up, it accumulates short position (see image below for an example). Because of this, it’s not something I would recommend to run without active management or a proper thought out strategy.

Risk of running the bot without active management

Mean Reversion

Mean reversion in trading theorizes that prices tend to return to average levels, and extreme price moves are hard to sustain for extended periods. To try and explain this as simple as possible, the strategy involves buying/selling during volatility and then counter trading when price returns to the n-day Simple Moving Average (SMA) price level.

Usually, mean reversion is used in daily time frames compared to this bot which runs in much shorter time frames (the below configs are in 20 windows at 5 seconds each!).

I ran the bot on testnet and didn’t really achieve any good results. This could have possibly been due to skewed price data as there were more volatility than average price action (as someone was clearing the ask orders every hour!).

Before reading on, I highly recommend you take a look at a few Youtube videos showing examples of how Bollinger Bands are calculated, it helps a lot!

Mean Reversion Config file settings

BOLU=MA(TP,n)+mσ[TP,n]

BOLD=MA(TP,n)−mσ[TP,n]

where :

BOLU=Upper Bollinger Band

BOLD=Lower Bollinger Band

MA=Moving average

TP (typical price)=(High+Low+Close)÷3

n=Number of days in smoothing period — In bot’s case, n_window = 20 windows at 5 seconds each. Meaning, the bot will continuously calculate the SMA and standard deviation of the price at the most recent 100 seconds.

m=Number of standard deviations — n_std = 1.5, which is a bit too high for this time frame considering it’s scanning for price changes over the last 20*5 = 100 seconds)

σ[TP,n]=Standard Deviation over last n periods of TP​ (the Standard Deviation of the last n periods)

Once started, the bot will keep looking for signals to execute trades on. If no signal, the bot will hold and wait for the next interval.

Below is an example of what manually trading INJ/USDT would have resulted in whilst using the mean reversion strategy.

Please remember this is not financial advice and risky scenarios such as the line 1 and 2 could occur meaning you will end up in a losing position.

Summary:

Pros: Executes trades during volatility.

Cons: The bot executes taker orders which receive less T&E reward multipliers. Also, risky price action such as lines 1 and 2 in the image above.

Cross Exchange

This is a simplified Injective Protocol-Binance cross-exchange market strategy demo that compares Top of Orderbook (TOB) prices on Injective and Binance.

A change in TOB prices will trigger the following actions:

1. Cancel existing orders:

2. Placing new orders will be one of the following actions:

i. Places one bid order and one ask order on Injective simultaneously, both base asset is greater than minimum base asset balance and quote asset is greater than minimum quote asset balance.

ii. Only places one bid order, if the quote asset balance is greater than the minimum, and the base asset balance is smaller than the minimum base asset balance.

iii. Only places one ask order, if the base asset balance is greater than the minimum, and the quote asset balance is smaller than the minimum quote asset balance.

iv. Do not do anything.

I can’t review this bot as I haven’t tested it myself yet. Once I experiment with it, I will post the results on twitter. For now if you want to try it out, please use a small amount of fees to experiment with.

Final Thoughts

These trading tools gave me an amazing insight towards API trading. I will definitely work on improving my Injective API knowledge and I urge everyone else to do so as well. There are no boundaries to what you can achieve if you take the time to learn this.

Future Methods of providing liquidity

More markets are coming to Injective in the near future for you to take advantage of. On top of the existing bridges we currently have (Ethereum, IBC), the following bridges will be coming which will give traders more markets to trade on:

  1. BSC Bridge
  2. Avax Bridge
  3. Sol Bridge
  4. Dot Bridge

The one I’m really looking forward to is the BSC bridge as this will provide traders the opportunity to directly withdraw from a popular centralised exchange (Binance) and avoid those ridiculous Ethereum gas fees!

The following features are still in research and development (R&D). I can’t provide an estimated time of arrival (ETA) but I can discuss what they may involve and how you can benefit from them.

Trading Guilds

Trading Guilds involve providing access of your funds to a third party such as a market maker or professional trader (or even a friend you trust). So, if you don’t have the technical expertise or time to trade then you could provide access to someone who knows what they’re doing. This will allow you to make passive gains similar to those of an AMM model while also helping increase liquidity on the DEX leading to more volume which in turn will result in greater INJ token burns!

Using Cosmowasm to utilise AMM models

There have been recent open discussion from the Injective labs team over utilising liquidity pools similar to those in AMM models for the Injective exchange markets. There aren’t much detail over how this will be done but, I trust the skills and expertise of the team to pull this off.

Injective Links

Website | Telegram | Discord | Blog | Twitter | Learn | Youtube | Facebook | LinkedIn | Reddit | Instagram | Weibo | Orbit Newsletter

--

--

No responses yet