22047, 1/1103 ȸ¿ø°¡ÀÔ  ·Î±×ÀΠ 
   ÇØÅ·ÀßÇÏ°í½Í´Ù
   http://¾øÀ½
   test(backup)

http://www.hackerschool.org/HS_Boards/zboard.php?id=Free_Board&no=37823 [º¹»ç]


import pyupbit
import numpy as np
import pandas as pd
import time
import datetime
import re
import os
import matplotlib.pyplot as plt

# ³¯Â¥ °¹¼ö Â÷ÀÌ ±¸Çϱâ
def cal_data_different(coin, interval, day_count):
    df = pd.read_excel(os.path.join(os.getcwd(),'C:/Users/mark/Desktop/',f"{coin}.xlsx"),index_col=0)
    past = datetime.datetime.strptime(str(df.iloc[-1].name), f'%Y-%m-%d %H:%M:00')
    now = datetime.datetime.now().strftime(f'%Y-%m-%d %H:%M:00')
    now = datetime.datetime.strptime(now, f'%Y-%m-%d %H:%M:00')
    diff = str(now-past)
    n = re.sub(r'[^0-9]', '', interval, day_count)
    h, m, s = list(map(int, diff.split(":")))
    total_time_diff = (h * 60) + m + s # ºÐÀ¸·Î ȯ»ê
    total_diff_num = int(total_time_diff / int(n))

    if "day" in diff: # intervalÀÌ dayÀÌ»ó ³Ñ¾î°¥ °æ¿ì
        print("Create new file")
        df = pyupbit.get_ohlcv(coin, count=day_count, interval=interval)
        time.sleep(0.1)
        df = df.drop('value', axis=1)
        df = cal_indicators(df)
        df.to_excel(excel_writer="C:/Users/mark/Desktop/{coin}.xlsx")       # ¿¢¼¿ ÀúÀå
        print(f"{coin} Data is saved. . . ")
        return df
    else:
        if total_diff_num > 0: # °»½ÅÀÌ ÇÊ¿äÇÒ°æ¿ì
            print('Update Required.') # str(df.iloc[-1,0])
            orig_df = df.copy()
            dfs = pyupbit.get_ohlcv(coin, count=total_diff_num, interval=interval)
            dfs = dfs.drop('value', axis=1)
            df = pd.concat([df,dfs], ignore_index=False)
            cal_df = cal_indicators(df[-50:])
            df = pd.concat([orig_df,cal_df[-total_diff_num:]])
            df.to_excel(excel_writer=f'C:/Users/mark/Desktop/{coin}.xlsx')
            print(f"Success Update.({coin} update {total_diff_num} amount)")
            return df
        else: # °»½ÅÀÌ ÇÊ¿ä ¾øÀ» °æ¿ì
            print("No update")
            return df

# µ¥ÀÌÅÍ ½Ç½Ã°£ ÀúÀåÇϱâ
def save_DataFrame(coin, interval, day_count):
    coin = coin            # ÄÚÀθí
    interval = interval        # Â÷Æ®ÀÇ Á¾·ù (minute1,3,5,10,15,30,60), day
    day_count = day_count           # µ¥ÀÌÅÍ ¼ö
    
    if os.path.exists(os.path.join(os.getcwd(),'C:/Users/mark/Desktop/',f"{coin}.xlsx")): # data°¡ ÀÖÀ» °æ¿ì
        print("File exist.")
        return cal_data_different(coin, interval, day_count)

    else: # data °¡ ¾øÀ» °æ¿ì
        print("Create new Dataframe file")
        df = pyupbit.get_ohlcv(coin, count=day_count, interval=interval)
        time.sleep(0.1)
        df = df.drop('value', axis=1)
        df = cal_indicators(df)
        df.to_excel(excel_writer=f"C:/Users/mark/Desktop/{coin}.xlsx")       # ¿¢¼¿ ÀúÀå
        print(f"{coin} Data is saved. . . ")
        return df

# ÇöÀç°¡ Á¶È¸
def get_current_price(coin):
    print(pyupbit.get_current_price(coin))
    return pyupbit.get_current_price(coin)

# º¸Á¶ÁöÇ¥ ±¸Çϱâ
def cal_indicators(DataFrame):
    df = DataFrame
    # Moving Average
    df['MA3'] = df['close'].rolling(window=3).mean()
    df['MA5'] = df['close'].rolling(window=5).mean()
    df['MA10'] = df['close'].rolling(window=10).mean()
    df['MA15'] = df['close'].rolling(window=15).mean()
    df['MA20'] = df['close'].rolling(window=20).mean() # 20ÀÏ Æò±Õ À̵¿ : Áß°£ º¼¸°Àú ¹êµå
    df['MA30'] = df['close'].rolling(window=30).mean()

    # RSI
    rsi_interval = 14
    df['U'] = np.where(df.diff(1)['close'] > 0, df.diff(1)['close'],0)
    df['D'] = np.where(df.diff(1)['close'] < 0, df.diff(1)['close']*(-1), 0)
    df['AU'] = df['U'].rolling(rsi_interval).mean()
    df['AD'] = df['D'].rolling(rsi_interval).mean()
    df['RSI'] = (df['AU'] / (df['AU']+df['AD'])) *100
    # df['RSI_Signal'] = df['RSI'].rolling(9).mean()
    del df['U'], df['D'], df['AU'], df['AD']

    # MACD
    df['MACD_EMA12'] = df['close'].ewm(span=12).mean()
    df['MACD_EMA26'] = df['close'].ewm(span=26).mean()
    df['MACD'] = df['MACD_EMA12'] - df['MACD_EMA26']
    df['MACD_signal'] = df['MACD'].ewm(span=9).mean()

    # Bollinger Band
    
    df['Bollinger_stddev'] = df['close'].rolling(window=20).std() # 20ÀÏ À̵¿ Ç¥ÁØÆíÂ÷
    df['Bollinger_upper'] = df['MA20'] + (df['Bollinger_stddev'] * 2) # »ó´Ü º¼¸°Àú ¹êµå
    df['Bollinger_lower'] = df['MA20'] - (df['Bollinger_stddev'] * 2) # »ó´Ü º¼¸°Àú ¹êµå
    return df



