Пример #1
0
def fetch_quote(symbols=None):
    expiry_dates = []
    notes = []
    opt_prices = []
    call_asks = []
    call_bids = []
    put_asks = []
    put_bids = []
    ss = []
    exchanges = []

    for expiry_date, note in zip(dates(datetime.date.today()),
                                 '5T 10T 30C'.split()):
        if note in '5T 10T'.split(): continue

        url = 'http://dsdx.shcifco.com:10084/shcifco_option/custom/atm.json'

        params = {'qryDay': expiry_date.replace('-', '')}

        r = requests.post(url, data=params)

        if r.ok:
            for item in r.json():
                symbol = replace_expiry_month(item['instrumentId'])
                exchange = market.exchange(symbol)
                opt_price = float(item['lastprice'])
                call_bid0 = float(item['absBuyPrice'])
                call_ask0 = float(item['absSalePrice'])
                put_bid0 = float(item['absBuyPrice'])
                put_ask0 = float(item['absSalePrice'])

                opt_prices.append(opt_price)
                call_asks.append(call_ask0)
                call_bids.append(call_bid0)
                put_asks.append(put_ask0)
                put_bids.append(put_bid0)
                exchanges.append(exchange)
                ss.append(replace_expiry_month(symbol))

                expiry_dates.append(expiry_date)

                notes.append(note)

    return pd.DataFrame({
        'exchange': exchanges,
        'symbol': ss,
        'time': [datetime.datetime.now()] * len(ss),
        'expiry_date': expiry_dates,
        'note': notes,
        'opt_price': opt_prices,
        'call_ask': call_asks,
        'call_bid': call_bids,
        'put_ask': put_asks,
        'put_bid': put_bids,
        'rate': [1] * len(ss)
    })
Пример #2
0
def fetch_quote(symbols):
    assert type(symbols) is list

    exchanges = []
    ss = []
    notes = []
    expiry_dates = []
    bid_vols = []
    bid_pcts = []
    ask_vols = []
    ask_pcts = []

    header = {
        'accept-encoding': 'gzip, deflate, br',
        'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
        'user-agent':
        'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/71.0.3578.80 Chrome/71.0.3578.80 Safari/537.36',
        'accept': 'application/json',
        'referer': 'https://otc.mycapital.net/oop/pricing-management2.html',
        'authority': 'otc.mycapital.net',
        'cookie': cookie
    }

    r = requests.get(
        'https://otc.mycapital.net/api/v1/otc_lw/atm_option/pricing?show_diff=true',
        headers=header)

    quote_date = None

    if r.ok:
        if r.json()['code'] == 0:
            quote_date = r.json()['data']['date']
            for datas in r.json()['data']['pricing']:
                for data in datas['rows']:
                    # print datas
                    # print '\n', data
                    expiry_date = bid_vol = bid_pct = ask_vol = ask_pct = None

                    symbol = utils.replace_expiry_month(data['contract'])

                    bid_vol = data['atm_bid_vol']
                    bid_pct = data['atm_bid_percentage']

                    ask_vol = data['atm_ask_vol']
                    ask_pct = data['atm_ask_percentage']
                    expiry_date = data['maturity']

                    bid_vols.append(bid_vol)
                    bid_pcts.append(bid_pct)
                    ask_vols.append(ask_vol)
                    ask_pcts.append(ask_pct)
                    expiry_dates.append(expiry_date)
                    ss.append(symbol)
                    notes.append('30C')
                    exchanges.append(market.exchange(symbol))

    close_prices = [
        close_price(symbol, last_settlement_date()) for symbol in ss
    ]
    bids = [mul(pct, price) for pct, price in zip(bid_pcts, close_prices)]
    asks = [mul(pct, price) for pct, price in zip(ask_pcts, close_prices)]

    return pd.DataFrame({
        'exchange': exchanges,
        'symbol': ss,
        'quote_date': [quote_date] * len(ss),
        'expiry_date': expiry_dates,
        'time': [datetime.datetime.now()] * len(ss),
        'note': notes,
        'bid_vol_src': bid_vols,
        'bid_pct': bid_pcts,
        'ask_vol_src': ask_vols,
        'ask_pct': ask_pcts,
        'opt_price': close_prices,
        'call_bid': bids,
        'call_ask': asks,
        'put_bid': bids,
        'put_ask': asks,
        'rate': [1] * len(ss)
    })
