Get Open Orders
- 거래소에 접수 되어 있는 주문들 확보.
Get Open Orders. HTTP Request
GET /v5/order/realtime
Get Open Orders . 요청 인자
Parameter | Required | Type | Comments |
category | true | string | Product type
|
symbol | false | string | Symbol name. For linear, either symbol, baseCoin, settleCoin is required |
baseCoin | false | string | Base coin. Supports linear, inverse & option. For option. Return all option open orders if not passed |
settleCoin | false | string | Settle coin
|
orderId | false | string | Order ID |
orderLinkId | false | string | User customised order ID |
openOnly | false | integer |
|
orderFilter | false | string | Order: active order, StopOrder: conditional order for Futures and Spot, tpslOrder: spot TP/SL order, OcoOrder: UTA spot OCO orders only
|
limit | false | integer | Limit for data size per page. [1, 50]. Default: 20 |
cursor | false | string | Cursor. Use the nextPageCursor token from the response to retrieve the next page of the result set |
Get Open Orders . 응답 데이터
{
"retCode": 0,
"retMsg": "OK",
"result": {
"list": [
{
"orderId": "fd4300ae-7847-404e-b947-b46980a4d140",
"orderLinkId": "test-000005",
"blockTradeId": "",
"symbol": "ETHUSDT",
"price": "1600.00",
"qty": "0.10",
"side": "Buy",
"isLeverage": "",
"positionIdx": 1,
"orderStatus": "New",
"cancelType": "UNKNOWN",
"rejectReason": "EC_NoError",
"avgPrice": "0",
"leavesQty": "0.10",
"leavesValue": "160",
"cumExecQty": "0.00",
"cumExecValue": "0",
"cumExecFee": "0",
"timeInForce": "GTC",
"orderType": "Limit",
"stopOrderType": "UNKNOWN",
"orderIv": "",
"triggerPrice": "0.00",
"takeProfit": "2500.00",
"stopLoss": "1500.00",
"tpTriggerBy": "LastPrice",
"slTriggerBy": "LastPrice",
"triggerDirection": 0,
"triggerBy": "UNKNOWN",
"lastPriceOnCreated": "",
"reduceOnly": false,
"closeOnTrigger": false,
"smpType": "None",
"smpGroup": 0,
"smpOrderId": "",
"tpslMode": "Full",
"tpLimitPrice": "",
"slLimitPrice": "",
"placeType": "",
"createdTime": "1684738540559",
"updatedTime": "1684738540561"
}
],
"nextPageCursor": "page_args%3Dfd4300ae-7847-404e-b947-b46980a4d140%26symbol%3D6%26",
"category": "linear"
},
"retExtInfo": {},
"time": 1684765770483
}
Parameter | Type | Comments |
category | string | Product type |
nextPageCursor | string | Refer to the cursor request parameter |
list | array | Object |
> orderId | string | Order ID |
> orderLinkId | string | User customised order ID |
> blockTradeId | string | Paradigm block trade ID |
> symbol | string | Symbol name |
> price | string | Order price |
> qty | string | Order qty |
> side | string | Side. Buy,Sell |
> isLeverage | string | Whether to borrow. Unified spot only. 0: false, 1: true. . Classic spot is not supported, always 0 |
> positionIdx | integer | Position index. Used to identify positions in different position modes. |
> orderStatus | string | Order status |
> cancelType | string | Cancel type |
> rejectReason | string | Reject reason. Classic spot is not supported |
> avgPrice | string | Average filled price. If unfilled, it is "0" |
> leavesQty | string | The remaining qty not executed. Classic spot is not supported |
> leavesValue | string | The estimated value not executed. Classic spot is not supported |
> cumExecQty | string | Cumulative executed order qty |
> cumExecValue | string | Cumulative executed order value. Classic spot is not supported |
> cumExecFee | string | Cumulative executed trading fee. Classic spot is not supported |
> timeInForce | string | Time in force |
> orderType | string | Order type. Market,Limit. For TP/SL order, it means the order type after triggered |
> stopOrderType | string | Stop order type |
> orderIv | string | Implied volatility |
> triggerPrice | string | Trigger price. If stopOrderType=TrailingStop, it is activate price. Otherwise, it is trigger price |
> takeProfit | string | Take profit price |
> stopLoss | string | Stop loss price |
> tpslMode | string | TP/SL mode, Full: entire position for TP/SL. Partial: partial position tp/sl. Spot does not have this field, and Option returns always "" |
> ocoTriggerType | string | The trigger type of Spot OCO order.OcoTriggerByUnknown, OcoTriggerTp, OcoTriggerBySl. Classic spot is not supported |
> tpLimitPrice | string | The limit order price when take profit price is triggered |
> slLimitPrice | string | The limit order price when stop loss price is triggered |
> tpTriggerBy | string | The price type to trigger take profit |
> slTriggerBy | string | The price type to trigger stop loss |
> triggerDirection | integer | Trigger direction. 1: rise, 2: fall |
> triggerBy | string | The price type of trigger price |
> lastPriceOnCreated | string | Last price when place the order |
> reduceOnly | boolean | Reduce only. true means reduce position size |
> closeOnTrigger | boolean | Close on trigger. What is a close on trigger order? |
> placeType | string | Place type, option used. iv, price |
> smpType | string | SMP execution type |
> smpGroup | integer | Smp group ID. If the UID has no group, it is 0 by default |
> smpOrderId | string | The counterparty's orderID which triggers this SMP execution |
> createdTime | string | Order created timestamp (ms) |
> updatedTime | string | Order updated timestamp (ms) |
VC++ 코드 구현예.
- 요청하고 확보된 데이터 파싱 하는 부분까지.
/*
2023.10.26
api v5
종목1개의 alive 주문들 확보.
v5 에서 데이터 반환받는 수량 줄었음. 구버전에서는 1회요청에 500개 가능.
limit : Limit for data size per page. [1, 50]. Default: 20
1회에 500개 모두 못받기때문에 cursor 정보 이용하여 여러번 호출해야함.
Response Example
{
"retCode": 0,
"retMsg": "OK",
"result": {
"list": [
{
"orderId": "fd4300ae-7847-404e-b947-b46980a4d140",
"orderLinkId": "test-000005",
"blockTradeId": "",
"symbol": "ETHUSDT",
"price": "1600.00",
"qty": "0.10",
"side": "Buy",
"isLeverage": "",
"positionIdx": 1,
"orderStatus": "New",
"cancelType": "UNKNOWN",
"rejectReason": "EC_NoError",
"avgPrice": "0",
"leavesQty": "0.10",
"leavesValue": "160",
"cumExecQty": "0.00",
"cumExecValue": "0",
"cumExecFee": "0",
"timeInForce": "GTC",
"orderType": "Limit",
"stopOrderType": "UNKNOWN",
"orderIv": "",
"triggerPrice": "0.00",
"takeProfit": "2500.00",
"stopLoss": "1500.00",
"tpTriggerBy": "LastPrice",
"slTriggerBy": "LastPrice",
"triggerDirection": 0,
"triggerBy": "UNKNOWN",
"lastPriceOnCreated": "",
"reduceOnly": false,
"closeOnTrigger": false,
"smpType": "None",
"smpGroup": 0,
"smpOrderId": "",
"tpslMode": "Full",
"tpLimitPrice": "",
"slLimitPrice": "",
"placeType": "",
"createdTime": "1684738540559",
"updatedTime": "1684738540561"
}
],
"nextPageCursor": "page_args%3Dfd4300ae-7847-404e-b947-b46980a4d140%26symbol%3D6%26",
"category": "linear"
},
"retExtInfo": {},
"time": 1684765770483
}
*/
int CCyRestBybit_Spot::http_get_OpenOrders(CCyD_CyFinSymbol::Symbol* p_symbol, std::string current_page_cursor, std::string* next_page_cursor)
{
std::string str_query;
if (current_page_cursor.compare("first_igotit") == 0)
{
str_query = "category=spot&symbol=" + p_symbol->map_FieldValue["name_api"] + "&limit=50";
}
else
{
str_query = "category=spot&symbol=" + p_symbol->map_FieldValue["name_api"] + "&limit=50" + "&cursor=" + current_page_cursor;
}
// 처리1. timestamp+api_key+recv_window+queryString
std::string timestamp = std::to_string(CyUtilTime::get_time_ms()); // 밀리초 단위의 현재시각.
std::string recv_window = "5000";
std::string str_hmac_input = timestamp + m_ApiKey + recv_window + str_query;
// 처리2. HMAC_SHA256
std::string sign = m_CCyUtilSSL.hmac_sha256(m_ApiSecret.c_str(), str_hmac_input.c_str());
// 처리3. http header
std::string http_header = "";
http_header.append("X-BAPI-SIGN: " + sign);
http_header.append("\nX-BAPI-API-KEY: " + m_ApiKey);
http_header.append("\nX-BAPI-TIMESTAMP: " + timestamp);
http_header.append("\nX-BAPI-RECV-WINDOW: " + recv_window);
http_header.append("\nContent-Type: application/json");
// 처리4. http get with header.
std::string url_with_query = m_AddressBase + URL_OpenOrders_V5 + "?" + str_query;
std::string result;
m_CCyRestAPI.https_get_header(url_with_query, http_header, &result);
//수신된 result 파싱처리.
rapidjson::Document m_RJDoc;
m_RJDoc.Parse(result.c_str());
if (m_RJDoc.HasParseError())
{
Display_Status_Ext("CCyRestBybit_Spot::http_get_OpenOrders", "error doc_json parse");
return -1;
}
int ret_code = m_RJDoc["retCode"].GetInt();
if (0 != ret_code) // 0 아니면 실패.
{
CString cst_msg(m_RJDoc["retMsg"].GetString());
CString cst_ret_code; cst_ret_code.Format(L"retCode = %d . ", ret_code);
Display_Status_Ext(L"CCyRestBybit_Spot::http_get_OpenOrders. error message = ", cst_ret_code + cst_msg);
return -2;
}
if (m_RJDoc.HasMember("result") == 0) {
Display_Status_Ext("CCyRestBybit_Spot ::http_get_OpenOrders : ", "error :no key found result");
return -2;
}
const rapidjson::Value& rj_val = m_RJDoc["result"]["list"];
int i_size = rj_val.Size();
std::string oid_exchange;
//std::string str_side;
CCyD_CyFinSymbol::AliveOrder alive_order;
for (rapidjson::SizeType i = 0; i < i_size; i++)//
{
Forced_MessageHandler();
alive_order.oid_exchange = rj_val[i]["orderId"].GetString();
alive_order.oid_cfs = rj_val[i]["orderLinkId"].GetString();
alive_order.oid_num_cfs = CCyUtilTime::Get_OID_NUM_CFS_ThreadSafe(alive_order.oid_cfs);
alive_order.str_Price = rj_val[i]["price"].GetString();
alive_order.str_Qty = rj_val[i]["qty"].GetString();
alive_order.str_Side = rj_val[i]["side"].GetString();
if (NULL == p_symbol->m_pAliveOrders->create_alive_order(&alive_order)) {
//Display_Status_Ext("CCyRestBybit_Spot :: Acquire_AliveOrder : ", map_para["symbol"] + " : p_symbol->m_pAliveOrders->create_alive_order() is NULL");
continue;
}
// 시험출력.
// Display_Status_Ext("CCyRestBybit_Spot :: Acquire_AliveOrder : Symbol = " + map_para["symbol"], "oid_cfs = " + alive_order.oid_cfs + " oid_num = " + std::to_string(alive_order.oid_num_cfs));
}
// 현재수신된 nextPageCursor
*next_page_cursor = m_RJDoc["result"]["nextPageCursor"].GetString();
return 1;
}
상위정리
첫 등록 : 2023.10.26
최종 수정 :
단축 주소 : https://igotit.tistory.com/4955
'트레이딩 > 암호화폐' 카테고리의 다른 글
bybit . API V5 . rest . 주문하기 (0) | 2023.10.27 |
---|---|
bybit . API V5 . rest . authentication 처리 (0) | 2023.10.26 |
bybit . API V5 . 웹소켓 . authentication 처리 (0) | 2023.10.26 |
bybit . API V5 . 웹소켓 Order , Execution . 내 주문 처리 정보 실시간 수신 (1) | 2023.10.26 |
bybit . API V5 . 웹소켓 Trade . 실시간 시세 수신 (0) | 2023.10.25 |
댓글