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

암호화폐. API. bybit. 주문 코딩규칙. http request post & response.

by i.got.it 2020. 4. 15.

개요 

암호 화폐 거래소 bybit 에서 제공하는 API 중에서 주문 관련 정리. 

주문 송신은 REST 형식으로 신규, 정정, 취소 주문 제공되며,

주문한 것의 체결 정보등은 WebSocket 형식으로 실시간 이벤트 수신처리가능하다. 

 

주문관련 무결성 코딩

코드상에서 REST 요청으로 주문한 경우 응답으로 알 수 있는 정보(주문의 정상접수, 거절) 및 WebSocket 으로 수신되는 실시간 상태 (체결여부, 강제 청산 여부 등) 확인하고 다음 로직을 진행하는 식으로 구현 해야 무결성 달성된다. 이때 주문 발행시 응답데이터 중에 order_id 와  websocket 으로 제공되는 order_id 이용하여 주문 식별 처리한다.  

 

 

 

REST Base Endpoint 

 

실거래 서버 : https://api.bybit.com

모의거래 서버 : https://api-testnet.bybit.com

 

신규 주문

POST : /v2/private/order/create

                                                     

parameter required type comments
side true string Side
symbol true string Contract type
order_type true string Active order type
qty true integer Order quantity in USD. Integer only
price false number Order price. Required if you make limit price order
time_in_force true string Time in force
take_profit false number Take profit price, only take effect upon opening the position
stop_loss false number Stop loss price, only take effect upon opening the position
reduce_only false bool Reduce only
close_on_trigger false bool Close on trigger. When creating a closing order, we highly recommend close_on_trigger is set as True to avoid failing by insufficient available margin
order_link_id false string Customised order ID, maximum length at 36 characters, and order ID under the same agency has to be unique.

 

인자 -reduce_only

reduce_only 값을 true 로 하면 기보유 포지션 청산(= Close , Exit)  주문임. 

false 로 하면 포지션 증가 시키는 진입(= Open, Entry) 주문. 

 

 

 

response 

{
    "ret_code": 0,
    "ret_msg": "OK",
    "ext_code": "",
    "ext_info": "",
    "result": {
        "user_id": 1,
        "order_id": "335fd977-e5a5-4781-b6d0-c772d5bfb95b",
        "symbol": "BTCUSD",
        "side": "Buy",
        "order_type": "Limit",
        "price": 8800,
        "qty": 1,
        "time_in_force": "GoodTillCancel",
        "order_status": "Created",
        "last_exec_time": 0,
        "last_exec_price": 0,
        "leaves_qty": 1,
        "cum_exec_qty": 0,
        "cum_exec_value": 0,
        "cum_exec_fee": 0,
        "reject_reason": "",
        "order_link_id": "",
        "created_at": "2019-11-30T11:03:43.452Z",
        "updated_at": "2019-11-30T11:03:43.455Z"
    },
    "time_now": "1575111823.458705",
    "rate_limit_status": 98,
    "rate_limit_reset_ms": 1580885703683,
    "rate_limit": 100
}

 

ret_code, ext_code 의미. 

ret_code ext_code 주문성공여부.
0 "" 성공 
0 != "" 주문생성은 했으나 , 파라메타셋팅에 실패. 
!= 0   실패

ext_code 값이 "" 이 아닌 경우 상세 정보 확인 : bybit-exchange.github.io/docs/linear/#t-errors

 

 

 

 

 

취소 주문

POST : /v2/private/order/cancel

 

parameter required type comment 
symbol true string Contract type
order_id false string Order ID. Required if not passing order_link_id
order_link_id false string Agency customized order ID. Required if not passing order_id

response

