This bounty is no longer available
Web3 DAO | injectivelabs Logo

Modularize python demo strategy library for better re-use, strategy development, and integration

Organization

injectivelabs

Deadline

over 1 year ago

Status

ENDED

3861.42 USD

INSTRUCTIONS

The Injective python API demo has served as a focal point for algorithmic developers to kickstart integrations with exchange applications and leverage the order-book primitives on the Injective Chain.

While some of these demo strategies are sophisticated enough to be utilized in a production environment, it can be further modularized and refactored to be reusable for traders looking to incorporate into their existing systems.

I noticed that the strategy implementations have numerous overlapping functions and helper objects that can be highly useful for all algorithm developers. A robust, well-abstracted helper and utility library can help reduce some of these strategies down to just a few hundred lines of code!

Suggestion

Structured OOP:

Listener: Manages market-specific streaming and maintains the latest state with easy-to-access market information.

  • Account listener: address and subaccount state with helper functions deriving detailed balances (in margin, in order, and total/available balance), positions, and estimated portfolio value (using external price feed).
  • Spot listener: market related data for 1 specified market: simple orderbook (price,quantity), trade stream, complex orderbook (includes every subaccount's quantity in a single price level) etc...
  • Derivatives listener: similar to spot, except a listener that can stream relevant data for all derivatives markets including perpetuals, expiry futures, and binary options in 1 place.

Executer: Manages message sending and execution with abstract instructions

  • Msg Executer: enables safe account sequence management and various types execution needs
  • Account executer: manages deposit, withdrawal, transfer, bridging
  • Spot executer: executes spot market related actions with abstract instructions
  • Derivatives executer: executes derivatives market related actions with abstract instructions

Executer can start with simple executions and build progressively toward advanced executions from highly abstract instructions. E.g. conversion of model-generated price/quantity to market-compliant ticks and denoms -----> auto-allocation of reduce-only orders in trade instructions, relative abstraction instead of absolute execution, TWAP & iceberg automations.

With these components implemented, an algorithm developer can spend 90% of his time implementing his model and backtesting instead of more than 60% of time building other components.

A spot market-making strategy for e.g. WETH/USDT can now be composed of:

spot listener(WETH/USDT) + account listener (MM address) + external custom data stream -> Model: stoikov -> spot executer (WETH/USDT) and optionally account executer (MM address)

optionally if it includes hedging: derivatives listener (ETH/USDT Perp) -> Model: Hedging -> derivatives executer (ETH/USDT Perp)

Instead of needing to build all of these components, a trader only needs to implement the model and incorporate/setup the relevant executers and listeners based on his needs.

Simple back testing:

There should be a plug-and-play library for developers to easily back-test their strategies with local or sample trade data by simply changing a few lines in their existing codebase.