Files
DeepStock/bithumb/Bithumb_Example.py
dsyoon 4a453f36b6 init
2023-01-21 19:29:02 +09:00

84 lines
2.8 KiB
Python

import pybithumb
con_key = "946dd0b0e6f8ad411144cd33f09518d3" # 본인의 Connect Key를 입력한다.
sec_key = "56b2a3cdd9fe3a82aa3f38c97c161125" # 본인의 Secret Key를 입력한다.
# bithumb api에 연결한 클라스 객체를 선언한다.
bithumb = pybithumb.Bithumb(con_key, sec_key)
def bull_market(ticker):
df = pybithumb.get_ohlcv(ticker)
m5 = df['close'].rolling(5).mean()
last_m5 = m5[-2]
price = pybithumb.get_current_price(ticker)
if price > last_m5:
return True
else:
return False
# 상장된 코인 Tickers 확인하기
#print (bithumb.get_tickers())
tickers = ['XRP']
for ticker in tickers:
# 과거 시세 얻기
result = pybithumb.get_ohlcv(ticker)
print(result)
is_bull = bull_market(ticker)
if is_bull:
print(ticker, "상승장")
else:
print(ticker, "하락장")
# [잔고 확인하기]
# - 비트코인의 총 잔고
# - 거래 중인 비트코인의 수량
# - 보유 중인 총원화
# - 주문에 사용된 원화
# (4.978e-05, 0.0, 3438133.120299, 0)
print (bithumb.get_balance(ticker))
# [매수]
# buy_limit_order() 메서드의 파라미터로 구매하고자 하는 가상화폐의
# 티커, 지정가, 매수 수량을 순서대로 입력합니다
# order = ('bid', 'BTC', 'C0101000000322993432', 'KRW')
order = bithumb.buy_limit_order(ticker, 300, 1)
print(order)
# 미체결 주문 확인
# get_balance를 통해 지정가 주문이 들어간 금액만큼 매수에 사용된 원화의 값이 확인된다. 39098.5에 해당된다.
# (0.04588863, 0.0, 3438133.120299, 39098.5)
print (bithumb.get_balance(ticker))
# 주문 취소 하기
cancel = bithumb.cancel_order(order)
print(cancel) # True
# 호가창 Order Book 살펴보기
orderbook = pybithumb.get_orderbook('BTC')
print (orderbook)
# bids의 최상단 66883000.0원이 매수 최상단 금액 (매수자가 기꺼이 지불하려고 하는 최대 금액)
# asks의 최상단 66919000.0원이 매도 최하단 금액 (판매자가 판매하고자 하는 최소 금액)
"""
{'timestamp': '1616913007272',
'payment_currency': 'KRW',
'order_currency': 'BTC',
'bids': [{'price': 66883000.0, 'quantity': 0.0951},
{'price': 66881000.0, 'quantity': 0.0607},
{'price': 66880000.0, 'quantity': 0.503},
{'price': 66878000.0, 'quantity': 0.0415},
{'price': 66868000.0, 'quantity': 0.0293}],
'asks': [{'price': 66919000.0, 'quantity': 0.9946},
{'price': 66927000.0, 'quantity': 0.002},
{'price': 66936000.0, 'quantity': 0.0382},
{'price': 66937000.0, 'quantity': 0.1541},
{'price': 66939000.0, 'quantity': 0.188}]}
"""