Пример #3
0
def fetch_quote(symbols):
    assert type(symbols) is list

    expiry_dates = []
    notes = []
    opt_prices = []
    call_asks = []
    call_bids = []
    put_asks = []
    put_bids = []
    ss = []
    exchanges = []

    for expiry_date, note in zip(dates(datetime.date.today()),
                                 '5T 10T 30C'.split()):
        if note in '5T 10T'.split(): continue

        r = requests.get('http://www.jhotc.com/QuoteList')
        if not r.ok:
            return False, None

        trs = []
        soup = BeautifulSoup(r.content, 'lxml')
        for index, tr in enumerate(soup.find_all('tr')):
            if index < 3: continue
            trs.append(tr)

        for symbol, tr in zip(symbols, trs):
            tds = tr.find_all('td')

            opt_price = float(tds[2].get_text())
            call_bid0 = float(tds[1].get_text())
            call_ask0 = float(tds[0].get_text())
            put_bid0 = float(tds[4].get_text())
            put_ask0 = float(tds[3].get_text())
            exchange = market.exchange(symbol)

            opt_prices.append(opt_price)
            call_asks.append(call_ask0)
            call_bids.append(call_bid0)
            put_asks.append(put_ask0)
            put_bids.append(put_bid0)
            exchanges.append(exchange)
            ss.append(replace_expiry_month(symbol))

            expiry_dates.append(expiry_date)

            notes.append('30C')

    return pd.DataFrame({
        'exchange': exchanges,
        'symbol': ss,
        'time': [datetime.datetime.now()] * len(ss),
        'expiry_date': expiry_dates,
        'note': notes,
        'opt_price': opt_prices,
        'call_ask': call_asks,
        'call_bid': call_bids,
        'put_ask': put_asks,
        'put_bid': put_bids,
        'rate': [1] * len(ss)
    })
Пример #4
0
def fetch_quote(symbols):
    assert type(symbols) is list

    expiry_dates = []
    notes = []
    opt_prices = []
    call_asks = []
    call_bids = []
    put_asks = []
    put_bids = []
    ss = []
    exchanges = []

    params = []
    http_headers = []

    urls = []
    for symbol in symbols:
        for expiry_date, note in zip(dates(datetime.date.today()),
                                     '5T 10T 30C'.split()):
            header = {
                'Origin': 'https://xinhu.tongyuquant.com:9140',
                'Accept-Encoding': 'gzip, deflate, br',
                'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
                'User-Agent':
                'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/70.0.3538.77 Chrome/70.0.3538.77 Safari/537.36',
                'Content-Type': 'application/x-www-form-urlencoded',
                'Accept': 'application/json, text/plain, */*',
                'Referer':
                'https://xinhu.tongyuquant.com:9140/option?code=%s' % symbol,
                'Connection': 'keep-alive'
            }

            http_headers.append(header)

            data = {
                "method": "tQuoting",
                "params": {
                    "underlying": symbol,
                    "expireDate": expiry_date,
                    "optionName": "euro"
                }
            }
            param = urlencode({'json': json.dumps(data)})
            params.append(param)
            url = 'https://xinhu.tongyuquant.com/bct/quote'
            urls.append(url)
            exchanges.append(market.exchange(symbol))
            ss.append(replace_expiry_month(symbol))
            expiry_dates.append(expiry_date)
            notes.append(note)

    http_requests = (grequests.post(
        url, headers=headers,
        data=param) for url, headers, param in zip(urls, http_headers, params))
    http_responses = grequests.map(http_requests,
                                   size=18,
                                   exception_handler=on_error)

    for r in http_responses:
        opt_price = call_bid0 = call_ask0 = put_bid0 = put_ask0 = None
        if r.ok:
            data = r.json()

            if data['success'] == True:
                if data['data'] != None:
                    price_levels = data['data']['quotingUnits']
                    index = int(len(price_levels) * 0.5)
                    price_level = price_levels[index]

                    opt_price = float(data['data']['spot'])
                    call_bid0 = float(price_level['buyCall'])
                    call_ask0 = float(price_level['sellCall'])
                    put_bid0 = float(price_level['buyPut'])
                    put_ask0 = float(price_level['sellPut'])

        opt_prices.append(opt_price)
        call_asks.append(call_bid0)
        call_bids.append(call_ask0)
        put_asks.append(put_bid0)
        put_bids.append(put_ask0)

    return pd.DataFrame({
        'exchange': exchanges,
        'symbol': ss,
        'time': [datetime.datetime.now()] * len(ss),
        'expiry_date': expiry_dates,
        'note': notes,
        'opt_price': opt_prices,
        'call_ask': call_asks,
        'call_bid': call_bids,
        'put_ask': put_asks,
        'put_bid': put_bids,
        'rate': [1] * len(ss)
    })
