Exclusive 22% OFF All Quantra by QuantInsti Courses for IBridgePy Users Master algorithmic trading from beginner to advanced — Python for trading, machine learning strategies, options trading, and more.
HUI22 Use HUI22 for 22% off
HUI7 Stack HUI7 for an additional 7% off
Browse Courses →
← Back to Blog

Do you have any feature for scheduling? Which would be similar to Quantopian schedule_function?

May 17, 2017

Scheduling function features in IBridgePy give you full control over when your algorithm trading strategies execute. Unlike platforms limited to US equities, IBridgePy supports custom scheduling for any security or commodity with different trading hours across global markets.

Scheduling function for algorithmic trading automation

No. The main products that quantopian trades are US equities and they have clear market open and close time. Therefore, quantopian provides schedule_function either before market opens or after market closes. In IBridgePy, you can trade any securities or commodities that IB supports and they may have totally different trading hours. The solution is to make your own schedule_functions.

Custom Scheduling Trading Functions Example

Please see the follow example. Something is scheduled before market opens and something else is scheduled after market closes.

def handle_data(context, data):
    sTime=get_datetime() 
    # sTime is the IB server time. 
    if sTime.weekday()<=4:  # Only trade from Mondays to Fridays
        if sTime.hour==9 and sTime.minute==29 and context.machineState=='sleep':
            # schedule actions before market opens at 9:29AM EST
            do_something()
            context.machineState='idle'
        
        if sTime.hour==15 and sTime.minute==59 and context.machineState=='idle':
            # do thing during trading hours
            do_something_else()
            context.machineState='afterTrade'

        if sTime.hour==16 and sTime.minute==10 and context.machineState=='afterTrade':
            display_results()
            context.machineState='sleep'

Learn more from Interactive Brokers platform documentation.