Exemple #1
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 #2
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 #3
0
    def get_first_quote_data(self, symbol_id):

        message = intraday.quote(apiToken=self.api_token,
                                 symbolId=symbol_id,
                                 output='raw')

        ask = message['order']['bestAsks']
        ask.reverse()

        df_ask = pd.DataFrame(ask,
                              columns=['price', 'unit'
                                       ]).rename(columns={'unit': 'ask_unit'})

        bid = message['order']['bestBids']
        bid.reverse()

        df_bid = pd.DataFrame(bid,
                              columns=['unit', 'price'
                                       ]).rename(columns={'unit': 'bid_unit'})

        df_quote = pd.merge(df_ask, df_bid, on='price', how='outer')
        df_quote = df_quote[['bid_unit', 'price', 'ask_unit']]

        price_list = list(df_quote['price'])

        return df_quote, price_list
Exemple #4
0
    def target_price_strategy(self, symbol_id, rise_target_price, drop_target_price):

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

        if current_price > rise_target_price:
            self.lineNotifyMessage('快訊!' + symbol_id + '價格已經高過' + str(rise_target_price) + '元\n'+
                                   'https://www.fugle.tw/trade?symbol_id=' + symbol_id + '&openExternalBrowser=1')

        elif current_price < drop_target_price:
            self.lineNotifyMessage('快訊!' + symbol_id + '價格已經跌破' + str(drop_target_price) + '元\n'+
                                   'https://www.fugle.tw/trade?symbol_id=' + symbol_id + '&openExternalBrowser=1')

        else:
            pass
Exemple #5
0
 def _get_best_five(self, symbol_id):
     quote = intraday.quote(apiToken=self.api_token, symbolId=symbol_id)
     temp = ['此為【' + symbol_id + '】的最佳五檔\n', '◆ bestAsks:\n']
     for i in range(5):
         temp.append('價格:' + str(quote['order.bestAsks'][0][i]['price']) +
                     '  張數' + str(quote['order.bestAsks'][0][i]['unit']) +
                     '\n')
     temp.append('◆ bestBids:\n')
     for j in range(5):
         temp.append('價格:' + str(quote['order.bestBids'][0][j]['price']) +
                     '  張數' + str(quote['order.bestBids'][0][j]['unit']) +
                     '\n')
     reply = ''
     for k in temp:
         reply = reply + '{}'.format(k)
     return reply
Exemple #6
0
def best5(bot, update):

    s = intraday.quote(apiToken=api_token, symbolId=str(aa[0]),
                       output="raw")['order']
    s1 = s['bestAsks']
    s2 = s['bestBids']

    for i in range(0, len(s1)):
        a.append(s1[i]['price'])
        b.append(s1[i]['unit'])
    for i in range(0, len(s2)):
        c.append(s2[i]['price'])
        d.append(s2[i]['unit'])

    aaa = "bestAsks" + "\n" + "price" + str(a) + "\n" + "unit" + str(b)
    bbb = 'bestBids' + "\n" + "price" + str(c) + "\n" + "unit" + str(d)

    update.message.reply_text(aaa)
    update.message.reply_text(bbb)
Exemple #7
0
    def serv_top_share(self):
        """
        To get the best 5 sell and buy price by share number.
        """
        print('【serv_top_share】')

        # Check whether has share number in memory
        if self.temp_share_no:
            share_data = intraday.quote(apiToken=FUGLE_API_TOKEN,
                                        symbolId=self.temp_share_no,
                                        output='raw')['order']

            # Creat Template For ask bid price
            text_ask = "您好 😁,菜雞偷了Fugle的最佳5檔機密,請參考!\n 最佳五檔(買價):\n"
            text_bid = "您好 😁,菜雞偷了Fugle的最佳5檔機密,請參考!\n 最佳五檔(賣價):\n"

            # Build Specific Text
            count = 1
            for ask, bid in zip(share_data['bestAsks'],
                                share_data['bestBids']):
                temp_ask = '➡' + str(count) + '.價格: ' + str(
                    ask['price']) + ' 交易張數:' + str(
                        ask['unit']) + ' 交易量:' + str(ask['volume']) + "\n "
                temp_bid = '➡' + str(count) + '.價格: ' + str(
                    bid['price']) + ' 交易張數:' + str(
                        bid['unit']) + ' 交易量:' + str(bid['volume']) + "\n "
                text_ask = text_ask + "{}".format(temp_ask)
                text_bid = text_bid + "{}".format(temp_bid)
                count += 1
            # Send message by List
            for send_content in [text_ask, text_bid]:
                self.out_msg = send_content
                success = self.send_message()

            # Save Temp Data
            self.temp_msg = [text_ask, text_bid]
        else:
            self.out_msg = self.temp_msg = "抱歉,菜雞不懂您 🙃,無法得知您想瞭解的股票!請您重新輸入!"
            self.prev_action = "serv_top_share"
            success = self.send_message()
        return success
Exemple #8
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_quote_output_raw():
    quote = intraday.quote(output="raw")
    assert type(quote) is dict
def test_intraday_quote_output_dataframe():
    quote = intraday.quote(output="dataframe")
    assert type(quote) is DataFrame
def test_intraday_quote_output():
    with raises(ValueError) as excinfo:
        intraday.quote(output="")
    assert excinfo.type is ValueError
    assert str(excinfo.value) == 'output must be one of ["dataframe", "raw"]'
def test_intraday_quote():
    quote = intraday.quote()
    assert type(quote) is DataFrame