Esempio n. 1
0
def exec_filter(client_id):
    contract = make_contract('NVDA')
    filt = ExecutionFilter()
    filt.m_clientId = client_id
    filt.m_symbol = contract.m_symbol
    filt.m_secType = contract.m_secType
    filt.m_exchange = contract.m_exchange
    return filt
Esempio n. 2
0
def exec_filter(client_id):
    contract = make_contract('NVDA')
    filt = ExecutionFilter()
    filt.m_clientId = client_id
    filt.m_symbol = contract.m_symbol
    filt.m_secType = contract.m_secType
    filt.m_exchange = contract.m_exchange
    return filt
Esempio n. 3
0
 def exec_filter(self, client_id, accountName, contract):
     filt = ExecutionFilter()
     filt.m_clientId = client_id
     filt.m_acctCode = accountName
     #filt.m_time = "20160122-00:00:00"
     filt.m_symbol = contract.m_symbol
     filt.m_secType = contract.m_secType
     filt.m_exchange = contract.m_exchange
     return filt
Esempio n. 4
0
 def exec_filter(self, client_id, accountName, contract):
     filt = ExecutionFilter()
     filt.m_clientId = client_id
     filt.m_acctCode = accountName
     #filt.m_time = "20160122-00:00:00"
     filt.m_symbol = contract.m_symbol
     filt.m_secType = contract.m_secType
     filt.m_exchange = contract.m_exchange
     return filt    
Esempio n. 5
0
def testExecutions():
    print 'testing executions'
    f = ExecutionFilter()
    #f.m_clientId = 101
    f.m_time = '20110901-00:00:00'
    f.m_symbol = 'SPY'
    f.m_secType = 'STK'
    f.m_exchange = 'SMART'
    #f.m_side = 'BUY'

    con.reqExecutions(f)

    sleep(2)
Esempio n. 6
0
    def get_transactions(self, event, orders):
        import time

        time.sleep(1)
        efilter = ExecutionFilter()
        efilter.m_symbol = event.sid

        for order in orders:

            # Todo: I need to refactor how executions are summoned, this is currently a huge bottleneck
            # cycle through all executions matching the event sid
            for execution in self.executions(efilter):
                prior_execution = None

                # further filter out any executions not matching the order.id
                if execution.m_orderRef == order.id:

                    # prevent processing of duplicate executions
                    if execution != prior_execution:
                        order_status_vals = (0, 0)

                        # cycle through the order status messages to get transaction details
                        for status in self.order_status(execution.m_orderId):

                            # filter out duplicate transaction messages
                            if (status['remaining'],
                                    status['filled']) != order_status_vals:

                                # get execution date
                                date = dt.datetime.strptime(
                                    execution.m_time,
                                    '%Y%m%d %H:%M:%S').replace(tzinfo=pytz.utc)
                                amount = status['filled'] - order_status_vals[1]

                                txn = {
                                    'sid': event.sid,
                                    'amount': int(amount),
                                    'dt': date,
                                    'price': status['lastFillPrice'],
                                    'order_id': order.id
                                }

                                transaction = Transaction(**txn)
                                order_status_vals = (status['remaining'],
                                                     status['filled'])
                                #TODO: pretty sure there is still transactions are being duplicated still
                                if order.status == ORDER_STATUS.OPEN:
                                    yield order, transaction

                    prior_execution = execution
def testExecutions():
    print 'testing executions'
    f = ExecutionFilter()
    #f.m_clientId = 101
    f.m_time = '20110901-00:00:00'
    f.m_symbol = 'SPY'
    f.m_secType = 'STK'
    f.m_exchange = 'SMART'
    #f.m_side = 'BUY'
    
    con.reqExecutions(f)
   
    
    sleep(2)
Esempio n. 8
0
    def get_transactions(self, event, orders):
        import time

        time.sleep(1)
        efilter = ExecutionFilter()
        efilter.m_symbol = event.sid

        for order in orders:

            # Todo: I need to refactor how executions are summoned, this is currently a huge bottleneck
            # cycle through all executions matching the event sid
            for execution in self.executions(efilter):
                prior_execution = None

                # further filter out any executions not matching the order.id
                if execution.m_orderRef == order.id:

                    # prevent processing of duplicate executions
                    if execution != prior_execution:
                        order_status_vals = (0, 0)

                        # cycle through the order status messages to get transaction details
                        for status in self.order_status(execution.m_orderId):

                            # filter out duplicate transaction messages
                            if (status["remaining"], status["filled"]) != order_status_vals:

                                # get execution date
                                date = dt.datetime.strptime(execution.m_time, "%Y%m%d %H:%M:%S").replace(
                                    tzinfo=pytz.utc
                                )
                                amount = status["filled"] - order_status_vals[1]

                                txn = {
                                    "sid": event.sid,
                                    "amount": int(amount),
                                    "dt": date,
                                    "price": status["lastFillPrice"],
                                    "order_id": order.id,
                                }

                                transaction = Transaction(**txn)
                                order_status_vals = (status["remaining"], status["filled"])
                                # TODO: pretty sure there is still transactions are being duplicated still
                                if order.status == ORDER_STATUS.OPEN:
                                    yield order, transaction

                    prior_execution = execution