Skip to content

Commit

Permalink
更新接口出入参并添加新接口
Browse files Browse the repository at this point in the history
  • Loading branch information
“VincentCai” committed May 20, 2024
1 parent 5d6107f commit 7d7abda
Show file tree
Hide file tree
Showing 49 changed files with 1,346 additions and 29 deletions.
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Huobi C++ SDK v2
# Huobi C++ SDK For Spot v3

This is Huobi C++ SDK v2, you can import to your C++ project and use this SDK to query all market data, trading and manage your account. The SDK supports RESTful API invoking, and subscribing the market, account and order update from the WebSocket connection.
This is Huobi C++ SDK v3, you can import to your project and use this SDK to query all market data, trading and manage your account. The SDK supports RESTful API invoking, and subscribing the market, account and order update from the WebSocket connection.

If you already use SDK v1, it is strongly suggested migrate to v2 as we refactor the implementation to make it simpler and easy to maintain. We will stop the maintenance of v1 in the near future. Please refer to the instruction on how to migrate v1 to v2 in section [Migrate from v1](#Migrate-from-v1)
If you already use SDK v1 or v2, it is strongly suggested migrate to v3 as we refactor the implementation to make it simpler and easy to maintain. The SDK v3 is completely consistent with the API documentation of the new HTX open platform. Compared to SDK versions v1 and v2, due to changes in parameters of many interfaces, in order to match the latest interface parameter situation, v3 version has made adjustments to parameters of more than 80 interfaces to ensure that requests can be correctly initiated and accurate response data can be obtained. Meanwhile, the v3 version has added over 130 new interfaces available for use, greatly expanding the number of available interfaces. We will stop the maintenance of v2 in the near future. Please refer to the instruction on how to migrate v1 or v2 to v3 in section [Migrate from v1 and v2](#Migrate-from-v1-and-v2).

## Table of Contents

Expand All @@ -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 and v2](#Migrate-from-v1-and-v2)
- [Request example](#Request-example)
- [Reference data](#Reference-data)
- [Market data](#Market-data)
Expand Down Expand Up @@ -150,7 +150,7 @@ $ make

### Client

In this SDK, the client is the struct to access the Huobi API. In order to isolate the private data with public data, and isolated different kind of data, the client category is designated to match the API category.
In this SDK, the client is the struct to access the Huobi API. In order to isolate the private data with public data, and isolated different kind of data, the client category is designated to match the API category.

All the client is listed in below table. Each client is very small and simple, it is only responsible to operate its related data, you can pick up multiple clients to create your own application based on your business.

Expand All @@ -161,11 +161,14 @@ All the client is listed in below table. Each client is very small and simple, i
| Account | AccountClient | Private | Rest |
| Wallet | WalletClient | Private | Rest |
| Trade | TradeClient | Private | Rest |
| SubUser | SubUserClient | Private | Rest |
| Algo | AlgoClient | Private | Rest |
| IsolatedMargin | IsolatedMarginClient | Private | Rest |
| CrossMargin | CrossMarginClient | Private | Rest |
| WebSocketMarket | WebSocketMarketClient | Public | WebSocket |
| WebSocketAsset | WebSocketAssetClient | Private | WebSocket v2 |
| WebSocketOrders | WebSocketOrdersClient | Private | WebSocket v2 |
| WebSocketTrade | WebSocketTradeClient | Private | WebSocket v2 |

#### Public and Private

Expand Down Expand Up @@ -204,19 +207,21 @@ There are two protocols of API, Rest and WebSocket
- Request method: The method name starts with "req-", it will receive the once-off data after sending the request.
- Subscription: The method name starts with "sub-", it will receive update after sending the subscription.
### Migrate from v1
### Migrate from v1 and v2
#### Why v2
#### Why v3
The major difference between v1 and v2 is that the client category.
In SDK v1, the client is categorized as two protocol, request client and subscription client. For example, for Rest API, you can operate everything in request client. It is simple to choose which client you use, however, when you have a client instance, you will have dozens of method, and it is not easy to choose the proper method.
The thing is different in SDK v2, the client class is categorized as seven data categories, so that the responsibility for each client is clear. For example, if you only need to access market data, you can use MarketClient without applying API Key, and all the market data can be retrieved from MarketClient. If you want to operate your order, then you know you should use TradeClient and all the order related methods are there. Since the category is exactly same as the API document, so it is easy to find the relationship between API and SDK. In SDK v2, each client is smaller and simpler, which means it is easier to maintain and less bugs.
Compared to SDK versions v1 and v2, due to changes and updates in the out and in parameters of many interfaces, in order to match the latest interface in and out parameter situation, v3 version has made adjustments and updates to the out and in parameters of more than 80 interfaces to ensure that requests can be correctly initiated and accurate response data can be obtained. Meanwhile, the v3 version has added over 130 new interfaces available for use, greatly expanding the number of available interfaces.
#### How to migrate
You don't need to change your business logic, what you need is to find the v1 request client and subscription client, and replace with the proper v2 client. The additional cost is that you need to have additional initialization for each v2 client.
You don't need to change your business logic, what you need is to find the v1 or v2 request client and subscription client, and replace with the proper v3 client. The additional cost is that you need to have additional initialization for each v3 client.
## Request example
Expand Down Expand Up @@ -416,7 +421,7 @@ std::string amount = "100.0";
crossMarginClient.repay(marginId, amount.c_str());
```

####Loan history
#### Loan history

```c++
CrossMarginClient crossMarginClient{APIKEY, SECRETKEY};
Expand All @@ -437,7 +442,7 @@ client.subTrade("htusdt", [](Trade trade) {
});
```

###Subscribe candlestick update
### Subscribe candlestick update

```c++
websocketMarketClient client;
Expand Down
6 changes: 5 additions & 1 deletion include/client/accountClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ struct AccountClient {

AccountTransferResponse accountTransfer(AccountTransferRequest &request);

long pointTransfer(PointTransferRequest &request);
AccountTransferResponse pointTransfer(PointTransferRequest &request);

PointAccount getPointAccount(long subUid);

AssetValuation getAssetValuation(AssetValuationRequest &request);

AccountValuation getAccountValuation(AccountValuationRequest &request);

long accountTransferV2(AccountTransferV2Request &request);

private:
Signature signature;

Expand Down
2 changes: 2 additions & 0 deletions include/client/isolatedMarginClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct IsolatedMarginClient {

std::vector<IsolatedMarginBalance> getBalance(IsolatedMarginBalanceRequest &request);

std::vector<MarginLimitResponse> getMarginLimit(string currency);

private:
Signature signature;

Expand Down
12 changes: 12 additions & 0 deletions include/client/referenceClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ struct ReferenceClient {

long getTimestamp();

std::vector<SymbolV2> getSymbolsV2(long ts);

std::vector<CurrenciesV2> getCurrenciesV2(long ts);

std::vector<CurrenciesV1> getCurrenciesV1(long ts);

std::vector<SymbolsV1> getSymbolsV1(long ts);

std::vector<MarketSymbols> getMarketSymbols(string symbols, long ts);

std::vector<Chains> getChains(string show_desc, string symbols, long ts)

};


Expand Down
4 changes: 3 additions & 1 deletion include/client/subUserClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct SubUserClient {

std::vector<Balance> getSubuserAggregateBalance();

void manageSubUser(ManageSubUserRequest &request);
ManageSubUserResponse manageSubUser(ManageSubUserRequest &request);

ApiKeyGenerationResponse apiKeyGeneration(ApiKeyGenerationRequest &request);

Expand All @@ -42,6 +42,8 @@ struct SubUserClient {

long getUid();

std::vector<SubUserDeductModeResponse> subUserDeductMode(SubUserDeductModeRequest &request);

private:
Signature signature;
};
Expand Down
8 changes: 6 additions & 2 deletions include/client/tradeClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ struct TradeClient {

long placeOrder(PlaceOrderRequest &request);

std::vector<long> batchOrders(std::vector<PlaceOrderRequest> &request);
std::vector<PlaceOrderResponse> batchOrders(std::vector<PlaceOrderRequest> &request);

void submitCancelOrder(long orderId);
void submitCancelOrder(long orderId, string symbol);

void submitCancelClientOrder(const char *clientOrderId);

Expand All @@ -39,6 +39,10 @@ struct TradeClient {

std::vector<TransactFeeRate> getTransactFeeRate(std::string symbols);

long autoPlace(AutoPlaceRequest &request);

CancelAllAfterResponse cancelAllAfter(int timeout);

private:
Signature signature;
};
Expand Down
2 changes: 2 additions & 0 deletions include/client/walletClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct WalletClient {

std::vector<GetWithdrawAddressResponse> getWithdrawAddress(GetWithdrawAddressRequest& request);

GetWithdrawClientOrderIdResponse getWithdrawClientOrderId(string clientOrderId);

private:
Signature signature;
};
Expand Down
17 changes: 17 additions & 0 deletions include/include.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include <response/accounts/pointAccount.h>
#include <request/accounts/assetValuationRequest.h>
#include <response/accounts/assetValuation.h>
#include <request/accounts/accountValuationRequest.h>
#include <response/accounts/accountValuation.h>
#include <request/accounts/accountTransferV2Requese.h>

#include <response/wallet/depositaddress.h>
#include <response/wallet/withdrawquota.h>
Expand All @@ -45,6 +48,7 @@
#include <request/wallet/querydepositwithdraw.h>
#include <request/wallet/getWithdrawAddressRequest.h>
#include <response/wallet/getWithdrawAddressResponse.h>
#include <response/wallet/getWithdrawClientOrderIdResponse.h>


#include <request/trade/placeorder.h>
Expand All @@ -60,10 +64,19 @@
#include <request/trade/ordershistory.h>
#include <request/trade/matchresultshistory.h>
#include <response/trade/transactfeerate.h>
#include <response/trade/placeOrderResponse.h>
#include <request/trade/autoPlaceRequest.h>
#include <response/trade/cancelAllAfterResponse.h>

#include <response/reference/symbol.h>
#include <response/reference/currencies.h>
#include <request/reference/currencies.h>
#include <response/reference/symbolV2.h>
#include <response/reference/currenciesV2.h>
#include <response/reference/currenciesV1.h>
#include <response/reference/symbolsV1.h>
#include <response/reference/marketSymbols.h>
#include <response/reference/chains.h>


#include <request/isolatedMargin/transferorapply.h>
Expand All @@ -72,6 +85,7 @@
#include <request/isolatedMargin/loanorders.h>
#include <response/isolatedmargin/loanorder.h>
#include <response/isolatedmargin/balance.h>
#include <response/isolatedmargin/marginLimitResponse.h>


#include <request/crossMargin/transferorapply.h>
Expand Down Expand Up @@ -108,6 +122,9 @@
#include <response/subUser/subUserAccount.h>
#include <request/subUser/querysubuserdeposit.h>
#include <response/subUser/subuserdeposit.h>
#include <response/subUser/manageSubUserResponse.h>
#include <request/subUser/subUserDeductModeRequest.h>
#include <response/subUser/subUserDeductModeResponse.h>

#include <request/algo/createAlgoOrderRequest.h>
#include <request/algo/openingAlgoOrdersRequest.h>
Expand Down
15 changes: 15 additions & 0 deletions include/request/accounts/accountTransferV2Requese.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


#ifndef HUOBI_ACCOUNTTRANSFERV2REQUESE_H
#define HUOBI_ACCOUNTTRANSFERV2REQUESE_H
#include <string>

struct AccountTransferV2Request {
std::string from;
std::string to;
std::string currency;
double amount;
std::string marginAccount;
};

#endif //HUOBI_ACCOUNTTRANSFERV2REQUESE_H
12 changes: 12 additions & 0 deletions include/request/accounts/accountValuationRequest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


#ifndef HUOBI_ACCOUNTVALUATIONREQUEST_H
#define HUOBI_ACCOUNTVALUATIONREQUEST_H

#include <string>
struct AccountValuationRequest{
std::string accountType;
std::string valuationCurrency;

};
#endif //HUOBI_ACCOUNTVALUATIONREQUEST_H
1 change: 1 addition & 0 deletions include/request/accounts/historyrequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ struct AccountHistoryRequest {
long endTime = 0;
std::string sort;
int size = 0;
long fromId = 0;
};
#endif //HUOBI_ACCOUNTHISTORYREQUEST_H
10 changes: 10 additions & 0 deletions include/request/subUser/subUserDeductModeRequest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


#ifndef HUOBI_SUBUSERDEDUCTMODEREQUEST_H
#define HUOBI_SUBUSERDEDUCTMODEREQUEST_H
#include <string>
struct SubUserDeductModeRequest{
long subUids;
std::string deductMode;
};
#endif //HUOBI_SUBUSERDEDUCTMODEREQUEST_H
1 change: 1 addition & 0 deletions include/request/subUser/subusertransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ struct SubuserTransferRequest {
std::string currency;
std::string amount;
std::string type;
std::string clientOrderId;
};
#endif //HUOBI_SUBUSERTRANSFERREQUEST_H
20 changes: 20 additions & 0 deletions include/request/trade/autoPlaceRequest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#ifndef HUOBI_AUTOPLACEREQUEST_H
#define HUOBI_AUTOPLACEREQUEST_H
#include <string>

struct AutoPlaceRequest {
std::string symbol;
std::string accountId;
std::string amount;
std::string marketAmount;
std::string borrowAmount;
std::string type;
std::string tradePurpose;
std::string price;
std::string stopPrice;
std::string opreator_;
std::string source;
};

#endif //HUOBI_AUTOPLACEREQUEST_H
2 changes: 2 additions & 0 deletions include/request/trade/batchcancelopenorders.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ struct BatchCancelOpenOrdersRequest {
long accountId;
std::string symbol;
std::string side;
std::string types;
int size = 0;

};
#endif //HUOBI_BATCHCANCELOPENORDERS_H
1 change: 1 addition & 0 deletions include/request/trade/openorders.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ struct OpenOrdersRequest {
std::string side;
long from = 0;
std::string direct;
std::string types;
};
#endif //HUOBI_OPENORDERSREQUEST_H
1 change: 1 addition & 0 deletions include/request/trade/placeorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ struct PlaceOrderRequest {
std::string stopPrice;
std::string source;
std::string operator_;
long selfMatchPrevent;
};
#endif //HUOBI_PLACEORDERREQUEST_H
1 change: 1 addition & 0 deletions include/request/wallet/withdraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ struct WithdrawCreateRequest {
std::string fee;
std::string addressTag;
std::string chain;
std::string clientOrderId;
};
#endif //HUOBI_WITHDRAWCREATEREQUEST_H
25 changes: 25 additions & 0 deletions include/response/accounts/accountValuation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


#ifndef HUOBI_ACCOUNTVALUATION_H
#define HUOBI_ACCOUNTVALUATION_H

#include <string>
#include <vector>
struct AccountValuation{
std::string totalBalance;
std::string todayProfit;
std::string todayProfitRate;
struct ProfitAccountBalance {
std::string distributionType;
float balance;
bool success;
std::string accountBalance;
};
std::vector<ProfitAccountBalance> profitAccountBalanceList;
struct Updated{
bool success;
long time;
};
Updated updated;
};
#endif //HUOBI_ACCOUNTVALUATION_H
3 changes: 3 additions & 0 deletions include/response/accounts/balance.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ struct Balance {
std::string currency;
std::string type;
std::string balance;
std::string debt;
std::string available;
std::string seq_num;
};
#endif //HUOBI_BALANCE_H
3 changes: 3 additions & 0 deletions include/response/isolatedmargin/loanorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ struct IsolatedMarginLoanOrder {
std::string interestAmount;
std::string interestBalance;
std::string state;
long updatedAt;
long createdAt;
long accruedAt;
std::string paidPoint;
std::string paidCoin;
std::string deductCurrency;
std::string deductAmount;
std::string deductRate;
std::string hourInterestRate;
std::string dayInterestRate;
};
#endif //HUOBI_ISOLATEDMARGINLOANORDER_H
Loading

0 comments on commit 7d7abda

Please sign in to comment.