##############################################################################################

if __name__ =="__main__":
    pd.set_option('mode.chained_assignment',  None) # °æ°í off

    
    print("-----------------------Main-----------------------")
    print(f'Stat time : {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}')
    
    # ±âº» ¼ÂÆÃ
    start_time = datetime.datetime.now()
    coins = pyupbit.get_tickers(fiat="KRW-BTC") # ÄÚÀεé
    interval = "day"        # Â÷Æ®ÀÇ Á¾·ù (minute1,3,5,10,15,30,60), day
    day_count = 365          # Á¶È¸ÇÒ µ¥ÀÌÅÍ ¾ç

    # # µ¥ÀÌÅÍ ÀúÀå ȤÀº ºÒ·¯¿À±â, µ¥ÀÌÅÍ °¡°øÇϱâ
    while True:
        for coin in coins:
            df = save_DataFrame(coin,interval,day_count)
            time.sleep(1)

  Hit : 338     Date : 2024/09/13 01:40



    
     [°øÁö]ÇØÄ¿½ºÄð ÀÌ¿ë¼öÄ¢ 2021/04/11 ¼öÁ¤ÆÇ [51] ÇѽÂÀç 01/05 9444
22046   Ç϶ó´Â ÇØÅ·Àº ¾È ÇÏ°í -part9-     ÇØÅ·ÀßÇÏ°í½Í´Ù
12/08 101
22045   Ç϶ó´Â ÇØÅ·Àº ¾È ÇÏ°í -part8-     ÇØÅ·ÀßÇÏ°í½Í´Ù
12/08 57
22044   Ç϶ó´Â ÇØÅ·Àº ¾È ÇÏ°í -part7-     ÇØÅ·ÀßÇÏ°í½Í´Ù
12/08 64
22043   Ç϶ó´Â ÇØÅ·Àº ¾È ÇÏ°í -part6-     ÇØÅ·ÀßÇÏ°í½Í´Ù
12/08 64
22042   À½¾ÇÀåºñ ´ë½Å ´Ù¸¥°É Áú·¶...     ÇØÅ·ÀßÇÏ°í½Í´Ù
12/03 82
22041   ·Îµå¸Ê     ÇØÅ·ÀßÇÏ°í½Í´Ù
12/03 76
22040   ÇØÅ·º¸¾È °ú¿Ü ÁøÇàÇÕ´Ï´Ù.     sysadm
12/03 72
22039   ·¦ ³ìÀ½ ÇÏ·Á°í Çϴµ­...     ÇØÅ·ÀßÇÏ°í½Í´Ù
11/22 118
22038   Drunken Tiger... Drunken Ka0r1...     ÇØÅ·ÀßÇÏ°í½Í´Ù
11/22 99
22037   À©µµ¿ì Ãë¾àÁ¡ ¿¬±¸Çã½Ç ¹é¼ö ¸ðÁý[1]     µ¹¸Íµ¹¸Í
11/10 210
22036   Æ÷³Êºí¿¡ µµ¿òÀÌ µÇ´Â ÀÚ·á     ÇØÅ·ÀßÇÏ°í½Í´Ù
10/24 391
22035   Ç϶ó´Â ÇØÅ·Àº ¾È ÇÏ°í -part5-     ÇØÅ·ÀßÇÏ°í½Í´Ù
10/22 441
22034   Ç϶ó´Â ÇØÅ·Àº ¾È ÇÏ°í -part4-     ÇØÅ·ÀßÇÏ°í½Í´Ù
10/22 923
22033   Ç϶ó´Â ÇØÅ·Àº ¾È ÇÏ°í -part3-     ÇØÅ·ÀßÇÏ°í½Í´Ù
10/22 354
22032   ÇØÅ· º¸¾È °ü·Ã °ú¿Ü¸¦ ÁøÇàÇÕ´Ï´Ù.     bluewindsoul
10/12 344
22031   º¸ÀÌ´Â °ÍÀÌ ´Ù´Â ¾Æ´Ñµ¥     ÇØÅ·ÀßÇÏ°í½Í´Ù
09/16 387
22030   ¿ÀǼҽº¸¦ ¼öÁ¤Çϸ鼭 ÄÚµùÁß     ÇØÅ·ÀßÇÏ°í½Í´Ù
09/13 426
  test(backup)     ÇØÅ·ÀßÇÏ°í½Í´Ù
09/13 337
22028   µðÁöÅÐ Æ÷·»½Ä with ctf (ctf-d)     cocookie0
09/03 602
1 [2][3][4][5][6][7][8][9][10]..[1103]

Copyright 1999-2024 Zeroboard / skin by Hackerschool.org / Secure Patch by Hackerschool.org