Skip to content

This is a Delta Neutral strategy on OKX for the following pairs, BTCUSDT, ETHUSDT & SOLUSDT

Notifications You must be signed in to change notification settings

SaloniLL/Delta-NeutralHedge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Delta-NeutralHedge

This project implements a Delta Neutral Hedging Strategy on OKX for trading pairs BTC-USDT, ETH-USDT, and SOL-USDT. It simultaneously trades spot and perpetual swap contracts to hedge price risk while capturing funding rate differentials.


Overview of main.py

main.py is the entry point of the strategy. Its core responsibilities include:

  • Tracking Basis and Volatility:
    Using the configured pairs, the script calculates the basis (price difference between spot and perpetual contracts) and tracks recent volatility and funding rates.

  • Adaptive Position Sizing and Allocation:
    It applies statistical methods to adaptively size positions based on historical basis and volatility, allocating capital across pairs proportionally.

  • Asynchronous Funding Event Listener:
    The script runs an async listener (funding_listener) that receives live funding rate updates via WebSocket. On each funding event, it:

    • Computes updated basis values.
    • Evaluates if conditions meet thresholds to open delta-neutral positions (long spot, short perp).
    • Opens hedged positions using the open_position function.
    • Logs all relevant events, errors, and state changes through a dual logger system (JSON and CSV).
  • Robust Logging & Error Handling:
    The logger records info, warnings, and errors during runtime, enabling traceability and debugging.


How It Works

  1. The script maintains a tracker for basis and funding rates per pair.
  2. Upon receiving funding rate updates, it calculates an adaptive threshold for basis.
  3. If the basis exceeds the threshold and no position is open for that pair, it allocates a size and opens a hedged position.
  4. Positions are sized based on confidence derived from the basis relative to volatility.
  5. The script continuously listens to funding updates and dynamically manages positions.

Requirements

  • Python 3.7+
  • Dependencies: numpy, asyncio, plus the custom modules (config.py, strategy.py, logger_setup.py, ws_client.py)
  • OKX API credentials stored securely (e.g., .env file)

About

This is a Delta Neutral strategy on OKX for the following pairs, BTCUSDT, ETHUSDT & SOLUSDT

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages