コード例 #1
0
ファイル: combobot.py プロジェクト: botticket/cryptobott
                def ticket(self):
                    end = datetime.now()
                    start = datetime(end.year, end.month, end.day)
                    list = self.stock

                    dfall = data.DataReader(f'{list}',
                                            data_source="yahoo",
                                            start=start_year,
                                            end=end)
                    try:
                        dfM = data.DataReader(f'{list}',
                                              data_source="yahoo",
                                              start=monthly,
                                              end=end)
                    except ValueError:
                        dfM = data.DataReader(f'{list}',
                                              data_source="yahoo",
                                              start=start_year,
                                              end=end)
                    try:
                        preM = data.DataReader(f'{list}',
                                               data_source="yahoo",
                                               start=prevm,
                                               end=endvm)
                    except ValueError:
                        preM = data.DataReader(f'{list}',
                                               data_source="yahoo",
                                               start=start_year,
                                               end=end)

                    list = list.replace('.bk', '')
                    st = checkmarket(code)
                    stock = f'{list}'
                    list = list.upper()

                    try:
                        Close = float(st[1])
                    except ValueError:
                        Close = dfall['Close'].iloc[-1]
                    Close = '%.2f' % Close

                    OpenD = dfall['Open'].iloc[-1]
                    OpenD = '%.2f' % OpenD

                    try:
                        today_chg = float(st[2])
                    except ValueError:
                        today_chg = float(dfall['Close'].iloc[-1]) - float(
                            dfall['Close'].iloc[-2])
                    today_chg = '%.2f' % today_chg

                    #copy dataframeY
                    dfall = dfall.copy()
                    dfall['date_id'] = (
                        (dfall.index.date -
                         dfall.index.date.min())).astype('timedelta64[D]')
                    dfall['date_id'] = dfall['date_id'].dt.days + 1

                    # high trend lineY
                    dfall_mod = dfall.copy()
                    while len(dfall_mod) > 3:
                        reg = linregress(
                            x=dfall_mod['date_id'],
                            y=dfall_mod['Close'],
                        )
                        dfall_mod = dfall_mod.loc[dfall_mod['Close'] > reg[0] *
                                                  dfall_mod['date_id'] +
                                                  reg[1]]
                    reg = linregress(
                        x=dfall_mod['date_id'],
                        y=dfall_mod['Close'],
                    )
                    dfall['high_trend'] = reg[0] * dfall['date_id'] + reg[1]

                    # low trend lineY
                    dfall_mod = dfall.copy()
                    while len(dfall_mod) > 3:
                        reg = linregress(
                            x=dfall_mod['date_id'],
                            y=dfall_mod['Close'],
                        )
                        dfall_mod = dfall_mod.loc[dfall_mod['Close'] < reg[0] *
                                                  dfall_mod['date_id'] +
                                                  reg[1]]
                    reg = linregress(
                        x=dfall_mod['date_id'],
                        y=dfall_mod['Close'],
                    )
                    dfall['low_trend'] = reg[0] * dfall['date_id'] + reg[1]

                    HpreM = preM.nlargest(1, columns='High')
                    HpreM = HpreM['High'].iloc[-1]
                    if HpreM >= 100:
                        HpreM = (round(HpreM / 0.5) * 0.5)
                    elif HpreM >= 25:
                        HpreM = (round(HpreM / 0.25) * 0.25)
                    elif HpreM >= 10:
                        HpreM = (round(HpreM / 0.1) * 0.1)
                    elif HpreM >= 5:
                        HpreM = (round(HpreM / 0.05) * 0.05)
                    else:
                        HpreM = (round(HpreM / 0.02) * 0.02)
                    HpreM = '%.2f' % HpreM

                    LpreM = dfM.nlargest(1, columns='High')
                    LpreM = LpreM['Low'].iloc[-1]
                    if LpreM >= 100:
                        LpreM = (round(LpreM / 0.5) * 0.5)
                    elif LpreM >= 25:
                        LpreM = (round(LpreM / 0.25) * 0.25)
                    elif LpreM >= 10:
                        LpreM = (round(LpreM / 0.1) * 0.1)
                    elif LpreM >= 5:
                        LpreM = (round(LpreM / 0.05) * 0.05)
                    else:
                        LpreM = (round(LpreM / 0.02) * 0.02)
                    LpreM = '%.2f' % LpreM

                    HpreMp = (
                        (float(Close) - float(HpreM)) / float(HpreM)) * 100
                    HpreMp = '%.2f' % HpreMp

                    max_Y = dfall.nlargest(1, columns='High')
                    max_Y = max_Y['High'].iloc[-1]
                    max_Y = '%.2f' % max_Y

                    dif_max = (
                        (float(max_Y) - float(Close)) / float(Close)) * 100
                    dif_max = '%.2f' % dif_max

                    if (stock in set50):
                        inline = f'SET50'
                    elif (stock in set100):
                        inline = f'SET100'
                    else:
                        inline = ' '

                    text_return = f'{list} \nH {HpreM} ({HpreMp}%) > {Close} ({today_chg}) \ntake profit <= {LpreM}'
                    linechat(text_return)
                    word_to_reply = str(f'{text_return}')
                    print(word_to_reply)

                    text = st[0]
                    price_now = str(Close)
                    change = str(today_chg)
                    chgp = str(inline)

                    notice = f'{max_Y} ({dif_max}%)'
                    start = f'{HpreM} ({HpreMp}%)'
                    stop = f'{LpreM}'
                    target = f'{OpenD}'
                    avg = ' '

                    bubbles = []
                    bubble = flex_stock(text, price_now, change, chgp, notice,
                                        start, stop, target, avg)

                    flex_to_reply = SetMessage_Object(bubble)
                    reply_msg(reply_token,
                              data=flex_to_reply,
                              bot_access_key=channel_access_token)
                    return 'OK'
