Skip to main content

bithumb-api

Asynchronus Python Wrapper for Bithumb API Based on pybithumb: https://github.com/sharebook-kr/pybithumb

Installation

pip install async-bithumb

Import

import asyncio
from async_bithumb import Bithumb

Public API

암호화폐 목록

빗썸이 지원하는 암호화폐 목록을 얻어온다.

print(asyncio.run(Bithumb.get_tickers()))
['BTC', 'ETH', 'DASH', 'LTC', 'ETC', 'XRP', 'BCH', 'XMR', 'ZEC', 'QTUM', 'BTG', 'EOS', 'ICX', 'TRX', 'ELF', 'MCO', 'OMG', 'KNC', 'GNT', 'ZIL', 'WAXP', 'POWR', 'LRC', 'STEEM', 'STRAT', 'AE', 'ZRX', 'REP', 'XEM', 'SNT', 'ADA', 'CTXC', 'BAT', 'WTC', 'THETA', 'LOOM', 'WAVES', 'ITC', 'TRUE', 'LINK', 'RNT', 'ENJ', 'PLX', 'VET', 'MTL', 'INS', 'IOST', 'TMTG', 'QKC', 'BZNT', 'HDAC', 'NPXS', 'LBA', 'WET', 'AMO', 'BSV', 'APIS', 'DAC', 'ORBS', 'VALOR', 'CON', 'ANKR', 'MIX', 'LAMB', 'CRO', 'FX', 'CHR', 'MBL', 'MXC', 'FAB', 'OGO', 'DVP', 'FCT', 'FNB', 'FZZ', 'TRV', 'PCM', 'DAD', 'AOA', 'XSR', 'WOM', 'SOC', 'EM', 'QBZ', 'BOA', 'WPX', 'FLETA', 'BNP', 'SXP', 'COS', 'EL', 'BASIC', 'HC', 'BCD', 'XVG', 'XLM', 'PIVX', 'GXC', 'BHP', 'BTT', 'HYC', 'VSYS', 'IPX', 'WICC', 'LUNA', 'AION', 'COSM']

최근 체결가격

get_current_price 함수는 최근 체결 가격을 조회한다.

for coin in asyncio.run(Bithumb.get_tickers())[:5]:
    print(coin, asyncio.run(Bithumb.get_current_price(coin)))
BTC 8190000.0
ETH 171900.0
DASH 82450.0
LTC 48810.0
ETC 6180.0

시장 현황 상세정보

get_market_detail 함수는 00시 기준으로 시가/고가/저가/종가/거래량 정보를 반환한다.

for coin in  asyncio.run(Bithumb.get_tickers()):
    print(coin, asyncio.run(Bithumb.get_market_detail(coin)))
BTC (8162000.0, 8240000.0, 8050000.0, 8190000.0, 3117.77267769)
ETH (170500.0, 172600.0, 168000.0, 171500.0, 34816.2510681)
DASH (81950.0, 82700.0, 80600.0, 82450.0, 1651.47875125)
LTC (48440.0, 49410.0, 48270.0, 48810.0, 3344.70736905)
ETC (6150.0, 6250.0, 6075.0, 6180.0, 77986.83409064)

매수/매도 호가

get_orderbook 함수는 호가 정보를 가져온다. 기본적으로 5개를 가져오며, limit 파라미터로 30개까지 지정할 수 있다.

for coin in  asyncio.run(Bithumb.get_tickers()):
    print(coin, asyncio.run(Bithumb.get_orderbook(coin)))

시간별 가격정보

시가/종가/고가/저가/거래량 정보를 DataFrame으로 반환한다.

df = asyncio.run(Bithumb.get_candlestick("BTC"))
print(df.tail(5))
                       open      close       high        low        volume
time
2020-03-30 15:00:00  7740000.0  7848000.0  8019000.0  7683000.0   7913.696718
2020-03-31 15:00:00  7847000.0  7630000.0  7893000.0  7534000.0   5163.670206
2020-04-01 15:00:00  7633000.0  8194000.0  8216000.0  7569000.0   9123.583777
2020-04-02 15:00:00  8193000.0  8162000.0  8499000.0  8057000.0  11354.950247
2020-04-04 08:00:00  8162000.0  8177000.0  8240000.0  8050000.0   3082.263414

chart_intervals 파라미터로 조회 간격을 조정할 수 있다.

  • 1m, 3m, 5m, 10m, 30m, 1h, 6h, 12h, 24h
df = asyncio.run(Bithumb.get_candlestick("BTC", chart_intervals="30m"))
print(df.tail(5))

웹소켓

WebSocket을 이용해서 현재가, 호가, 체결에 대한 정보를 수신한다.

  • 첫 번째 파라미터로 수신정보를 입력하며 ticker, orderbook, transaction을 사용할 수 있다.
  • 두 번째 파라미터는 구독할 필터를 설정하며 암호화폐의 티커를 입력한다. 현재 버전에서는 원화 시장만을 지원한다.
if __name__ == "__main__":
    wm = WebSocketManager("ticker", ["BTC_KRW"])
    for i in range(10):
        data = wm.get()
        print(data)
    wm.terminate()

주의할 사항은 multiprocessing을 위해 __name__ guard를 반드시 써줘야한다는 것이다.

PyQt5와 함께 웹소켓을 사용하는 예제는 다음과 같다.

Private API

로그인

connectkey와 secretkey를 사용해서 로그인한다. 두 key를 생성하는 방법은 링크를 참조한다.

bithumb = Bithumb("conkey", "seckey")

수수료 조회

print(asyncio.run(bithumb.get_trading_fee()))

잔고 조회

for coin in asyncio.run(Bithumb.get_tickers():)
    print(coin, asyncio.run(bithumb.get_balance(coin)))

매수/매도 주문

비트코인을 1100만원에 1개 매수/매도한다.

desc = asyncio.run(bithumb.buy_limit_order("BTC", 11000000, 1))
desc = asyncio.run(bithumb.sell_limit_order("BTC", 11000000, 1))

매수/매도 잔량 확인

quanity = asyncio.run(bithumb.get_outstanding_order(desc))

매수/매도 주문 취소

status = asyncio.run(bithumb.cancel_order(desc))

마켓별 주문 조회

비트코인 원화 마켓의 최신 주문내역을 가져온다.

status = asyncio.run(bithumb.user_transactions("BTC", "KRW"))

Metadata

Release files for async-bithumb 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for async-bithumb 1.0.6
File Size Uploaded
async-bithumb-1.0.6.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for async-bithumb 1.0.6
File Interpreter ABI Platform
async_bithumb-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 25.8 kB

Release files / async-bithumb-1.0.6.tar.gz

Download URL async-bithumb-1.0.6.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6a2fb07dea51c5818e31126f34d65a42447c9a4f8c9c4ebcde9ee407da6b84b0
BLAKE2b-256 checksum
How to use checksums
9cf1dea0cbeac47d04218263a3f77e27a8821d05b6e2df2332ccea5aebb5273e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.3

Release files / async_bithumb-1.0.6-py3-none-any.whl

Download URL async_bithumb-1.0.6-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b27ea436ccf5807c3f1c4995f271cdda1840b83f684e3081bdf23e28901e0b06
BLAKE2b-256 checksum
How to use checksums
3d67f6da537f1cdf7a32fffb6a00152b3c1398105b984ca1835b9b2eaa4e0eeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.3

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page