Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Behavior about filling market order for cmegroup currency future

I run a backtest script on cmegroup currency future and find that i am unable to fill the market order in the following time slot. However, i believe it should work because the cmegroup bid/ask is very narrow (and there should be market maker) and i do not mind to use slightly higher price to fill my order. How can i fix this ? Also, anyone knows when the cmegroup future can be traded from 5PM to 4PM (US central time) ?

At 25 Aug 2015 16:40, issue a market order
In between 25 Aug 2015 16:45 - 16:50, keep checking the order and the order is still not filled
At 25 Aug 2015 16:52, print the last 10 1-minute OHLC and see that there are indeed transactions.

2015-08-26 04:40 handle_data:25 INFO 2015-08-25 16:40:00-04:00 issue market order
2015-08-26 04:45 handle_data:30 INFO 2015-08-25 16:45:00-04:00 order not yet filled
2015-08-26 04:46 handle_data:30 INFO 2015-08-25 16:46:00-04:00 order not yet filled
2015-08-26 04:47 handle_data:30 INFO 2015-08-25 16:47:00-04:00 order not yet filled
2015-08-26 04:48 handle_data:30 INFO 2015-08-25 16:48:00-04:00 order not yet filled
2015-08-26 04:49 handle_data:30 INFO 2015-08-25 16:49:00-04:00 order not yet filled
2015-08-26 04:50 handle_data:30 INFO 2015-08-25 16:50:00-04:00 order not yet filled
2015-08-26 04:52 handle_data:36 INFO 2015-08-25 16:52:00-04:00
2015-08-26 04:52 PRINT close high low open volume
2015-08-25 20:43:00+00:00 1.5686 1.5687 1.5686 1.5687 10.0
2015-08-25 20:44:00+00:00 1.5689 1.5689 1.5684 1.5684 9.0
2015-08-25 20:45:00+00:00 1.5689 1.5690 1.5688 1.5690 9.0
2015-08-25 20:46:00+00:00 1.5689 1.5689 1.5689 1.5689 3.0
2015-08-25 20:47:00+00:00 1.5687 1.5688 1.5687 1.5687 8.0
2015-08-25 20:48:00+00:00 1.5684 1.5686 1.5683 1.5686 14.0
2015-08-25 20:49:00+00:00 1.5685 1.5685 1.5684 1.5684 6.0
2015-08-25 20:50:00+00:00 1.5683 1.5683 1.5683 1.5683 5.0
2015-08-25 20:51:00+00:00 1.5686 1.5687 1.5686 1.5686 12.0
2015-08-25 20:52:00+00:00 1.5685 1.5685 1.5685 1.5685 3.0
This backtest didn't generate any logs.

from datetime import datetime  
import time

def initialize(context):  
    # CMEGROUP POUND/USD Currency Future  
    context.underlying = continuous_future('BP',roll='calendar')  
    context.orderid=0

def handle_data (context,data):  
     fmt = '%Y-%m-%d %H:%M:%S'  
     ordertime = datetime.strptime("2015-08-25 16:40:00", fmt)  
     start = datetime.strptime("2015-08-25 16:45:00", fmt)  
     end = datetime.strptime("2015-08-25 16:50:00", fmt)  
     now = datetime.strptime(str(get_datetime('US/Eastern'))[:-6], fmt)  
     review = datetime.strptime("2015-08-25 16:52:00", fmt)      

     ordertimex = time.mktime(ordertime.timetuple())  
     startx = time.mktime(start.timetuple())  
     endx = time.mktime(end.timetuple())  
     nowx = time.mktime(now.timetuple())  
     reviewx = time.mktime(review.timetuple())  
     if (nowx == ordertimex):  
        log.info(str(get_datetime('US/Eastern')) + " issue market order")  
        context.orderid = order(data.current(context.underlying,'contract'),1)  
     if (endx >= nowx and nowx >= startx):  
        if get_order(context.orderid).status != 1:  
            log.info(str(get_datetime('US/Eastern')) + " order not yet filled")  
        elif get_order(context.orderid).status == 1:  
            log.info(str(get_datetime('US/Eastern')) + " order filled successfully with price " + str(context.portfolio.positions[data.current(context.underlying,'contract')].cost_basis))  
     if (nowx == reviewx):  
        mydata = data.history(context.underlying,['close','high','low','open','volume'],10,'1m')  
        log.info(str(get_datetime('US/Eastern')))  
        print mydata