Пример #5
0
def fetch_quote(symbols):
    assert type(symbols) is list

    expiry_dates = []
    notes = []
    opt_prices = []
    call_asks = []
    call_bids = []
    put_asks = []
    put_bids = []
    ss = []
    exchanges = []

    begin_date = getExpiryByShift(datetime.date.today(), 9, 'T',
                                  getHolidays()).strftime("%Y-%m-%d")
    #print 'begin_date', begin_date

    for expiry_date, note in zip(dates(datetime.date.today()),
                                 '5T 10T 30C'.split()):
        if expiry_date > begin_date:

            encrypt_date = aes.encrypt(expiry_date, encrypt_key)
            encrypt_date = urlencode({'valueDate': encrypt_date})
            url = 'http://101.95.0.114:8092/quotation/atMoneyOptionQuotes?' + encrypt_date

            r = requests.post(url)

            opt_price = call_bid0 = call_ask0 = put_bid0 = put_ask0 = None

            if r.ok:
                #print r.content

                data = json.loads(
                    aes.decrypt(r.json()['msgContent'], decrypt_key))
                #print data

                for item in data:
                    opt_price = float(item['spotPrice'])
                    call_bid0 = float(item['buyOptionPrice'])
                    call_ask0 = float(item['sellOptionPrice'])
                    put_bid0 = float(item['buyOptionPrice'])
                    put_ask0 = float(item['sellOptionPrice'])

                    exchanges.append(item['marketCode'])
                    symbol = item['underlyingCode']

                    opt_prices.append(opt_price)
                    call_asks.append(call_ask0)
                    call_bids.append(call_bid0)
                    put_asks.append(put_ask0)
                    put_bids.append(put_bid0)
                    ss.append(replace_expiry_month(symbol))

                    expiry_dates.append(expiry_date)
                    notes.append(note)

    return pd.DataFrame({
        'exchange': exchanges,
        'symbol': ss,
        'time': [datetime.datetime.now()] * len(ss),
        'expiry_date': expiry_dates,
        'note': notes,
        'opt_price': opt_prices,
        'call_ask': call_asks,
        'call_bid': call_bids,
        'put_ask': put_asks,
        'put_bid': put_bids,
        'rate': [1] * len(ss)
    })
Пример #6
0
def fetch_quote(symbols):
    assert type(symbols) is list

    expiry_dates = []
    notes = []
    opt_prices = []
    call_asks = []
    call_bids = []
    put_asks = []
    put_bids = []
    ss = []
    exchanges = []

    urls = []

    for symbol in symbols:
        for expiry_date, note in zip(dates(datetime.date.today()),
                                     '5T 10T 30C'.split()):
            url = 'http://www.lzqh.net.cn/rest/weixin/getOptionPrice?contractcode=%s&expiryDate=%s' % (
                symbol, expiry_date)
            urls.append(url)
            exchanges.append(market.exchange(symbol))
            ss.append(replace_expiry_month(symbol))  # M905 -> M1905
            expiry_dates.append(expiry_date)
            notes.append(note)

    http_requests = (grequests.get(url) for url in urls)
    http_responses = grequests.map(http_requests,
                                   size=18,
                                   exception_handler=on_error)

    for r in http_responses:
        opt_price = call_bid0 = call_ask0 = put_bid0 = put_ask0 = None

        if r.ok:
            data = r.json()

            if data['success'] == True:
                price_levels = data["obj"]["priceList"]
                index = int(len(price_levels) * 0.5)
                #print index
                price_level = price_levels[index]

                #assert len(price_levels) == 11

                opt_price = float(price_level['optPrice'])
                call_bid0 = float(price_level['call1'])
                call_ask0 = float(price_level['call2'])
                put_bid0 = float(price_level['put1'])
                put_ask0 = float(price_level['put2'])

        opt_prices.append(opt_price)
        call_asks.append(call_ask0)
        call_bids.append(call_bid0)
        put_asks.append(put_ask0)
        put_bids.append(put_bid0)

    return pd.DataFrame({
        'exchange': exchanges,
        'symbol': ss,
        'time': [datetime.datetime.now()] * len(ss),
        'expiry_date': expiry_dates,
        'note': notes,
        'opt_price': opt_prices,
        'call_ask': call_asks,
        'call_bid': call_bids,
        'put_ask': put_asks,
        'put_bid': put_bids,
        'rate': [1] * len(ss)
    })
