Notice
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 코인
- 롱숏비율
- orderbook
- place_active_order
- 비트코인
- kline
- 파아썬
- 데이터불러오기
- 머신러닝
- open_interest
- 모멘텀지표
- 백테스팅
- 변동성돌파
- Query_Kline
- 바이비트
- Public_Trading_Records
- bitcoin
- 파이썬
- Query_Premium_Index_Kline
- API
- 자동매매
- latest_big_deal
- Machine Learning
- Python
- 프리미엄지수
- 호가창
- Bybit
- Query_Index_Price_Kline
- myposition
- xgboost
Archives
- Today
- Total
돈벌고싶다
바이비트 파이썬 API - 최근 거래 데이터 본문
728x90
반응형
정의
public trading records 함수. 공식 문서에서는 "Get recent trades." 라 하여, 최근 거래 데이터를 불러온다는 뜻이다. 주가 데이터를 불러오는 쿼리인 Query Kline 와 다른 점은 Public Trading Records의 경우 거래된 가격과 수량을 알려준다는 점이다. 즉 Query Kline은 시간이 기준이지만, Public Trading Records는 거래 발생이 기준이다. 이는 거래량이 기준인 것과는 다르다는 점을 유의해야 한다.
코드
import pandas as pd
from pybit import usdt_perpetual
session = usdt_perpetual.HTTP("https://api-testnet.bybit.com")
response = session.public_trading_records(symbol="BTCUSDT", limit=1000)['result']
data = pd.DataFrame(response)
data['time'] = pd.to_datetime(data['time'])
data
Request Parameters
Parameter | Required | Type | Comment |
symbol | true | string | 코인명 |
limit | false | int | 데이터 수. default 값은 500이며, 최대 1000개까지 가져올 수 있다. |
Response Parameters
Parameter | Type | Comment |
symbol | string | 코인명 |
price | number | 거래가 성립된 가격 |
qty | number | 물량 |
side | string | 롱/숏 포지션 포현 |
time | string | 거래된 시간(UTC 기준) |
위 코드를 실행할 경우 output으로 정리된 데이터프레임을 얻을 수 있다.
결과 시각화 예시
ax = data[data['side']=='Sell'].plot(x="time", y="qty", color="Blue", label="Sell", kind='scatter', figsize=(10, 8))
data[data['side']=='Buy'].plot(x="time", y="qty", color="Red", label="Buy", ax=ax, kind='scatter', figsize=(10, 8))
시간 - 물량 그래프이다. 숏의 물량은 파란색으로, 롱의 물량은 빨간색으로 표현하였다.
ax = data[data['side']=='Sell'].plot(x="time", y="price", color="Blue", label="Sell", kind='line', figsize=(10, 8))
data[data['side']=='Buy'].plot(x="time", y="price", color="Red", label="Buy", ax=ax, kind='line', figsize=(10, 8))
시간 - 가격 그래프이다. 평균값에서 벗어나는 경우가 매우 빈번한 것을 보아, 시장가(Market) 매매를 진행할 경우 지속적으로 손해를 볼 가능성이 높음을 알 수 있다.
728x90
반응형
'바이비트 python API 뜯어보기' 카테고리의 다른 글
바이비트 파이썬 API - 프리미엄 지수 가격 데이터 (0) | 2022.05.16 |
---|---|
바이비트 파이썬 API - 지수 가격 데이터 (0) | 2022.05.16 |
바이비트 파이썬 API - 롱숏 비율 데이터 (0) | 2022.05.15 |
바이비트 파이썬 API - 포지션 확인 (1) | 2022.05.13 |
바이비트 파이썬 API - 주문 (0) | 2022.05.12 |
Comments