コード例 #1
0
    def build_chain(self, px, bound, trade_vol):
        self.set_trade_vol(trade_vol)
        undlypx = round(px / self.spd_size) * self.spd_size
        upper_limit = undlypx * (1 + bound)
        lower_limit = undlypx * (1 - bound)

        base_opt_contract = json.loads(
            ContractHelper.object2kvstring(
                self.get_underlying().get_contract()))

        #for i in self.xfrange(int(undlypx), int(upper_limit ), self.spd_size):
        for i in self.xfrange(undlypx, upper_limit, self.spd_size):

            base_opt_contract['m_secType'] = 'OPT'
            base_opt_contract['m_strike'] = i
            base_opt_contract['m_expiry'] = self.expiry
            base_opt_contract['m_right'] = 'C'
            base_opt_contract['m_multiplier'] = self.multiplier
            #self.options.append(ContractHelper.kv2object(base_opt_contract, Contract))
            self.options.append(
                Option(ContractHelper.kv2object(base_opt_contract, Contract)))

            base_opt_contract['m_right'] = 'P'
            #self.options.append(ContractHelper.kv2object(base_opt_contract, Contract))
            self.options.append(
                Option(ContractHelper.kv2object(base_opt_contract, Contract)))

        for i in self.xfrange(undlypx - self.spd_size, lower_limit,
                              -self.spd_size):
            base_opt_contract['m_secType'] = 'OPT'
            base_opt_contract['m_strike'] = i
            base_opt_contract['m_expiry'] = self.expiry
            base_opt_contract['m_right'] = 'C'
            base_opt_contract['m_multiplier'] = self.multiplier
            #self.options.append(ContractHelper.kv2object(base_opt_contract, Contract))
            self.options.append(
                Option(ContractHelper.kv2object(base_opt_contract, Contract)))

            base_opt_contract['m_right'] = 'P'
            #self.options.append(ContractHelper.kv2object(base_opt_contract, Contract))
            self.options.append(
                Option(ContractHelper.kv2object(base_opt_contract, Contract)))
コード例 #2
0
 def tickPrice(self, items):
     try:
         contract = self.tickerMap[items.__dict__['tickerId']]
         field = items.__dict__['field']
         ct = ContractHelper.kv2object(contract, Contract)
         print 'tickPrice>> %s' % ('[%d:%s] %s=%0.4f [%s]' % \
                                     (items.__dict__['tickerId'], ContractHelper.makeRedisKeyEx(ct),\
                                     'bid_q' if field == 1 else ('ask_q' if field == 2 else ('last_q' if field == 4 else field)), \
                                     items.__dict__['price'], datetime.datetime.fromtimestamp(items.__dict__['ts']).strftime('%Y-%m-%d %H:%M:%S.%f')))
     except KeyError:
         print 'tickPrice: keyerror:'
         print items
コード例 #3
0
 def tickSize(self, items):
     try:
         contract = self.tickerMap[items.__dict__['tickerId']]
         field = items.__dict__['field']
         ct = ContractHelper.kv2object(contract, Contract)
         print 'tickSize>> %s' % ('[%d:%s] %s=%0.4f [%s]' % \
                                     (items.__dict__['tickerId'], ContractHelper.makeRedisKeyEx(ct),\
                                     'bid' if field == 0 else ('ask' if field == 3 else ('last' if field == 5 else field)), \
                                     items.__dict__['size'], datetime.datetime.fromtimestamp(items.__dict__['ts']).strftime('%Y-%m-%d %H:%M:%S.%f')))
     except KeyError:
         print 'tickSize: keyerror: (this could happen on the 1st run as the subscription manager sub list is still empty.'
         print items