{
    "ret_code": 0,
    "ret_msg": "OK",
    "ext_code": "",
    "ext_info": "",
    "result": {
        "user_id": 1,
        "order_id": "3bd1844f-f3c0-4e10-8c25-10fea03763f6",
        "symbol": "BTCUSD",
        "side": "Buy",
        "order_type": "Limit",
        "price": 8800,
        "qty": 1,
        "time_in_force": "GoodTillCancel",
        "order_status": "New",
        "last_exec_time": 0,
        "last_exec_price": 0,
        "leaves_qty": 1,
        "cum_exec_qty": 0,
        "cum_exec_value": 0,
        "cum_exec_fee": 0,
        "reject_reason": "",
        "order_link_id": "",
        "created_at": "2019-11-30T11:17:18.396Z",
        "updated_at": "2019-11-30T11:18:01.811Z"
    },
    "time_now": "1575112681.814760",
    "rate_limit_status": 98,
    "rate_limit_reset_ms": 1580885703683,
    "rate_limit": 100
}

 

 

 

취소주문 - 모두 

POST : /v2/private/order/cancelAll

 

 

parameter required type comment
symbol true string Contract type

 

response

{
    "ret_code": 0,      
    "ret_msg": "OK",    
    "ext_code": "",     
    "ext_info": "",
    "result": [
        {
            "clOrdID": "89a38056-80f1-45b2-89d3-4d8e3a203a79",  
            "user_id": 1,                                  
            "symbol": "BTCUSD",                                
            "side": "Buy",                                      
            "order_type": "Limit",                              
            "price": "7693.5",                                  
            "qty": 1,                                           
            "time_in_force": "GoodTillCancel",                  
            "create_type": "CreateByUser",                     
            "cancel_type": "CancelByUser",                      
            "order_status": "",                                 
            "leaves_qty": 1,                                    
            "leaves_value": "0",                                
            "created_at": "2019-11-30T10:38:53.564428Z",        
            "updated_at": "2019-11-30T10:38:59.102589Z",        
            "cross_status": "PendingCancel",  // `PendingCancel` means the matching engine received the cancellation but there is no guarantee that the cancellation will be successful.
            "cross_seq": 387734027                              
        }
    ],
    "time_now": "1575110339.105675",
    "rate_limit_status": 98,
    "rate_limit_reset_ms": 1580885703683,
    "rate_limit": 100
}

 

정정 주문 

 

POST : /open-api/order/replace

 

parameter required type comment
order_id true string Your active order ID. The unique order ID returned to you when the corresponding active order was created
symbol true string Contract type.
p_r_qty false int New order quantity. Do not pass this field if you don't want modify it
p_r_price false number New order price. Do not pass this field if you don't want modify it

 

response 

{
    "ret_code": 0,    //Error code,
    "ret_msg": "ok",  //Error message,
    "ext_code": "",
    "result": {
        "order_id": "efa44157-c355-4a98-b6d6-1d846a936b93"
    },
    "time_now": "1539778407.210858",    // UTC timestamp
    "rate_limit_status": 99, // The remaining number of accesses in one minute
    "rate_limit_reset_ms": 1580885703683,
    "rate_limit": 100             
}

 

 

 

 

 

response 데이터 항목 상세

 

 

Create type (create_type)

  • CreateByUser
  • CreateByClosing
  • CreateByAdminClosing
  • CreateByStopOrder
  • CreateByTakeProfit
  • CreateByStopLoss
  • CreateByTrailingStop
  • CreateByLiq - Created by partial liquidation
  • CreateByAdl_PassThrough - Created by ADL
  • CreateByTakeOver_PassThrough - Created by liquidation takeover

 

Order status (order_status)

Filter fetched orders by their order statuses. To filter by multiple statuses, separate with a comma like so: Filled,New

  • Created
  • Rejected - order is triggered but fail to be placed
  • New
  • PartiallyFilled
  • Filled
  • Cancelled
  • PendingCancel - The matching engine has received the cancellation but there is no guarantee that it will be successful

 

Order type (order_type)

  • Limit
  • Market

Symbol (symbol)

  • BTCUSD
  • ETHUSD
  • EOSUSD
  • XRPUSD

 

Time in force (time_in_force)

  • GoodTillCancel
  • ImmediateOrCancel
  • FillOrKill
  • PostOnly

 

 

from : https://bybit-exchange.github.io/docs/inverse/#t-placev2active

 

////////////////////////////////////////////////////////

 

 

Query Active Order 

- 종목1개의 order_id 1개의 정보 요청. 

 

GET /v2/private/order

 

Response Example

{
    "ret_code": 0,
    "ret_msg": "OK",
    "ext_code": "",
    "ext_info": "",
    "result": {
        "user_id": 1,
        "symbol": "BTCUSD",
        "side": "Sell",
        "order_type": "Limit",
        "price": "8083",
        "qty": 10,
        "time_in_force": "GoodTillCancel",
        "order_status": "New",
        "ext_fields": {
            "o_req_num": -308787,
            "xreq_type": "x_create",
            "xreq_offset": 4154640
        },
        "leaves_qty": 10,
        "leaves_value": "0.00123716",
        "cum_exec_qty": 0,
        "reject_reason": "",
        "order_link_id": "",
        "created_at": "2019-10-21T07:28:19.396246Z",
        "updated_at": "2019-10-21T07:28:19.396246Z",
        "order_id": "efa44157-c355-4a98-b6d6-1d846a936b93"
    },
    "time_now": "1571651135.291930",
    "rate_limit_status": 99, // The remaining number of accesses in one minute
    "rate_limit_reset_ms": 1580885703683,
    "rate_limit": 100
}

 

 

http request 로 주문정보 받기 상세 

 

암호화폐. 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

 

 

 

 

////////////////////////////////////////////////////////// 

 

WebSocket 형식으로 주문관련 실시간 수신 가능한 데이터. 

 

2개의 토픽 order , execution  제공. 

 

order 

 

요청 : websocket 의 send('{"op": "subscribe", "args": ["order"]}')

- 1회만 실행하면 이후 아래 데이터 자동으로 수신됨.

 

Response Example


{
    "topic": "order",
    "data": [
        {
            "order_id": "xxxxxxxx-xxxx-xxxx-9a8f-4a973eb5c418",
            "order_link_id": "",
            "symbol": "BTCUSD",
            "side": "Sell",
            "order_type": "Market",
            "price": "8579.5",
            "qty": 1,
            "time_in_force": "ImmediateOrCancel",
            "create_type": "CreateByClosing",
            "cancel_type": "",
            "order_status": "Filled",
            "leaves_qty": 0,
            "cum_exec_qty": 1,
            "cum_exec_value": "0.00011655",
            "cum_exec_fee": "0.00000009",
            "timestamp": "2020-01-14T14:09:31.778Z",
            "take_profit": "0",
            "stop_loss": "0",
            "trailing_stop": "0",
            "trailing_active": "0",
            "last_exec_price": "8300"
        }
    ]
}

 

order 타입의 websocket 수신 정보 상세 별도정리. 

 

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

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

igotit.tistory.com

 

 

 

execution 

- 주문 한것의 체결정보 실시간. 

요청 : websocket 의 send('{"op": "subscribe", "args": ["execution"]}'

- 1회만 실행하면 이후 아래 데이터 자동으로 수신됨.

 

Response Example

{
    "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
        }
    ]
}

 

 

 

상위

 

 

암호화폐 매매 정보 정리.

가격 단위 : 달러 - 암화폐거래소. - 암호화폐 API . - 접근성 좋은 거래소 쾌적한 매매 환경 - 유동성 풍부. 변동성 양호. - 완전한 연속거래시장. 거래 휴일 없음. - 암호화폐 매매 관련 정보 정리

igotit.tistory.com

 


첫 등록 : 2020.03.18

최종 수정 : 

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

 


 

 

 

 

 

 

 

 

 

 

댓글



 

비트코인




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