Skip to content

Commit

Permalink
add new subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-y committed Dec 11, 2019
1 parent bd9f71b commit ba78880
Show file tree
Hide file tree
Showing 22 changed files with 819 additions and 47 deletions.
13 changes: 13 additions & 0 deletions CHANGE_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The SDK supports both synchronous RESTful API invoking, and subscribe the market

## Table of Contents

- [Huobi Global API C++ SDK version 1.0.9](#Huobi-Global-API-c++-SDK-version-1.0.9)

- [Huobi Global API C++ SDK version 1.0.8](#Huobi-Global-API-c++-SDK-version-1.0.8)

- [Huobi Global API C++ SDK version 1.0.7](#Huobi-Global-API-c++-SDK-version-1.0.7)
Expand All @@ -32,6 +34,17 @@ The SDK supports both synchronous RESTful API invoking, and subscribe the market

- [Huobi Global API C++ SDK version 1.0.1](#Huobi-Global-API-c++-SDK-version-1.0.1)

## Huobi Global API Cpp SDK version 1.0.9

[***version 1.0.9***](https://github.com/HuobiRDCenter/huobi_Cpp/releases)
***2019-12-11***

- add subscribe
```
add subscribe accounts.update#{mode}
add subscribe trade.clearing#${symbol}
```
## Huobi Global API Cpp SDK version 1.0.8
[***version 1.0.8***](https://github.com/HuobiRDCenter/huobi_Cpp/releases)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The SDK supports both synchronous RESTful API invoking, and subscribe the market

## Huobi C++ SDK Download

- [Huobi Global API C++ SDK version 1.0.9](https://github.com/HuobiRDCenter/huobi_Cpp/releases/tag/1.0.9)

- [Huobi Global API C++ SDK version 1.0.8](https://github.com/HuobiRDCenter/huobi_Cpp/releases/tag/1.0.8)

- [Huobi Global API C++ SDK version 1.0.7](https://github.com/HuobiRDCenter/huobi_Cpp/releases/tag/1.0.7)
Expand Down
2 changes: 1 addition & 1 deletion config.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define CURRENT_VERSION 1.0.8
#define CURRENT_VERSION 1.0.9
131 changes: 131 additions & 0 deletions examples/SubscribeAccountUpdateEvent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
cmake_minimum_required(VERSION 2.8)

#设置编译器
IF (CMAKE_COMPILER_TYPE MATCHES "GCC")
SET(CMAKE_C_COMPILER "gcc")
SET(CMAKE_CXX_COMPILER "g++")
ELSEIF (CMAKE_COMPILER_TYPE MATCHES "CLANG")
SET(CMAKE_C_COMPILER "clang")
SET(CMAKE_CXX_COMPILER "clang++")
ENDIF ()

SET(CMAKE_C_FLAGS "-Wall -std=c99")
SET(CMAKE_C_FLAGS_DEBUG "-g")
SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")

SET(CMAKE_CXX_FLAGS "-Wall -std=c++11")
SET(CMAKE_CXX_FLAGS_DEBUG "-g")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")


#判断操作系统
IF (WIN32)
MESSAGE(STATUS "Now is windows")
ELSEIF (APPLE)
MESSAGE(STATUS "Now is Apple systens.")
ELSEIF (UNIX)
MESSAGE(STATUS "Now is UNIX-like OS's. Including aPPLE os x and CygWin")
ENDIF ()

if (UNIX AND NOT APPLE)
set(platform x64)
set(LINUX TRUE)
endif ()

if (APPLE)
endif ()



if (LINUX)
message(STATUS "当前操作系统: Linux")
endif ()

if (APPLE)
message(STATUS "当前操作系统: MacOS")
endif ()

MESSAGE(STATUS "operation system is ${CMAKE_SYSTEM}")

PROJECT(SubscribeAccountUpdateEvent)

AUX_SOURCE_DIRECTORY(. DIR_SRCS)
ADD_EXECUTABLE(${PROJECT_NAME} ${DIR_SRCS})

IF (CMAKE_BUILD_TYPE MATCHES "Release")
SET(CMAKE_BUILD_POSTFIX ${CMAKE_BUILD_TYPE})
ELSEIF(CMAKE_BUILD_TYPE MATCHES "Debug")
SET(CMAKE_BUILD_POSTFIX ${CMAKE_BUILD_TYPE})
ELSE()
MESSAGE(FATAL_ERROR "The CMAKE_BUILD_TYPE only supports Release or Debug")
ENDIF()


find_library(LIBHUOBICLIENT_PATH HuobiClient)
IF(NOT LIBHUOBICLIENT_PATH)
message(${HUOBI_CLIENT_DIR}/lib/${CMAKE_BUILD_POSTFIX})
MESSAGE(FATAL_ERROR "HuobiClient not found")
ENDIF(NOT LIBHUOBICLIENT_PATH)
MESSAGE(STATUS ${LIBHUOBICLIENT_PATH} " found")


find_library(LIBWEBSOCKET_PATH websockets)
IF(NOT LIBWEBSOCKET_PATH)
MESSAGE(FATAL_ERROR "libwebsockets not found")
ENDIF(NOT LIBWEBSOCKET_PATH)
MESSAGE(STATUS ${LIBWEBSOCKET_PATH} " found")

find_library(LIBSSL_PATH ssl)
IF(NOT LIBSSL_PATH)
MESSAGE(FATAL_ERROR "libssl not found")
ENDIF(NOT LIBSSL_PATH)
MESSAGE(STATUS ${LIBSSL_PATH} " found")

find_library(LIBCRYPTO_PATH crypto)
IF(NOT LIBCRYPTO_PATH)
MESSAGE(FATAL_ERROR "libcrypto not found")
ENDIF(NOT LIBCRYPTO_PATH)
MESSAGE(STATUS ${LIBCRYPTO_PATH} " found")

find_library(LIBCURL_PATH curl)
IF(NOT LIBCURL_PATH)
MESSAGE(FATAL_ERROR "curl not found")
ENDIF(NOT LIBCURL_PATH)
MESSAGE(STATUS ${LIBCURL_PATH} " found")

find_library(LIBZ_PATH z)
IF(NOT LIBZ_PATH)
MESSAGE(FATAL_ERROR "z not found")
ENDIF(NOT LIBZ_PATH)
MESSAGE(STATUS ${LIBZ_PATH} " found")

find_library(LIBPTHREAD_PATH pthread)
IF(NOT LIBPTHREAD_PATH)
MESSAGE(FATAL_ERROR "pthread not found")
ENDIF(NOT LIBPTHREAD_PATH)
MESSAGE(STATUS ${LIBPTHREAD_PATH} " found")

find_library(LIBDECNUMBER_PATH decnumber)
IF(NOT LIBDECNUMBER_PATH)
MESSAGE(FATAL_ERROR "decnumber not found")
ENDIF(NOT LIBDECNUMBER_PATH)
MESSAGE(STATUS ${LIBDECNUMBER_PATH} " found")

FIND_PATH(
LIBDECNUMBER_INCLUDE_DIR
decNumber.h
/usr/include/decnumber/
/usr/local/include/decnumber/
)
include_directories(${LIBDECNUMBER_INCLUDE_DIR})
include_directories(/usr/local/include)

add_definitions(-std=c++11)

TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIBHUOBICLIENT_PATH} ${LIBDECNUMBER_PATH} ${LIBSSL_PATH} ${LIBCRYPTO_PATH} ${LIBWEBSOCKET_PATH} ${LIBCURL_PATH} ${LIBZ_PATH} ${LIBPTHREAD_PATH})


29 changes: 29 additions & 0 deletions examples/SubscribeAccountUpdateEvent/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
#include <iostream>
#include "Huobi/HuobiClient.h"


using namespace Huobi;
using namespace std;

int main(int argc, char** argv) {
SubscriptionClient* subscriptionClient = createSubscriptionClient(
"xxx", "xxx");
subscriptionClient->subscribeAccountUpdateEvent(AccountsUpdateMode::balanceAndaAvailable, [](AccountUpdateEvent event) {
cout << "---- accountId: " << event.accountId << " ----" << endl;
cout << "---- accountType: " << event.accountType.getValue() << " ----" << endl;
cout << "---- available: " << event.available << " ----" << endl;
cout << "---- balance: " << event.balance << " ----" << endl;
cout << "---- changeTime: " << event.changeTime << " ----" << endl;
cout << "---- changeType: " << event.changeType.getValue() << " ----" << endl;
cout << "---- currency: " << event.currency << " ----" << endl;

});
subscriptionClient->startService();


}
132 changes: 132 additions & 0 deletions examples/SubscribeTradeClearingEvent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
cmake_minimum_required(VERSION 2.8)

#设置编译器
IF (CMAKE_COMPILER_TYPE MATCHES "GCC")
SET(CMAKE_C_COMPILER "gcc")
SET(CMAKE_CXX_COMPILER "g++")
ELSEIF (CMAKE_COMPILER_TYPE MATCHES "CLANG")
SET(CMAKE_C_COMPILER "clang")
SET(CMAKE_CXX_COMPILER "clang++")
ENDIF ()

SET(CMAKE_C_FLAGS "-Wall -std=c99")
SET(CMAKE_C_FLAGS_DEBUG "-g")
SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")

SET(CMAKE_CXX_FLAGS "-Wall -std=c++11")
SET(CMAKE_CXX_FLAGS_DEBUG "-g")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")


#判断操作系统
IF (WIN32)
MESSAGE(STATUS "Now is windows")
ELSEIF (APPLE)
MESSAGE(STATUS "Now is Apple systens.")
ELSEIF (UNIX)
MESSAGE(STATUS "Now is UNIX-like OS's. Including aPPLE os x and CygWin")
ENDIF ()

if (UNIX AND NOT APPLE)
set(platform x64)
set(LINUX TRUE)
endif ()

if (APPLE)
endif ()



if (LINUX)
message(STATUS "当前操作系统: Linux")
endif ()

if (APPLE)
message(STATUS "当前操作系统: MacOS")
endif ()

MESSAGE(STATUS "operation system is ${CMAKE_SYSTEM}")

PROJECT(SubscribeTradeClearingEvent)

AUX_SOURCE_DIRECTORY(. DIR_SRCS)
ADD_EXECUTABLE(${PROJECT_NAME} ${DIR_SRCS})

IF (CMAKE_BUILD_TYPE MATCHES "Release")
SET(CMAKE_BUILD_POSTFIX ${CMAKE_BUILD_TYPE})
ELSEIF(CMAKE_BUILD_TYPE MATCHES "Debug")
SET(CMAKE_BUILD_POSTFIX ${CMAKE_BUILD_TYPE})
ELSE()
MESSAGE(FATAL_ERROR "The CMAKE_BUILD_TYPE only supports Release or Debug")
ENDIF()


find_library(LIBHUOBICLIENT_PATH HuobiClient)
IF(NOT LIBHUOBICLIENT_PATH)
message(${HUOBI_CLIENT_DIR}/lib/${CMAKE_BUILD_POSTFIX})
MESSAGE(FATAL_ERROR "HuobiClient not found")
ENDIF(NOT LIBHUOBICLIENT_PATH)
MESSAGE(STATUS ${LIBHUOBICLIENT_PATH} " found")


find_library(LIBWEBSOCKET_PATH websockets)
IF(NOT LIBWEBSOCKET_PATH)
MESSAGE(FATAL_ERROR "libwebsockets not found")
ENDIF(NOT LIBWEBSOCKET_PATH)
MESSAGE(STATUS ${LIBWEBSOCKET_PATH} " found")

find_library(LIBSSL_PATH ssl)
IF(NOT LIBSSL_PATH)
MESSAGE(FATAL_ERROR "libssl not found")
ENDIF(NOT LIBSSL_PATH)
MESSAGE(STATUS ${LIBSSL_PATH} " found")

find_library(LIBCRYPTO_PATH crypto)
IF(NOT LIBCRYPTO_PATH)
MESSAGE(FATAL_ERROR "libcrypto not found")
ENDIF(NOT LIBCRYPTO_PATH)
MESSAGE(STATUS ${LIBCRYPTO_PATH} " found")

find_library(LIBCURL_PATH curl)
IF(NOT LIBCURL_PATH)
MESSAGE(FATAL_ERROR "curl not found")
ENDIF(NOT LIBCURL_PATH)
MESSAGE(STATUS ${LIBCURL_PATH} " found")

find_library(LIBZ_PATH z)
IF(NOT LIBZ_PATH)
MESSAGE(FATAL_ERROR "z not found")
ENDIF(NOT LIBZ_PATH)
MESSAGE(STATUS ${LIBZ_PATH} " found")

find_library(LIBPTHREAD_PATH pthread)
IF(NOT LIBPTHREAD_PATH)
MESSAGE(FATAL_ERROR "pthread not found")
ENDIF(NOT LIBPTHREAD_PATH)
MESSAGE(STATUS ${LIBPTHREAD_PATH} " found")

find_library(LIBDECNUMBER_PATH decnumber)
IF(NOT LIBDECNUMBER_PATH)
MESSAGE(FATAL_ERROR "decnumber not found")
ENDIF(NOT LIBDECNUMBER_PATH)
MESSAGE(STATUS ${LIBDECNUMBER_PATH} " found")

FIND_PATH(
LIBDECNUMBER_INCLUDE_DIR
decNumber.h
/usr/include/decnumber/
/usr/local/include/decnumber/
)
include_directories(${LIBDECNUMBER_INCLUDE_DIR})
include_directories(/usr/local/include)

add_definitions(-std=c++11)

TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIBHUOBICLIENT_PATH} ${LIBDECNUMBER_PATH} ${LIBSSL_PATH} ${LIBCRYPTO_PATH} ${LIBWEBSOCKET_PATH} ${LIBCURL_PATH} ${LIBZ_PATH} ${LIBPTHREAD_PATH})



38 changes: 38 additions & 0 deletions examples/SubscribeTradeClearingEvent/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
#include <iostream>
#include "Huobi/HuobiClient.h"


using namespace Huobi;
using namespace std;

int main(int argc, char** argv) {
SubscriptionClient* subscriptionClient = createSubscriptionClient(
"xxx", "xxx");
subscriptionClient->subscribeTradeClearingEvent("htusdt", [](TradeClearingEvent event) {
cout << "---- aggressor: " << event.aggressor << " ----" << endl;
cout << "---- feeDeduct: " << event.feeDeduct << " ----" << endl;
cout << "---- feeDeductType: " << event.feeDeductType << " ----" << endl;
cout << "---- orderId: " << event.orderId << " ----" << endl;
cout << "---- orderSide: " << event.orderSide.getValue() << " ----" << endl;
cout << "---- orderType: " << event.orderType.getValue() << " ----" << endl;
cout << "---- symbol: " << event.symbol << " ----" << endl;
cout << "---- tradeId: " << event.tradeId << " ----" << endl;
cout << "---- tradePrice: " << event.tradePrice << " ----" << endl;
cout << "---- tradeTime: " << event.tradeTime << " ----" << endl;
cout << "---- tradeVolume: " << event.tradeVolume << " ----" << endl;
cout << "---- transactFee: " << event.transactFee << " ----" << endl;




});
subscriptionClient->startService();


}

Loading

0 comments on commit ba78880

Please sign in to comment.