Пример #7
0
def fetch_quote(symbols):
    expiry_dates = []
    notes = []
    opt_prices = []
    call_asks = []
    call_bids = []
    put_asks = []
    put_bids = []
    symbols = symbols
    exchanges = []

    headers = {
        'Origin': 'http://wx.cnzsqh.com',
        'Accept-Encoding': 'gzip, deflate',
        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
        'User-Agent':
        'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/71.0.3578.98 Chrome/71.0.3578.98 Safari/537.36',
        'Content-type': 'application/x-www-form-urlencoded',
        'Accept': '*/*',
        'Referer':
        'http://wx.cnzsqh.com/QDQuest_page/weixin/pages-react/index.html',
        #'Cookie': 'token=59bea888-d99c-4076-9e58-612bb2526e9d; expire_time=20190123184204',
        'Cookie': 'token=59bea888-d99c-4076-9e58-612bb2526e9d',
        'Connection': 'keep-alive'
    }

    for expiry_date, note in zip(dates(datetime.date.today()),
                                 '5T 10T 30C'.split()):
        if note == '5T': continue

        url = 'http://wx.cnzsqh.com/QDQuest/service/weixinService/queryOptions'
        params = 'params=["%s"]' % expiry_date.replace('-', '')

        r = requests.post(url, headers=headers, data=params)
        if not r.ok:
            continue

        datas = r.json()
        if datas['errorCode'] != 0: continue

        for price_level in json.loads(datas['data']):
            exchange = price_level['exchId']
            symbol = price_level['instrumentId']

            opt_price = float(price_level['underlyingPrice'])
            call_bid0 = float(price_level['askPrice'])
            call_ask0 = float(price_level['bidPrice'])
            put_bid0 = float(price_level['askPrice'])
            put_ask0 = float(price_level['bidPrice'])

            opt_prices.append(opt_price)
            call_asks.append(call_bid0)
            call_bids.append(call_ask0)
            put_asks.append(put_bid0)
            put_bids.append(put_ask0)

            symbols.append(replace_expiry_month(symbol))
            expiry_dates.append(expiry_date)
            notes.append(note)
            exchanges.append(exchange)

    return pd.DataFrame({
        'exchange': exchanges,
        'symbol': symbols,
        'time': [datetime.datetime.now()] * len(symbols),
        'expiry_date': expiry_dates,
        'note': notes,
        'opt_price': opt_prices,
        'call_ask': call_asks,
        'call_bid': call_bids,
        'put_ask': put_asks,
        'put_bid': put_bids,
        'rate': [1] * len(symbols)
    })
Пример #8
0
def fetch_quote(symbols):
    assert type(symbols) is list

    expiry_dates = []
    notes = []
    opt_prices = []
    call_asks = []
    call_bids = []
    put_asks = []
    put_bids = []
    ss = []
    exchanges = []

    urls = []

    start_date = begin_date()
    #print 'start_date', start_date

    for symbol in symbols:
        for expiry_date, note in zip(dates(datetime.date.today()),
                                     '5T 10T 30C'.split()):
            url = 'http://rh.dzqh.com.cn/RefreshPrice/?TargetCode=%s&EndDate=%s' % (
                symbol, expiry_date)
            #print url
            urls.append(url)
            exchanges.append(market.exchange(symbol))
            ss.append(utils.replace_expiry_month(symbol))
            expiry_dates.append(expiry_date)
            notes.append(note)

    http_requests = (grequests.get(url) for url in urls)
    http_responses = grequests.map(http_requests,
                                   size=12,
                                   exception_handler=on_error)

    for r, expiry_date in zip(http_responses, expiry_dates):
        opt_price = call_bid0 = call_ask0 = put_bid0 = put_ask0 = None

        if r.ok:
            if expiry_date >= start_date:
                data = r.json()

                price_levels = data
                price_level = price_levels[5]

                assert len(price_levels) == 11

                opt_price = float(price_level[0])
                call_bid0 = float(price_level[1])
                call_ask0 = float(price_level[2])
                put_bid0 = float(price_level[3])
                put_ask0 = float(price_level[4])

        opt_prices.append(opt_price)
        call_asks.append(call_ask0)
        call_bids.append(call_bid0)
        put_asks.append(put_ask0)
        put_bids.append(put_bid0)

    return pd.DataFrame({
        'exchange': exchanges,
        'symbol': ss,
        'time': [datetime.datetime.now()] * len(ss),
        'expiry_date': expiry_dates,
        'note': notes,
        'opt_price': opt_prices,
        'call_ask': call_asks,
        'call_bid': call_bids,
        'put_ask': put_asks,
        'put_bid': put_bids,
        'rate': [1] * len(ss)
    })