コード例 #2
0
                def ticket(self):
                    end = datetime.now()
                    start = datetime(end.year,end.month,end.day)
                    list = self.stock

                    dfY = data.DataReader(f'{list}', data_source="yahoo", start=yearly, end=end)
                    dfQ = data.DataReader(f'{list}', data_source="yahoo", start=quarter, end=end)
                    dfM = data.DataReader(f'{list}', data_source="yahoo", start=monthly, end=end)
                    list = list.replace('.bk','')
                                
                    OpenY = dfY['Open'].iloc[0]
                    OpenY  = '%.2f'%OpenY
                    OpenY = str(OpenY)

                    OpenQ = dfQ['Open'].iloc[0]
                    OpenQ  = '%.2f'%OpenQ
                    OpenQ = str(OpenQ)

                    p_openQ = ((float(OpenQ) - float(OpenY)) / float(OpenY))*100
                    p_openQ  = '%.2f'%p_openQ
                    p_openQ = str(p_openQ)

                    OpenM = dfM['Open'].iloc[0]
                    OpenM  = '%.2f'%OpenM
                    OpenM = str(OpenM)

                    Close = float(f'{r[1]}')
                    Close  = '%.2f'%Close
                    Close = str(Close)

                    barY = ((float(Close) - float(OpenY)) / float(OpenY) )*100
                    barY = '%.2f'%barY
                    barY = float(barY)

                    barQ = ((float(Close) - float(OpenQ)) / float(OpenQ) )*100
                    barQ = '%.2f'%barQ
                    barQ = float(barQ)

                    barM = ((float(Close) - float(OpenM)) / float(OpenM) )*100
                    barM = '%.2f'%barM
                    barM = float(barM)

                    Volume1 = dfY['Volume'].iloc[-1]
                    Volume2 = dfY['Volume'].iloc[-2]

                    Volume = (float(Volume1)+float(Volume2))/2
                    Volume  = '%.0f'%Volume
                    Volume = str(Volume)

                    value = float(Volume) * float(Close)
                    value  = '%.2f'%value
                    value = str(value)

                    request_val = float(value) 
                    request_val  = '{:,.0f}'.format(request_val)
                    request_val = str(request_val)
                    
                    exit1 = float(OpenQ) * 1.20
                    exit1 = '%.2f'%exit1
                    exit1 = str(exit1)

                    exit2 = float(OpenQ) * 1.40
                    exit2 = '%.2f'%exit2
                    exit2 = str(exit2)

                    exit3 = float(OpenQ) * 1.60
                    exit3 = '%.2f'%exit3
                    exit3 = str(exit3)

                    buyQ = float(OpenQ) * 1.02
                    buyQ = '%.2f'%buyQ
                    buyQ = str(buyQ) 

                    stopQ = float(OpenQ) * 0.98
                    stopQ = '%.2f'%stopQ
                    stopQ = str(stopQ) 

                    buyY = float(OpenY) * 1.02
                    buyY = '%.2f'%buyY
                    buyY = str(buyY) 

                    stopY = float(OpenY) * 0.98
                    stopY = '%.2f'%stopY
                    stopY = str(stopY) 

                    max_value = dfY.nlargest(1, columns = 'High')
                    max_value = max_value['High'].iloc[0]
                    max_value = '%.2f'%max_value
                    max_value = str(max_value) 

                    max_valueQ = dfQ.nlargest(1, columns = 'High')
                    max_valueQ = max_valueQ['High'].iloc[0]
                    max_valueQ = '%.2f'%max_valueQ
                    max_valueQ = str(max_valueQ) 

                    pmax_valueQ = ((float(max_valueQ) - float(OpenQ)) / float(OpenQ)) * 100
                    pmax_valueQ = '%.2f'%pmax_valueQ
                    pmax_valueQ = str(pmax_valueQ)  

                    min_value = dfY.nsmallest(1, columns = 'Low')
                    min_value = min_value['Low'].iloc[0]
                    min_value = '%.2f'%min_value
                    min_value = str(min_value) 

                    pmin_value = ((float(min_value) - float(OpenY)) / float(OpenY)) * 100
                    pmin_value = '%.2f'%pmin_value
                    pmin_value = str(pmin_value)

                    support1 = float(OpenY) * 0.80
                    support1 = '%.2f'%support1
                    support1 = str(support1)

                    support2 = float(OpenY) * 0.70
                    support2 = '%.2f'%support2
                    support2 = str(support2)

                    support3 = float(OpenY) * 0.60
                    support3 = '%.2f'%support3
                    support3 = str(support3)
                    
                    textY = exit1 + ' | ' + exit2 + ' | ' + exit3 
                    textQ = exit1 + ' | ' + exit2 + ' | ' + exit3 
                    text2 = support3 + ' | ' + support2 + ' | ' + support1 

                    alert1 = 'ชนแนวต้าน'
                    alert2 = 'ไปต่อ'
                    alert3 = 'ซื้อ'
                    alert4 = 'อย่าเพิ่งเข้า'
                    alert5 = 'กำลังย่อ'
                    alert6 = 'ห้ามพลาด'
                    alert7 = 'เด้ง'
                    alert8 = 'ลงต่อ'
                    alert9 = 'Vol น้อย'

                    text = r[0]
                    price_now = r[1] 
                    change = r[2] 
                    chgp = str(r[3])
                    re_avg = '{}%'.format(barQ) + '\n' + 'H {} L {}'.format(max_valueQ,min_value)

                    if float(value) > 7500000:
                        if  barY >= 0.00:
                            if 0.00 < barY < 10.00:
                                notice = alert6
                                start = OpenY
                                buy = buyY
                                stop = stopY
                                target = textY
                                avg = re_avg      
                            elif barQ > 12.00:
                                notice = alert1
                                start = OpenQ
                                buy = buyQ
                                stop = stopQ
                                target = textQ
                                avg = re_avg
                            elif barQ >= 0.00:
                                if barM >= 0.00:
                                    notice = alert3
                                    start = OpenQ
                                    buy = buyQ
                                    stop = stopQ
                                    target = textQ
                                    avg = re_avg
                                else:
                                    notice = alert5
                                    start = OpenQ
                                    buy = buyQ
                                    stop = stopQ
                                    target = textQ
                                    avg = re_avg
                            else:
                                notice = alert4
                                start = OpenQ
                                buy = buyQ
                                stop = stopQ
                                target = textQ
                                avg = re_avg
                        else:
                            if barQ >= 0.00:
                                if barM >= 0.00:
                                    notice = alert3
                                    start = OpenQ
                                    buy = buyQ
                                    stop = text2
                                    target = textQ
                                    avg = re_avg
                                else:
                                    notice = alert5
                                    start = OpenQ
                                    buy = buyQ
                                    stop = text2
                                    target = textQ
                                    avg = re_avg
                            else:
                                notice = alert8
                                start = OpenQ
                                buy = buyQ
                                stop = text2
                                target = textQ
                                avg = re_avg
                    else:
                        notice = alert9
                        start = OpenQ
                        buy = buyQ
                        stop = text2
                        target = textQ
                        avg = re_avg

                    word_to_reply = str('{} {}'.format(text,notice))
                    linechat(word_to_reply)

                    bubbles = []
                    bubble = flex_stock(text,price_now,change,chgp,notice,start,buy,stop,target,avg)
                    
                    flex_to_reply = SetMessage_Object(bubble)
                    reply_msg(reply_token,data=flex_to_reply,bot_access_key=channel_access_token)
                    return 'OK'
