본문 바로가기

Upbit trading bot - 4 본문

개인 프로젝트 공부

Upbit trading bot - 4

Seongjun_You 2024. 7. 23. 19:25
def get_BB():
    df = pyupbit.get_ohlcv("KRW-BTC", interval="minute240")
    data_BB = modules.data_processing.Bollinger_Band(df)
    return [df, data_BB]

pyupbit 라이브러리를 활용해 쉽게 캔들 정보와 지표들을 활용할 수 있었다.

매매나 계좌정보도 가능한 것 같다.

get_ohlcv를 통해 캔들정보를 가져오고 볼린저밴드를 계산해 준다.

4시간 차트기준이다.

 

def Bollinger_Band(df):
    pd.set_option('display.float_format', lambda x: '%.2f' % x)
    df['middle'] = df['close'].rolling(window=20).mean()
    std = df['close'].rolling(20).std(ddof=0)
    df['upper'] = df['middle'] + 2 * std
    df['lower'] = df['middle'] - 2 * std

    return df[['upper', 'middle', 'lower']].tail(n=10)

볼린저밴드의 값들을 구해 넘겨준다.

캔들 10개의 값만 넘겼다.

 

 

{
  "buy" : {
    "timestamp": 0,
    "bollinger_top" : 0,
    "bollinger_bottom" : 0,
    "open" : 0,
    "high" : 0,
    "low" : 0,
    "close" : 0
  },
  "flag" : 0,
  "revenue" : 0
}

새로운 json파일을 만들었다.

매매 진행 시 기록을 저장하기 위함이다.

매수를 진행할 때 기록을 남기고 매도할 때는 해당 json파일을 확인하고 매도한다.

이는 매매 코드를 작성할 때 사용할 예정이다.

 

 

캔들과 볼린저밴드 그리고 계좌정보를 출력했다.

 

'개인 프로젝트 공부' 카테고리의 다른 글

Upbit trading bot - 6  (0) 2024.07.30
Upbit trading bot - 5  (0) 2024.07.28
Upbit trading bot - 3  (1) 2024.07.22
Upbit trading bot - 2  (0) 2024.07.19
Upbit trading bot - 1  (0) 2024.07.15
Comments