Skip to content

Commit

Permalink
Fix memory issue in websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
eynzhang committed Aug 20, 2020
1 parent dfeb907 commit 3cf543d
Show file tree
Hide file tree
Showing 94 changed files with 115 additions and 177 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If you already use SDK v1, it is strongly suggested migrate to v2 as we refactor
- [Installation](#Installation)
- [Run examples](#Run-examples)
- [Client](#client)
- [Migrate from v1](#Migrate-from-v1)
- [Migrate from v1](#Migrate-from-v1)
- [Request example](#Request-example)
- [Reference data](#Reference-data)
- [Market data](#Market-data)
Expand Down
22 changes: 22 additions & 0 deletions demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.10...3.17)
project(demo LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)

include_directories(/usr/local/huobi)

add_subdirectory(account)
add_subdirectory(crossmargin)
add_subdirectory(isolatedmargin)
add_subdirectory(market)
add_subdirectory(reference)
add_subdirectory(trade)
add_subdirectory(wallet)
add_subdirectory(websocketAsset)
add_subdirectory(websocketMarket)
add_subdirectory(websocketOrders)

find_package(cpprestsdk REQUIRED)

link_directories(/usr/local/lib/)
link_directories(/usr/local/huobi/)
1 change: 0 additions & 1 deletion demo/account/accountdemo.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include <client/accountClient.h>

using namespace std;
Expand Down
2 changes: 0 additions & 2 deletions demo/crossmargin/crossmargindemo.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#include <client/crossMarginClient.h>

using namespace std;
Expand Down
2 changes: 0 additions & 2 deletions demo/isolatedmargin/isolatedmargindemo.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#include <client/isolatedMarginClient.h>

using namespace std;
Expand Down
2 changes: 0 additions & 2 deletions demo/reference/referencedemo.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#include <iostream>
#include <client/referenceClient.h>

Expand Down
2 changes: 0 additions & 2 deletions demo/trade/tradedemo.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#include <client/tradeClient.h>

using namespace std;
Expand Down
2 changes: 0 additions & 2 deletions demo/wallet/walletdemo.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#include <client/walletClient.h>

using namespace std;
Expand Down
4 changes: 1 addition & 3 deletions demo/websocketAsset/websocketAssetdemo.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@


#include <iostream>
#include <client/websocketAssetClient.h>

using namespace std;

int main() {
websocketAssetClient client{APIKEY, SECRETKEY};
WebsocketAssetClient client{APIKEY, SECRETKEY};

client.subAccounts(1, [](AccountsUpdate accountsUpdate) {
cout << accountsUpdate.changeType << endl;
Expand Down
3 changes: 1 addition & 2 deletions demo/websocketMarket/websocketMarketdemo.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

#include <iostream>
#include <client/websocketMarketClient.h>

using namespace std;

int main() {
websocketMarketClient client;
WebsocketMarketClient client;
const char *symbol = "htusdt";
client.subKline(symbol, "1min", [](Candlestick candlestick) {
cout << candlestick.amount << endl;
Expand Down
4 changes: 1 addition & 3 deletions demo/websocketOrders/websocketOrdersdemo.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@


#include <iostream>
#include <client/websocketOrdersClient.h>

using namespace std;

int main() {
websocketOrdersClient client{APIKEY, SECRETKEY};
WebsocketOrdersClient client{APIKEY, SECRETKEY};

client.subOrders("htusdt", [](OrdersUpdate ordersUpdate) {
cout << ordersUpdate.symbol << endl;
Expand Down
45 changes: 45 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#
# Ubuntu Dockerfile
#
# https://github.com/dockerfile/ubuntu
#

# Pull base image.
FROM ubuntu:18.04

# Install.
RUN \
sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list && \
apt-get update && \
apt-get -y upgrade && \
apt-get install -y build-essential && \
apt-get install -y curl git vim wget cmake && \
apt-get install -y libssl-dev libcurl4-openssl-dev zlib1g-dev libcpprest-dev && \
rm -rf /var/lib/apt/lists/*

# Set environment variables.
ENV HOME /root

# Define working directory.
WORKDIR /root

RUN \
git clone https://github.com/huobiapi/huobi_Cpp.git && \
cd huobi_Cpp && \
mkdir build && \
cd build && \
cmake .. -DCMAKE_PREFIX_PATH=/opt/cpprest-2.10.16/lib64/cmake/ && \
make && \
make install

WORKDIR /root

RUN \
cd huobi_Cpp/demo/reference && \
mkdir build && \
cd build && \
cmake .. -DCMAKE_PREFIX_PATH=/opt/cpprest-2.10.16/lib64/cmake/ -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/cmake && \
make

# Define default command.
CMD ["bash"]
2 changes: 0 additions & 2 deletions include/client/accountClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_ACCOUNTCLIENT_H
#define HUOBI_ACCOUNTCLIENT_H

Expand Down
2 changes: 0 additions & 2 deletions include/client/crossMarginClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_CROSSMARGINCLIENT_H
#define HUOBI_CROSSMARGINCLIENT_H

Expand Down
2 changes: 0 additions & 2 deletions include/client/isolatedMarginClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_ISOLATEDMARGINCLIENT_H
#define HUOBI_ISOLATEDMARGINCLIENT_H

Expand Down
2 changes: 0 additions & 2 deletions include/client/marketClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_MARKETCLIENT_H
#define HUOBI_MARKETCLIENT_H

Expand Down
2 changes: 0 additions & 2 deletions include/client/referenceClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_REFERENCECLIENT_H
#define HUOBI_REFERENCECLIENT_H

Expand Down
2 changes: 0 additions & 2 deletions include/client/tradeClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_TRADECLIENT_H
#define HUOBI_TRADECLIENT_H

Expand Down
2 changes: 0 additions & 2 deletions include/client/walletClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_WALLETCLIENT_H
#define HUOBI_WALLETCLIENT_H

Expand Down
6 changes: 2 additions & 4 deletions include/client/websocketAssetClient.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@


#ifndef HUOBI_WEBSOCKETASSETCLIENT_H
#define HUOBI_WEBSOCKETASSETCLIENT_H

#include "include.h"

struct websocketAssetClient {
websocketAssetClient(char *accessKey, char *secretKey) : signature{accessKey, secretKey} {
struct WebsocketAssetClient {
WebsocketAssetClient(char *accessKey, char *secretKey) : signature{accessKey, secretKey} {
}

void subAccounts(int mode, const std::function<void(const AccountsUpdate &)> &handler);
Expand Down
4 changes: 1 addition & 3 deletions include/client/websocketHelper.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_WEBSOCKETHELPER_H
#define HUOBI_WEBSOCKETHELPER_H

Expand All @@ -10,7 +8,7 @@ using namespace web;
using namespace web::websockets::client;
using namespace rapidjson;

struct websocketHelper {
struct WebsocketHelper {
static websocket_outgoing_message pong(string ping);

static websocket_outgoing_message buildSubTopic(string topic);
Expand Down
4 changes: 1 addition & 3 deletions include/client/websocketMarketClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_WEBSOCKETMARKETCLIENT_H
#define HUOBI_WEBSOCKETMARKETCLIENT_H

Expand All @@ -11,7 +9,7 @@ using namespace web;
using namespace web::websockets::client;
using namespace rapidjson;

struct websocketMarketClient {
struct WebsocketMarketClient {
void subKline(const char *symbol, const char *period, const std::function<void(const Candlestick &)> &handler);

void reqKline(const char *symbol, const char *period, long from, long to,
Expand Down
6 changes: 2 additions & 4 deletions include/client/websocketOrdersClient.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@


#ifndef HUOBI_WEBSOCKETORDERSCLIENT_H
#define HUOBI_WEBSOCKETORDERSCLIENT_H

#include "include.h"

struct websocketOrdersClient {
websocketOrdersClient(char *accessKey, char *secretKey) : signature{accessKey, secretKey} {
struct WebsocketOrdersClient {
WebsocketOrdersClient(char *accessKey, char *secretKey) : signature{accessKey, secretKey} {
}

void subOrders(const char* symbol, const std::function<void(const OrdersUpdate &)> &handler);
Expand Down
4 changes: 1 addition & 3 deletions include/define.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@


#ifndef HUOBI_DEFINE_H
#define HUOBI_DEFINE_H

#define GET "GET"
#define POST "POST"

#define HOST "api.huobi.de.com"
#define HOST "api.huobi.pro"
#define SPLICE(x) "https://" HOST x
#define WEBSOCKET_HOST "wss://api.huobi.pro/ws"
#define WEBSOCKET_V2_HOST "wss://api.huobi.pro/ws/v2"
Expand Down
2 changes: 0 additions & 2 deletions include/gzDecompress.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_GZDECOMPRESS_H
#define HUOBI_GZDECOMPRESS_H
#include <zlib.h>
Expand Down
2 changes: 0 additions & 2 deletions include/include.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_INCLUDE_H
#define HUOBI_INCLUDE_H

Expand Down
2 changes: 0 additions & 2 deletions include/request/accounts/futurestransfer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_FUTURESTRANSFERREQUEST_H
#define HUOBI_FUTURESTRANSFERREQUEST_H

Expand Down
2 changes: 0 additions & 2 deletions include/request/accounts/historyrequest.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_ACCOUNTHISTORYREQUEST_H
#define HUOBI_ACCOUNTHISTORYREQUEST_H

Expand Down
2 changes: 0 additions & 2 deletions include/request/accounts/ledger.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_ACCOUNTLEDGERREQUEST_H
#define HUOBI_ACCOUNTLEDGERREQUEST_H

Expand Down
2 changes: 0 additions & 2 deletions include/request/accounts/managesubuser.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_MANAGESUBUSERREQUEST_H
#define HUOBI_MANAGESUBUSERREQUEST_H

Expand Down
2 changes: 0 additions & 2 deletions include/request/accounts/subusertransfer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_SUBUSERTRANSFERREQUEST_H
#define HUOBI_SUBUSERTRANSFERREQUEST_H

Expand Down
2 changes: 0 additions & 2 deletions include/request/crossMargin/loanorders.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_CROSSMARGINLOANORDERSREQUEST_H
#define HUOBI_CROSSMARGINLOANORDERSREQUEST_H

Expand Down
2 changes: 0 additions & 2 deletions include/request/crossMargin/transferorapply.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_CROSSMARGINTRANSFERORAPPLYREQUEST_H
#define HUOBI_CROSSMARGINTRANSFERORAPPLYREQUEST_H

Expand Down
1 change: 0 additions & 1 deletion include/request/isolatedMargin/balance.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#ifndef HUOBI_ISOLATEDMARGINBALANCEREQUEST_H
#define HUOBI_ISOLATEDMARGINBALANCEREQUEST_H

Expand Down
2 changes: 0 additions & 2 deletions include/request/isolatedMargin/loanorders.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_LOANORDERSREQUEST_H
#define HUOBI_LOANORDERSREQUEST_H

Expand Down
2 changes: 0 additions & 2 deletions include/request/isolatedMargin/transferorapply.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef HUOBI_ISOLATEDMARGINTRANSFERORAPPLYREQUEST_H
#define HUOBI_ISOLATEDMARGINTRANSFERORAPPLYREQUEST_H

Expand Down
1 change: 0 additions & 1 deletion include/request/market/candlestick.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


#ifndef HUOBI_CANDLESTICKREQUEST_H
#define HUOBI_CANDLESTICKREQUEST_H

Expand Down
1 change: 0 additions & 1 deletion include/request/market/depth.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


#ifndef HUOBI_DEPTHREQUEST_H
#define HUOBI_DEPTHREQUEST_H

Expand Down
1 change: 0 additions & 1 deletion include/request/market/historytrade.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


#ifndef HUOBI_HISTORYTRADEREQUEST_H
#define HUOBI_HISTORYTRADEREQUEST_H
struct HistoryTradeRequest {
Expand Down
1 change: 0 additions & 1 deletion include/request/market/ticker.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


#ifndef HUOBI_TICKERREQUEST_H
#define HUOBI_TICKERREQUEST_H
struct TickerRequest {
Expand Down
1 change: 0 additions & 1 deletion include/request/market/trade.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


#ifndef HUOBI_TRADEREQUEST_H
#define HUOBI_TRADEREQUEST_H
struct TradeRequest{
Expand Down
1 change: 0 additions & 1 deletion include/request/reference/currencies.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


#ifndef HUOBI_REFERENCECURRENCIESREQUEST_H
#define HUOBI_REFERENCECURRENCIESREQUEST_H

Expand Down
1 change: 0 additions & 1 deletion include/request/trade/batchcancelopenorders.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


#ifndef HUOBI_BATCHCANCELOPENORDERSREQUEST_H
#define HUOBI_BATCHCANCELOPENORDERSREQUEST_H

Expand Down
1 change: 0 additions & 1 deletion include/request/trade/batchcancelorders.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


#ifndef HUOBI_BATCHCANCELORDERSREQUEST_H
#define HUOBI_BATCHCANCELORDERSREQUEST_H

Expand Down
1 change: 0 additions & 1 deletion include/request/trade/matchresultshistory.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


#ifndef HUOBI_MATCHRESULTSHISTORYREQUEST_H
#define HUOBI_MATCHRESULTSHISTORYREQUEST_H

Expand Down
Loading

0 comments on commit 3cf543d

Please sign in to comment.