コード例 #3
0
            def setcheck():
                st = setscrapt()                

                price_now = float(st[0])
                price_now = '%.2f'%price_now
                price_now = str(price_now)

                change = str(st[1]) 
                chgp = str(st[2])

                exit_long1 = float(price_now) * 1.05
                exit_long1 = '%.2f'%exit_long1

                exit_long2 = float(price_now) * 1.10
                exit_long2 = '%.2f'%exit_long2

                exit_long3 = float(price_now) * 1.20
                exit_long3 = '%.2f'%exit_long3      

                exit_short1 = float(price_now) * 0.95
                exit_short1 = '%.2f'%exit_short1

                exit_short2 = float(price_now) * 0.90
                exit_short2 = '%.2f'%exit_short2

                exit_short3 = float(price_now) * 0.80
                exit_short3 = '%.2f'%exit_short3

                LongY = float(set_value) * 1.005
                LongY = '%.2f'%LongY

                stop_longY = float(set_value) * 0.995
                stop_longY = '%.2f'%stop_longY     

                shortY = float(set_value) * 0.995
                shortY = '%.2f'%shortY

                stop_shortY = float(set_value) * 1.005
                stop_shortY = '%.2f'%stop_shortY                    
                
                barQ = float(price_now) - float(set_value)
                barQ = float(barQ)                

                text1 = exit_long1 + ' | ' + exit_long2 + ' | ' + exit_long3 
                text2 = exit_short1 + ' | ' + exit_short2 + ' | ' + exit_short3 

                alert1 = 'Long'
                alert2 = 'Short'

                text = text_from_user                

                if barQ >= 0:
                    notice = alert1
                    start = set_value
                    buy = LongY
                    stop = stop_longY
                    target = text1
                    number = '1'
                else:
                    notice = alert2
                    start = set_value
                    buy = shortY
                    stop = stop_shortY
                    target = text2 
                    number = '2'
                
                word_to_reply = '{}'.format(text) + '\n' + 'now {} {} ({}%)'.format(price_now,change,chgp)
                result = 'Position: {}'.format(notice) + '\n' + 'Range: {} - {} '.format(start,buy) + '\n' + 'Stop: {}'.format(stop) + '\n' + 'Target: {}'.format(target)
                linechat(word_to_reply)
                bubble = flex_setcheck(text,price_now,change,chgp,notice,start,buy,stop,target)
                
                flex_to_reply = SetMessage_Object(bubble)
                reply_msg(reply_token,data=flex_to_reply,bot_access_key=channel_access_token)
                return 'OK'
