8-Hour Advanced Algo Trading Marathon with Imran ! Only on DhanHQ Youtube

Hi @ROCKY2 ,

There is no direct function available to achieve this. To replay or rewind the option chain data for a particular trading day, the option chain data needs to be continuously stored with timestamps from market open to market close, either in a CSV file or a database. Once the data is stored, it can be replayed or fast-forwarded later for analysis.

Refer to the below pseudo code for the implementation approach.

START

LOGIN to Dhan / Tradehull

SET underlying = "NIFTY"
SET expiry = current_expiry
SET num_strikes = 20
SET interval = 3 seconds

WHILE market is open:

    current_time = now()
    option_chain = get_option_chain(underlying,expiry,num_strikes )

    ADD current_time as snapshot_time in option_chain data
    SAVE option_chain data into CSV / Database
    WAIT interval seconds

END WHILE

REPLAY MODE:

LOAD saved option_chain data from CSV / Database
GET all unique snapshot_time values
SET current_index = 0
SHOW snapshot[current_index]

IF user clicks PLAY:
    WHILE current_index < total_snapshots:
        SHOW snapshot[current_index]
        current_index = current_index + 1
        WAIT replay_speed seconds

IF user clicks NEXT:
    current_index = current_index + 1
    SHOW snapshot[current_index]

IF user clicks PREVIOUS:
    current_index = current_index - 1
    SHOW snapshot[current_index]

IF user clicks FAST_FORWARD:
    current_index = current_index + 10
    SHOW snapshot[current_index]

IF user clicks REWIND:
    current_index = current_index - 10
    SHOW snapshot[current_index]


END
1 Like