Exemple #1
0
def getClickButtonData(bot, update):
    data = intraday.meta(apiToken=api_token, symbolId=num, output='raw')

    if update.callback_query.data == 'info':
        if 'industryZhTw' in data:
            text = ('產業別:' + data['industryZhTw'] + '\n' + '交易幣別:' +
                    data['currency'] + '\n' + '股票中文簡稱:' + data['nameZhTw'] +
                    '\n' + '開盤參考價:' + str(data['priceReference']) + '\n' +
                    '漲停價:' + str(data['priceHighLimit']) + '\n' + '跌停價:' +
                    str(data["priceLowLimit"]) + '\n' + '股票類別:' +
                    data['typeZhTw'])
        else:
            text = ('交易幣別:' + data['currency'] + '\n' + '股票中文簡稱:' +
                    data['nameZhTw'] + '\n' + '開盤參考價:' +
                    str(data['priceReference']) + '\n' + '漲停價:' +
                    str(data['priceHighLimit']) + '\n' + '跌停價:' +
                    str(data["priceLowLimit"]) + '\n' + '股票類別:' +
                    data['typeZhTw'])

        update.callback_query.message.reply_text(text)

    if update.callback_query.data == 'trade':
        df2 = intraday.quote(apiToken=api_token, symbolId=num, output='raw')
        df3 = df2['trade']
        text = ('• ' + data['nameZhTw'] + '(' + num + ')' + '最新一筆交易:' + '\n' +
                '成交價:' + str(df3['price']) + '\n' + '成交張數:' +
                str(df3['unit']) + '\n' + '成交量:' + str(df3['volume']) + '\n' +
                '成交序號:' + str(df3['serial']))
        update.callback_query.message.reply_text(text)
Exemple #2
0
    def target_change_strategy(self, symbol_id, rise_target_change,
                               drop_target_change):

        message = intraday.quote(apiToken=self.api_token,
                                 symbolId=symbol_id,
                                 output='raw')
        current_price = message['trade']['price']

        symbol_info = intraday.meta(symbolId=symbol_id,
                                    apiToken=self.api_token,
                                    output='raw')
        adjust_open = symbol_info['priceReference']

        if (current_price - adjust_open) / adjust_open > rise_target_change:
            self.lineNotifyMessage('快訊!' + symbol_id + '漲幅已經高過' +
                                   str(rise_target_change * 100) + '%\n' +
                                   'https://www.fugle.tw/trade?symbol_id=' +
                                   symbol_id + '&openExternalBrowser=1')

        elif (current_price - adjust_open) / adjust_open < -drop_target_change:
            self.lineNotifyMessage('快訊!' + symbol_id + '跌幅已經低過' +
                                   str(drop_target_change * 100) + '%\n' +
                                   'https://www.fugle.tw/trade?symbol_id=' +
                                   symbol_id + '&openExternalBrowser=1')

        else:
            pass

        return current_price, adjust_open
Exemple #3
0
    def serv_buy_sell(self, keyword, msg_received):
        """
        To get information for buy sell in a day.
        """
        print('【serv_buy_sell】')

        # Check whether has share number in memory
        if self.temp_share_no:
            share_data = intraday.meta(apiToken=FUGLE_API_TOKEN,
                                       symbolId='{}'.format(
                                           self.temp_share_no),
                                       output='raw')
            if share_data['canDayBuySell'] == True and share_data[
                    'canDaySellBuy'] == True:
                text = "菜雞調查後 😃,建議【{}】{}可進行當冲交易,但最終決定在您手中!😉".format(
                    self.share_db[self.temp_share_no], self.temp_share_no)
            else:
                text = "菜雞調查後 😃,建議【{}】{}可不進行當冲交易,但最終決定在您手中!😉".format(
                    self.share_db[self.temp_share_no], self.temp_share_no)
        else:
            text = "抱歉,菜雞不懂您 😥,無法得知您想瞭解的股票!請您重新輸入!"
            self.prev_action = "serv_buy_sell"
        self.out_msg = self.temp_msg = text
        success = self.send_message()
        return success
Exemple #4
0
 def getStockInfo(self, id):
     ret = dict()
     output_meta = intraday.meta(apiToken=self.apiToken,
                                 output="dataframe",
                                 symbolId=id)
     output_chart = intraday.chart(apiToken=self.apiToken,
                                   output="dataframe",
                                   symbolId=id)
     ref_price = output_meta.iloc[
         0, output_meta.columns.get_loc("priceReference")]
     current_price = output_chart.iloc[
         -1, output_chart.columns.get_loc("close")]
     if ref_price > current_price:
         graph = output_chart.plot(x="at", y='close', color='green')
     elif ref_price == current_price:
         graph = output_chart.plot(x="at", y='close', color='gray')
     else:
         graph = output_chart.plot(x="at", y='close', color='red')
     graph.axhline(ref_price,
                   linestyle='dashed',
                   color='xkcd:dark grey',
                   alpha=0.6,
                   label='參考價',
                   marker='')
     graph.legend().set_visible(False)
     fig = graph.get_figure()
     buf = io.BytesIO()
     fig.savefig(buf, format='png')
     ret['Name'] = output_meta.iloc[0,
                                    output_meta.columns.get_loc("nameZhTw")]
     ret['RealPrice'] = current_price
     ret['ID'] = id
     ret['photo'] = buf
     return ret
Exemple #5
0
 def _get_meta(self, symbol_id):
     meta = intraday.meta(apiToken=self.api_token, symbolId=symbol_id)
     reply = '此為【' + meta['nameZhTw'][0] + '】的基本資訊\n'\
             '◆ 股票代碼:' + symbol_id + '\n'\
             '◆ 交易幣別代號:' + meta['currency'][0] + '\n'\
             '◆ 股票類型:' + meta['typeZhTw'][0] + '\n'\
             '◆ 是否為指數:' + self._change(meta['isIndex'][0]) + '\n'\
             '◆ 開盤參考價:' + str(meta['priceReference'][0]) + '\n'\
             '◆ 漲停價:' + str(meta['priceHighLimit'][0]) + '\n'\
             '◆ 跌停價:' + str(meta['priceLowLimit'][0])
     return reply
Exemple #6
0
def priceReference(bot, update):

    q_data = intraday.meta(apiToken=api_token,
                           symbolId=str(aa[0]),
                           output="raw")['priceReference']
    qq_data = intraday.meta(apiToken=api_token,
                            symbolId=str(aa[0]),
                            output="raw")['priceHighLimit']
    qqq_data = intraday.meta(apiToken=api_token,
                             symbolId=str(aa[0]),
                             output="raw")['priceLowLimit']
    qq = 'priceReference' + str(q_data)
    qq1 = 'priceHighLimit' + str(qq_data)
    qq2 = 'priceLowLimit' + str(qqq_data)
    #     print(qq)
    update.message.reply_text(qq)
    update.message.reply_text(qq1)
    update.message.reply_text(qq2)

    print(qq)
    def get_stock_info(self, num):
        data = intraday.meta(apiToken=self.config['FUGLE']['fugle_TOKEN'] , symbolId=num , output='raw')
        # data = intraday.meta(apiToken=Bot.config['FUGLE']['fugle_TOKEN'] , symbolId='0050', output='raw')
        df1 = intraday.chart(apiToken=self.config['FUGLE']['fugle_TOKEN'] , symbolId=num)
        # df1 = intraday.chart(apiToken=Bot.config['FUGLE']['fugle_TOKEN'] , symbolId='0050')
        if 'error' in df1.columns:
            return '請輸入正確的股票代碼:'
        elif df1.shape[0] == 0:
            if  'nameZhTw' not in data:
                text = 'api 無回應'
            elif 'industryZhTw' in data:
                text = "【{}({})】  \n⦁ 產業: {} \n⦁ 開盤股價: {}  \n⦁ 昨日漲停價: {} \n⦁ 昨日跌停價: {} ".format(
                                                                        data['nameZhTw'],
                                                                        num, 
                                                                        data['industryZhTw'],
                                                                        data['priceReference'],
                                                                        data['priceHighLimit'],
                                                                        data['priceLowLimit']
                                                                    )
            else:
                text = "【{}({})】  \n⦁ 開盤股價: {}  \n⦁ 昨日漲停價: {} \n⦁ 昨日跌停價: {} ".format(
                                                                        data['nameZhTw'],
                                                                        num, 
                                                                        data['priceReference'],
                                                                        data['priceHighLimit'],
                                                                        data['priceLowLimit']
                                                                    )
            return text
        else:               
            df1 = df1.iloc[-1]
            if 'industryZhTw' in data:
                text = "【{}({})】  \n⦁ 產業: {} \n⦁ 當前股價: {}  \n⦁ 今日漲跌: {}({}%) ".format(
                                                                        data['nameZhTw'],
                                                                        num, 
                                                                        data['industryZhTw'],
                                                                        df1['close'],
                                                                        round(df1['close']-data['priceReference'], 2),
                                                                        round(((df1['close']-data['priceReference'])/data['priceReference'])*100, 2)
                                                                    )
            else:
                text = "【{}({})】  \n⦁ 當前股價: {}  \n⦁ 今日漲跌: {}({}%) ".format(
                                                                        data['nameZhTw'],
                                                                        num, 
                                                                        df1['close'],
                                                                        round(df1['close']-data['priceReference'], 2),
                                                                        round(((df1['close']-data['priceReference'])/data['priceReference'])*100, 2)
                                                                    )

            return text
Exemple #8
0
def info(bot, update):
    global num
    num = update.message.text
    data = intraday.meta(apiToken=api_token, symbolId=num, output='raw')
    '''對話框按鈕'''
    global reply_markup
    reply_markup = InlineKeyboardMarkup([[
        InlineKeyboardButton('基本資訊', callback_data='info'),
        InlineKeyboardButton('最新一筆交易', callback_data='trade'),
    ]])
    '''輸入id,且判斷id是否存在'''
    if 'id' in num:
        if int(num[2:]) not in userdata().df['userid']:
            update.message.reply_text('ID%s 不存在' % (num[2:]))
        else:
            update.message.reply_text('登入成功 ID:%s,請輸入欲查詢的股票代碼:' % (num[2:]))
            userdata().write(update.message.chat.id, num[2:])

    elif 'error' in intraday.chart(apiToken=api_token,
                                   symbolId='2330').columns:
        '''直接輸入股票代碼'''
        update.message.reply_text('請輸入正確的股票代碼:')
    else:
        df1 = intraday.chart(apiToken=api_token, symbolId=num)
        df1 = df1.iloc[-1]
        text = ('•' + data['nameZhTw'] + '(' + num + ')\t\t' + '股價:' +
                str(df1['close']) + '\t\t' + '漲跌:' +
                str(data['priceReference'] - df1['close']) + '\t(' + str(
                    round(((data['priceReference'] - df1['close']) /
                           data['priceReference']) * 100, 2)) + '%)')
        bot.send_message(
            update.message.chat.id,
            text + '\n\n' +
            '{} 您還可以查詢:'.format(update.message.from_user.first_name),
            reply_to_message_id=update.message.message_id,
            reply_markup=reply_markup)
Exemple #9
0
        def ButtonCallback_handler(bot, update):
            order, sid = update.callback_query.data.split(' ')
            user_name = update.callback_query.from_user.first_name + update.callback_query.from_user.last_name  # update.message.from_user.first_name
            user_id = update.callback_query.from_user.id

            if order == 'stock':
                text = self.get_stock_info(num=str(sid))
                url = 'https://www.fugle.tw/ai/{}?'.format(sid)
                button = InlineKeyboardMarkup(
                    [[
                        InlineKeyboardButton(
                            '更多基本資訊', callback_data='info {}'.format(sid)),
                        InlineKeyboardButton(
                            '最新一筆交易', callback_data='trade {}'.format(sid))
                    ],
                     [
                         InlineKeyboardButton(
                             '推薦相關股票',
                             callback_data='recommend {}'.format(sid)),
                         InlineKeyboardButton('前往網站', url=url)
                     ]])
                bot.send_message(
                    user_id,
                    text,
                    # reply_to_message_id = update.message.message_id,
                    reply_markup=button)

            if order == 'recommend':
                try:
                    result = self.call_m3(stock_id=int(sid))
                    text = self.get_stock_info(num=str(result))
                    url = 'https://www.fugle.tw/ai/{}?'.format(result)
                    button = InlineKeyboardMarkup(
                        [[
                            InlineKeyboardButton(
                                '更多基本資訊',
                                callback_data='info {}'.format(result)),
                            InlineKeyboardButton(
                                '最新一筆交易',
                                callback_data='trade {}'.format(result))
                        ],
                         [
                             InlineKeyboardButton(
                                 '推薦相關股票',
                                 callback_data='recommend {}'.format(result)),
                             InlineKeyboardButton('前往網站', url=url)
                         ]])
                    bot.send_message(user_id,
                                     text,
                                     reply_to_message_id=update.callback_query.
                                     message.message_id,
                                     reply_markup=button)
                    self.logger.info("user_name{} | respond_text:{}".format(
                        user_name, text))

                except:
                    update.message.reply_text('請輸入存在的股票id。 \nex:6456、4552')
                    self.logger.info('m3 - uid error')

            if order == 'info':
                data = intraday.meta(
                    apiToken=self.config['FUGLE']['fugle_TOKEN'],
                    symbolId=sid,
                    output='raw')
                # data = intraday.meta(apiToken=Bot.config['FUGLE']['fugle_TOKEN'] , symbolId='0050' , output='raw')
                try:
                    if 'industryZhTw' in data:
                        text = ('【' + data['nameZhTw'] + '(' + sid + ')' +
                                ' 基本資訊】 \n  ⦁ 產業別:' + data['industryZhTw'] +
                                '\n  ⦁ 交易幣別:' + data['currency'] +
                                '\n  ⦁ 股票中文簡稱:' + data['nameZhTw'] +
                                '\n  ⦁ 開盤參考價:' + str(data['priceReference']) +
                                '\n  ⦁ 漲停價:' + str(data['priceHighLimit']) +
                                '\n  ⦁ 跌停價:' + str(data["priceLowLimit"]) +
                                '\n  ⦁ 股票類別:' + data['typeZhTw'])
                    else:
                        text = ('【' + data['nameZhTw'] + '(' + sid + ')' +
                                ' 基本資訊】 \n  ⦁ 交易幣別:' + data['currency'] +
                                '\n  ⦁ 股票中文簡稱:' + data['nameZhTw'] +
                                '\n  ⦁ 開盤參考價:' + str(data['priceReference']) +
                                '\n  ⦁ 漲停價:' + str(data['priceHighLimit']) +
                                '\n  ⦁ 跌停價:' + str(data["priceLowLimit"]) +
                                '\n  ⦁ 股票類別:' + data['typeZhTw'])
                except:
                    text = '查無此代碼'
                update.callback_query.message.reply_text(text)

            if order == 'trade':
                data = intraday.meta(
                    apiToken=self.config['FUGLE']['fugle_TOKEN'],
                    symbolId=sid,
                    output='raw')

                dt = intraday.quote(
                    apiToken=self.config['FUGLE']['fugle_TOKEN'],
                    symbolId=sid,
                    output='raw')
                # intraday.quote(apiToken=Bot.config['FUGLE']['fugle_TOKEN'], symbolId=num, output='raw')
                if 'trade' in dt.keys():
                    trade = dt['trade']
                    text = ('【' + data['nameZhTw'] + '(' + sid + ')' +
                            ' 最新一筆交易】 \n' + '  ⦁ 成交價:' + str(trade['price']) +
                            '\n  ⦁ 成交張數:' + str(trade['unit']) + '\n  ⦁ 成交量:' +
                            str(trade['volume']) + '\n  ⦁ 成交序號:' +
                            str(trade['serial']))
                else:
                    text = '查無最新資訊'
                update.callback_query.message.reply_text(text)
def test_intraday_meta_output_raw():
    meta = intraday.meta(output="raw")
    assert type(meta) is dict
def test_intraday_meta_output_dataframe():
    meta = intraday.meta(output="dataframe")
    assert type(meta) is DataFrame
def test_intraday_meta_output():
    with raises(ValueError) as excinfo:
        intraday.meta(output="")
    assert excinfo.type is ValueError
    assert str(excinfo.value) == 'output must be one of ["dataframe", "raw"]'
def test_intraday_meta():
    meta = intraday.meta()
    assert type(meta) is DataFrame