コード例 #4
0
            def tfexcheck():
                tff = tfexupdate()

                exit_long1 = float(tff[0]) * 1.04
                exit_long1 = '%.2f'%exit_long1

                exit_long2 = float(tff[0]) * 1.08
                exit_long2 = '%.2f'%exit_long2

                exit_long3 = float(tff[0]) * 1.12
                exit_long3 = '%.2f'%exit_long3      

                exit_short1 = float(tff[0]) * 0.96
                exit_short1 = '%.2f'%exit_short1

                exit_short2 = float(tff[0]) * 0.92
                exit_short2 = '%.2f'%exit_short2

                exit_short3 = float(tff[0]) * 0.88
                exit_short3 = '%.2f'%exit_short3

                LongY = float(tfex_value) * 1.005
                LongY = '%.2f'%LongY

                stop_longY = float(tfex_value) * 0.995
                stop_longY = '%.2f'%stop_longY     

                shortY = float(tfex_value) * 0.995
                shortY = '%.2f'%shortY

                stop_shortY = float(tfex_value) * 1.005
                stop_shortY = '%.2f'%stop_shortY                    

                price_now = float(tff[0])
                price_now = '%.2f'%price_now
                price_now = str(price_now)
                
                barM = float(price_now) - float(tfex_value)
                chgp = str(tff[2])

                text1 = exit_long1 + ' | ' + exit_long2 + ' | ' + exit_long3 
                text2 = exit_short1 + ' | ' + exit_short2 + ' | ' + exit_short3 

                alert1 = 'Long'
                alert2 = 'Short'

                text = '{}'.format(tfex_code)
                change = str(tff[1]) 

                if barM >= 0:
                    notice = alert1
                    start = tfex_value
                    buy = LongY
                    stop = stop_longY
                    target = text1
                    number = '11'
                else:
                    notice = alert2
                    start = tfex_value
                    buy = shortY
                    stop = stop_shortY
                    target = text2 
                    number = '22'
                
                word_to_reply = '{}'.format(text) + '\n' + 'now {} {} ({}%)'.format(price_now,change,chgp)
                result = 'Position: {}'.format(notice) + '\n' + 'Range: {} - {} '.format(start,buy) + '\n' + 'Stop: {}'.format(stop) + '\n' + 'Target: {}'.format(target)
                linechat(word_to_reply)

                bubble = flex_tfexcheck(text,price_now,change,chgp,notice,start,buy,stop,target)
                
                flex_to_reply = SetMessage_Object(bubble)
                reply_msg(reply_token,data=flex_to_reply,bot_access_key=channel_access_token)
                return 'OK'
