Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ericxor61a0c0d opened this issue Dec 1, 2022 · 4 comments

Comments

@ericxor61a0c0d
Copy link
Contributor

ericxor61a0c0d commented Dec 1, 2022

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.

@BowTiedHeron
Copy link

I noticed your bounty on OpenQ for this issue. Happy to connect you with a dev that is able to help you out with this!
Are you still planning to fund this bounty when you find a contributor? @ericxor61a0c0d

@boyin0x
Copy link

boyin0x commented Dec 19, 2022

Hi @BowTiedHeron, I'm currently working on it. I got approved by @ericxor61a0c0d to work on it on gitcoin bounties.

@ericxor61a0c0d
Copy link
Contributor Author

@boyin0x what's the best way to talk to you? Feel free to drop relevant handles :)

@relaxed04
Copy link

@ericxor61a0c0d Hi Eric, I submitted a proposal for this work on gitcoin. Let me know your thoughts, I can take this to the finish line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants