본문 바로가기
트레이딩/암호화폐

암호화폐. API. bybit. 주문 체결 정보 실시간 받기. websocket

by i.got.it 2021. 1. 4.

 

개요 

- 거래소 바이빗의 USD 종목, USDT 종목  주문한 것이 체결될 때  WebSocket 으로 실시간 수신되는 정보. 

- 1회 수신 데이터에 여러 종목의 데이터가 같이 제공될 수 있음. 

 

사전준비 

- 파이썬 웹소켓 기본 코딩 달성하고 인증 코딩 까지 달성한 상태. 

 

 

USD 종목에서의 체결 정보 

 

execution 요청 구문. 

 

websocket.send('{"op": "subscribe", "args": ["execution"]}')

 

상기 요청 한번만 요청하면 이후 내 주문이 체결 된 경우 아래와 같은 정보요소들이 json 형식으로 실시간 수신됨.

 

 

Response Parameters

 

parameter type comments
symbol string Symbol
side string Side
order_id string Order ID
exec_id string Transaction ID
order_link_id string Order link ID
price string Transaction price
order_qty number Order qty
exec_type string Exec Type Enum 4종 : Trade, AdlTrade, Funding, BustTrade 
exec_qty number Transaction qty
exec_fee string Transaction fee
leaves_qty number Number of unfilled contracts from the order's size
is_maker bool Is maker
trade_time string Transaction timestamp

 

 

 

{
    "topic": "execution",
    "data": [
        {
            "symbol": "BTCUSD",
            "side": "Buy",
            "order_id": "xxxxxxxx-xxxx-xxxx-9a8f-4a973eb5c418",
            "exec_id": "xxxxxxxx-xxxx-xxxx-8b66-c3d2fcd352f6",
            "order_link_id": "",
            "price": "8300",
            "order_qty": 1,
            "exec_type": "Trade",
            "exec_qty": 1,
            "exec_fee": "0.00000009",
            "leaves_qty": 0,
            "is_maker": false,
            "trade_time": "2020-01-14T14:07:23.629Z" // trade time
        }
    ]
}


예 : EOSUSD 주문수량 1달러 시장가 매도, 매수 주문한 것이 체결된 시점 수신된 데이터. 

 

 

USDT 종목에서의 체결 정보 

execution 요청 구문. 

websocket.send('{"op": "subscribe", "args": ["execution"]}')

 

한번만 요청하면 이후 내 주문이 체결 된 경우 아래와 같은 정보요소들이 json 형식으로 실시간 수신됨.

 

Response Parameters

parameter type comments
symbol string Symbol
side string Side
order_id string Order ID
exec_id string Transaction ID
order_link_id string Order link ID
price string Transaction price
order_qty number Order qty
exec_type string Exec Type Enum 4종 : Trade, AdlTrade, Funding, BustTrade 
exec_qty number Transaction qty
exec_fee string Transaction fee
trade_time string Transaction timestamp

비교 : USD 종목에 있는 leaves_qty, is_maker 는 USDT 종목에서는 제공안됨. 그외 동일. 

 

예:

{
    "topic": "execution",
    "data": [
        {
            "symbol": "BTCUSDT",
            "side": "Sell",
            "order_id": "xxxxxxxx-xxxx-xxxx-9a8f-4a973eb5c418",
            "exec_id": "xxxxxxxx-xxxx-xxxx-8b66-c3d2fcd352f6",
            "order_link_id": "",
            "price": 11527.5,
            "order_qty": 0.001,
            "exec_type": "Trade",
            "exec_qty": 0.001,
            "exec_fee": 0.00864563,
            "leaves_qty": 0,
            "is_maker": false,
            "trade_time": "2020-08-12T21:16:18.142746Z"
        }
    ]
}

 

 

 

execution  활용 코드 예. 

- 아래코드는 실시간 execution 활용 코드 전체 골격 예  보인다. 

 

- 라인 92 에서 execution 요청하였고, 이후 실시간으로 수신되는 데이터들을 문자열로 확보하는 곳이 라인 94 while 문 내의 라인 95   data_rcv_strjson 에서 확보된다. 

 

- 라인 97 함수 processing_all_ws_received(data_rcv_strjson)  을 호출하여 수신된 데이터가 어떤 형식의 데이터 이냐에 따른  분리 처리 수행한다. 

 

- 라인 34 def processing_all_ws_received(str_json): 함수 내부에서 수신한 웹소켓 수신 데이터 중에 execution 인 경우 실행되는 것은 라인 75  조건문의 함수 processing_execution(data_dic_one)  이다. 

 

- 라인 2 함수 def processing_execution(data_dic_one):  가 execution 으로 수신된 정보 처리기 이며 ,  라인 3의 leaves_qty 는 미체결 잔량인데 전량 체결된 경우에는 이 값이 0 이된다. 본 코드예에서는 주문한 수량이 모두 체결된 경우에만 처리하는 코드예 이기 때문에 leaves_qty 가 0보다 큰 경우에는 처리하지 않고 무처리 리턴(라인 4, 5)하고 있다.

 

- 라인 24~ 28 이 전량체결 에 대응한 주문 처리하는 구간이며 라인 25 조건은 매수 주문한 것이 전량 체결된 것일 때, 라인 26 에서 신규 매도 주문 송신하고 , 라인 27  매도 주문한것이 전량 체결이라면 신규 매수 주문 송신한다. 

 

 

 

 

 

 

연관 

 

 

 

 

 

 

암호화폐. API. bybit. 나의 주문 정보 실시간 받기. websocket

개요 거래소 바이빗의 USD 종목, USDT 종목 내가 주문 송신한것에 의한 WebSocket 으로 실시간 수신되는 주문응답. USD 종목에서의 주문 실시간 정보 order 실시간 정보 요청 구문. websocket.send('{"op": "subsc

igotit.tistory.com

 

 

 

 

암호화폐. API. bybit. 나의 주문 정보 받기. http request

개요 - 바이빗의 USD 종목 , USDT종목의 내 주문정보 HTTP Request 로 받기. USD 종목 의 주문정보 받기 HTTP Request GET /v2/private/order Request Parameters parameter required type comments order_id fals..

igotit.tistory.com

 

 

 


첫 등록 : 2021.01.04

최종 수정 : 2022.05.30

단축 주소 : https://igotit.tistory.com/2745

 


 

댓글



 

비트코인




암호화폐       외환/나스닥/골드       암호화폐/외환/나스닥/골드 암호화폐/외환/나스닥/골드   암호화폐/외환/나스닥/골드
     
현물 |선물 인버스 |선물 USDT       전략매니저(카피트레이딩)     롤오버 이자 없는 스왑프리계좌
( 스왑프리 암호화폐도 거래 가능 )    
MT4, MT5 , cTrader 모두 지원     FTMO 계좌 매매운용. MT4,MT5