コード例 #5
0
            def wticheck():
                wti = wtiscrapt()

                exit_long1 = float(wti[0]) * 1.04
                exit_long1 = '%.2f'%exit_long1

                exit_long2 = float(wti[0]) * 1.08
                exit_long2 = '%.2f'%exit_long2

                exit_long3 = float(wti[0]) * 1.12
                exit_long3 = '%.2f'%exit_long3      

                exit_short1 = float(wti[0]) * 0.96
                exit_short1 = '%.2f'%exit_short1

                exit_short2 = float(wti[0]) * 0.92
                exit_short2 = '%.2f'%exit_short2

                exit_short3 = float(wti[0]) * 0.88
                exit_short3 = '%.2f'%exit_short3

                LongY = float(IQXBRT) * 1.01
                LongY = '%.2f'%LongY

                stop_longY = float(IQXBRT) * 0.985
                stop_longY = '%.2f'%stop_longY     

                shortY = float(IQXBRT) * 0.985
                shortY = '%.2f'%shortY

                stop_shortY = float(IQXBRT) * 1.01
                stop_shortY = '%.2f'%stop_shortY                    

                price_now = float(wti[0])
                price_now = '%.2f'%price_now
                price_now = str(price_now)
                
                barQ = float(price_now) - float(IQXBRT)
                chgp = str(wti[2])

                text1 = exit_long1 + ' | ' + exit_long2 + ' | ' + exit_long3 
                text2 = exit_short1 + ' | ' + exit_short2 + ' | ' + exit_short3 

                alert1 = 'Long'
                alert2 = 'Short'

                text = text_from_user
                change = str(wti[1]) 

                if barQ >= 0:
                    notice = alert1
                    start = IQXBRT
                    buy = LongY
                    stop = stop_longY
                    target = text1
                    number = '1'
                else:
                    notice = alert2
                    start = IQXBRT
                    buy = shortY
                    stop = stop_shortY
                    target = text2 
                    number = '2'
                
                word_to_reply = '{}'.format(text) + '\n' + 'now {} {} ({}%)'.format(price_now,change,chgp)
                result = 'Position: {}'.format(notice) + '\n' + 'Range: {} - {} '.format(start,buy) + '\n' + 'Stop: {}'.format(stop) + '\n' + 'Target: {}'.format(target)
                linechat(word_to_reply)
                bubble = flex_wticheck(text,price_now,change,chgp,notice,start,buy,stop,target)
                
                flex_to_reply = SetMessage_Object(bubble)
                reply_msg(reply_token,data=flex_to_reply,bot_access_key=channel_access_token)
                return 'OK'
