Пример #1
0
def test_remote_data_service_inst_info():
    ds = RemoteDataService()
    
    res, msg = ds.query_inst_info('000001.SZ', fields='status,selllot,buylot,pricetick,multiplier,product')
    assert res.loc[0, 'multiplier'] == 1
    assert abs(res.loc[0, 'pricetick'] - 0.01) < 1e-2
    assert res.loc[0, 'buylot'] == 100
Пример #2
0
def test_remote_data_service_inst_info():
    ds = RemoteDataService()
    ds.init_from_config()

    sec = '000001.SZ'
    res = ds.query_inst_info(
        sec, fields='status,selllot,buylot,pricetick,multiplier,product')
    assert res.at[sec, 'multiplier'] == 1
    assert abs(res.at[sec, 'pricetick'] - 0.01) < 1e-2
    assert res.at[sec, 'buylot'] == 100
Пример #3
0
class InstManager(object):
    def __init__(self):
        self.data_api = RemoteDataService()
        self.inst_map = {}
        self.load_instruments()
    
    def load_instruments(self):
        fields = ['symbol', 'inst_type', 'market', 'status', 'multiplier']
        res, msg = self.data_api.query_inst_info(symbol='', fields=','.join(fields), inst_type="")
        
        for _, row in res.iterrows():
            inst = Instrument()
            dic = row.to_dict()
            dic = {k: v for k, v in dic.iteritems() if k in fields}
            inst.__dict__.update(dic)
            self.inst_map[inst.symbol] = inst
    
    def get_intruments(self, code):
        return self.inst_map.get(code, None)
Пример #4
0
class InstManager(object):
    def __init__(self, inst_type="", symbol="", data_api=None):
        if data_api is None:
            self.data_api = RemoteDataService()
        else:
            self.data_api = data_api

        self.inst_map = {}
        self.load_instruments(inst_type=inst_type, symbol=symbol)

    def load_instruments(self, inst_type="", symbol=""):
        fields = [
            'symbol', 'inst_type', 'market', 'status', 'multiplier',
            'list_date', 'delist_date'
        ]
        res = self.data_api.query_inst_info(symbol=symbol,
                                            fields=','.join(fields),
                                            inst_type=inst_type)
        res = res.reset_index()

        dic_of_dic = res.to_dict(orient='index')
        res = {
            v['symbol']: {
                v_key: v_value
                for v_key, v_value in v.viewitems() if v_key in fields
            }
            for _, v in dic_of_dic.viewitems()
        }
        for k, v in res.viewitems():
            inst = Instrument()
            inst.__dict__.update(v)
            self.inst_map[k] = inst
        print

    def get_instrument(self, code):
        return self.inst_map.get(code, None)