Final report - Arbitrum and GMX Python tooling for onchain trading

We have released the CCXT and FreqTrade adapters for GMX. Now you can do algorithmic trading on your favourite decentralised futures exchange.

Purpose

The goal was to enable algorithmic trading on GMX using familiar tools algorithmic traders use on centralised exchanges. Some of the most adapted packages for this purpose are the CCXT connector middleware and the FreqTrade framework integration for backtesting and live execution of algorithmic strategies.

Both the CCXT adapter and the FreqTrade integration are now available for GMX.

Milestone 2: Delivered items

Milestone 2 was: CCXT is the top software library that algorithmic traders use to connect with different perpetual exchanges for trading. CCXT is used by 1,000+ traders and proprietary trading firms. We’d like to write a GMX adapter that allows CCXT users to connect to GMX as they connect to any other exchange.

The following have been delivered as part of the grant:

Milestone 3: Promotion and Twitter spaces

Milestone 3 was: Closing up the project and writing promotional, the post-mortem blog posts and hosting Twitter Spaces.

  • The blog post is here
  • For promotional Twitter spaces, we still need to get a contact from the Arbitrum DAO who helps us to organise this, and this is pending us getting this organised

Extra milestones

Bonus we delivered

  • GMX data collector: we developed an additional infrastructure application to get higher-quality data out of GMX markets for backtesting of algorithmic strategies (more on this later)
  • The adapter has been updated to the latest GMX 2.2 version (recently released)

Bonus we could not get (was not part of the grant)

  • CCXT baseline merge: currently stuck. This was not part of the grant, but something we wish would happen. The current open-source module works as a drop-in replacement until the CCXT team is ready to maintain the GMX adapter as part of the baseline.
  • We have discussed with other projects that have received the official CCXT baseline status for their adapter, and there is usually a payment involved to the CCXT team.
  • Our proposal is for GMX to promote and link to the current GitHub repository in their documentation until/if CCXT is open to considering this adapter as part of their project. Because it is a drop-in replacement

Live trading on GMX

For all exchange adapters, middleware, and trading algorithms, the devil is in the details. The only way to build trading software is to trade with the software.

Trading Strategy deployed a directional trading vault which trades on GMX. It has been running for a few months in so-called forward testing.

  • This directional strategy combines mean reversion, trend following, and short-term BTC/ETH price prediction into a multi-strategy approach.
  • The vault is deployed on the Lagoon vault protocol, taking trades directly on GMX
  • Due to onchain nature of GMX, any of the multiple vault protocols can take positions on GMX, unlike other exchanges that often need a centralised custodian to deposit and withdraw assets in the exchange

The returns have hovered between 0% and 30% annually since the strategy launch. During forward testing, we identified and addressed numerous execution issues (more below). Both live trade execution and strategy performance are reaching a level of quality at which we will feel comfortable opening this vault to the public.

During the forward testing period, you can find ~1000 onchain transactions for trades on this rebalancer address.

Developing trading algorithms for GMX

You can now develop trading algorithms for GMX as you would do for any FreqTrade-supported exchange.

We provide a tutorial here for a basic ADX-based breakout strategy.

You can find the tutorial here.

Trading firm adoption

Some trading firms have privately expressed interest in trading on GMX. However, the GMX’s 4 bps/6 bps fee structure is not always competitive for their strategies.

Because of GMX’s AMM nature, it does not have an internal price; instead, it uses a special fee structure in which the trade fee depends on whether you increase or decrease the open interest. This may make GMX attractive for certain funding-rate strategies, but it also makes it more difficult to run existing strategies built for more conventional exchanges.

As competition among new perpetual futures exchanges heats up, many newcomers are offering very attractive fee and airdrop schemes. This has hurt GMX, known for its deep liquidity for major coins like BTC and ETH. The real-world asset (RWA) boom has also changed the market landscape: as of this writing, GMX offers six TradFi assets.

Quality and testing

Our GMX directional vault on Arbitrum has executed 1000+ orders across ~100 positions. All packages include a continuous integration test suite to ensure that future maintenance work can be delivered easily.

Challenges and lessons learnt

The actual onchain smart contract execution for GMX is robust and quite easy to manage. There have been some other gaps that may make algorithmic trading on GMX difficult.

  • Offchain data was not readily accessible: At the time of our integration, GMX market data required more integration work than conventional exchange feeds. Data was distributed across its APIs, GraphQL indexer and onchain Reader contracts rather than exposed through a single standardised exchange interface. GMX also does not use a single oracle source for every market: Chainlink Data Streams are the primary source for most tokens, while other configured providers may be used as well. Standardised live and historical data are critical for algorithmic trading, so we developed an additional GMX data collector to normalise these sources.
  • GMX’s accounting and business logic differ from those of other exchanges in some unexpected ways. By default, profits from long positions are paid in the market’s long pool token. For example, profits from a BTC/USD long backed by WBTC and USDC may be paid in WBTC unless they are explicitly swapped into another token.
  • GMX offers various trading-pair denominations; GMX perpetual markets are USD-denominated, but they are not simple base-and-quote pairs. Each market has an index token, a long pool token, a short pool token and a collateral token. Depending on the collateral deposited and the desired receive token, opening or closing a position may involve additional token swaps.

If you need any help with FreqTrade, CCXT or GMX, please hop into our Discord. We are happy to answer any questions that technical integrators may have