コード例 #6
0
                def ticket(self):
                    end = datetime.now()
                    start = datetime(end.year, end.month, end.day)
                    list = self.code

                    dfY = data.DataReader(f'{list}',
                                          data_source="yahoo",
                                          start=yearly,
                                          end=end)
                    dfM = data.DataReader(f'{list}',
                                          data_source="yahoo",
                                          start=monthly,
                                          end=end)
                    #2020-01-01 = Y M D

                    OpenY = dfY['Open'].iloc[1]
                    OpenY = '%.2f' % OpenY
                    OpenY = str(OpenY)

                    OpenM = dfM['Open'].iloc[1]
                    OpenM = '%.2f' % OpenM
                    OpenM = str(OpenM)

                    OpenD = dfY['Open'].iloc[-1]
                    OpenD = '%.2f' % OpenD
                    OpenD = str(OpenD)

                    Close = dfY['Close'].iloc[-1]
                    Close = '%.2f' % Close
                    Close = str(Close)

                    Prev = dfY['Close'].iloc[-2]
                    Prev = '%.2f' % Prev
                    Prev = str(Prev)

                    barY = ((float(Close) - float(OpenY)) / float(OpenY)) * 100
                    barY = '%.2f' % barY
                    barY = float(barY)

                    barM = ((float(Close) - float(OpenM)) / float(OpenM)) * 100
                    barM = '%.2f' % barM
                    barM = float(barM)

                    LongY = float(OpenM) * 1.01
                    LongY = '%.2f' % LongY
                    LongY = str(LongY)

                    stop_longY = float(OpenM) * 0.985
                    stop_longY = '%.2f' % stop_longY
                    stop_longY = str(stop_longY)

                    exit_long1 = float(OpenD) * 1.05
                    exit_long1 = '%.2f' % exit_long1
                    exit_long1 = str(exit_long1)

                    exit_long2 = float(OpenD) * 1.10
                    exit_long2 = '%.2f' % exit_long2
                    exit_long2 = str(exit_long2)

                    exit_long3 = float(OpenD) * 1.20
                    exit_long3 = '%.2f' % exit_long3
                    exit_long3 = str(exit_long3)

                    shortY = float(OpenM) * 0.985
                    shortY = '%.2f' % shortY
                    shortY = str(shortY)

                    stop_shortY = float(OpenM) * 1.01
                    stop_shortY = '%.2f' % stop_shortY
                    stop_shortY = str(stop_shortY)

                    exit_short1 = float(OpenD) * 0.95
                    exit_short1 = '%.2f' % exit_short1
                    exit_short1 = str(exit_short1)

                    exit_short2 = float(OpenD) * 0.90
                    exit_short2 = '%.2f' % exit_short2
                    exit_short2 = str(exit_short2)

                    exit_short3 = float(OpenD) * 0.80
                    exit_short3 = '%.2f' % exit_short3
                    exit_short3 = str(exit_short3)

                    change = float(Close) - float(Prev)
                    change = '%.2f' % change
                    change = str(change)

                    chgp = (float(change) / float(Prev)) * 100
                    chgp = '%.2f' % chgp
                    chgp = str(chgp)

                    text1 = exit_long1 + ' | ' + exit_long2 + ' | ' + exit_long3
                    text2 = exit_short1 + ' | ' + exit_short2 + ' | ' + exit_short3

                    alert1 = 'Long'
                    alert2 = 'Short'

                    text = code
                    price_now = float(Close)
                    change = str(change)

                    if barM >= 0:
                        notice = alert1
                        start = OpenM
                        buy = LongY
                        stop = stop_longY
                        target = text1
                        number = '1'
                    else:
                        notice = alert2
                        start = OpenM
                        buy = shortY
                        stop = stop_shortY
                        target = text2
                        number = '2'

                    word_to_reply = '{}'.format(
                        text) + '\n' + 'now {} {} ({}%)'.format(
                            price_now, change, chgp)
                    result = 'Position: {}'.format(
                        notice) + '\n' + 'Range: {} - {} '.format(
                            start, buy) + '\n' + 'Stop: {}'.format(
                                stop) + '\n' + 'Target: {}'.format(target)
                    linechat(word_to_reply)

                    bubble = flex_crypto(text, price_now, change, chgp, notice,
                                         start, buy, stop, target)

                    flex_to_reply = SetMessage_Object(bubble)
                    reply_msg(reply_token,
                              data=flex_to_reply,
                              bot_access_key=channel_access_token)
                    return 'OK'