Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,4 @@ ws.IsolatedSubPositions("XRP-USDT", [](const SubPositionsResponse &data) {
//LOG(INFO) << item.contract_code << ":" << item.direction << "/" << item.volume << "/" << item.margin_mode;
}
});
```
```
94 changes: 94 additions & 0 deletions huobi_futures/coin_futures/ws/WSNotifyClinet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ typedef huobi_futures::coin_futures::ws::response_notify::SubContractInfoRespons
#include "huobi_futures/coin_futures/ws/response/notify/SubTriggerOrderResponse.hpp"
typedef huobi_futures::coin_futures::ws::response_notify::SubTriggerOrderResponse SubTriggerOrderResponse;

#include "huobi_futures/coin_futures/ws/response/notify/SubAlgoOrdersResponse.hpp"
typedef huobi_futures::coin_futures::ws::response_notify::SubAlgoOrdersResponse SubAlgoOrdersResponse;

#include "huobi_futures/coin_futures/ws/response/notify/SubAccountResponse.hpp"
typedef huobi_futures::coin_futures::ws::response_notify::SubAccountResponse SubAccountResponse;

#include "huobi_futures/wsbase/WSOpData.hpp"
typedef huobi_futures::wsbase::WSOpData WSOpData;

Expand Down Expand Up @@ -573,6 +579,94 @@ namespace huobi_futures
Unsub(op_data.ToJson(), ch.str());
}

// 订阅策略订单
typedef std::function<void(const SubAlgoOrdersResponse&)> _OnSubAlgoOrdersResponse;
void SubAlgoOrders(const string &contract_code, _OnSubAlgoOrdersResponse callbackFun, const string &cid = utils::DEFAULT_ID)
{
// 构建频道:algo_orders.$contract_code
stringstream ch;
ch << "algo_orders." << contract_code;

WSOpData op_data;
op_data.op = "sub";
op_data.topic = ch.str();
op_data.cid = cid;

Sub(op_data.ToJson(), ch.str(), [&](const string &data) {
SubAlgoOrdersResponse obj;
JS::ParseContext parseContext(data);
parseContext.allow_unnasigned_required_members = false;

if (parseContext.parseTo(obj) != JS::Error::NoError)
{
std::string errorStr = parseContext.makeErrorString();
LOG(ERROR) << "Error parsing struct SubAlgoOrdersResponse error";
LOG(ERROR) << data;
return;
}
callbackFun(obj);
});
}

// 取消订阅策略订单
void UnsubAlgoOrders(const string &contract_code, const string &cid = utils::DEFAULT_ID)
{
// 构建频道:algo_orders.$contract_code
stringstream ch;
ch << "algo_orders." << contract_code;

WSOpData op_data;
op_data.op = "unsub";
op_data.topic = ch.str();
op_data.cid = cid;

Unsub(op_data.ToJson(), ch.str());
}

// 订阅账户变动数据
typedef std::function<void(const SubAccountResponse&)> _OnSubAccountResponse;
void SubAccount(_OnSubAccountResponse callbackFun, const string &cid = utils::DEFAULT_ID)
{
// 构建频道:account
stringstream ch;
ch << "account";

WSOpData op_data;
op_data.op = "sub";
op_data.topic = ch.str();
op_data.cid = cid;

Sub(op_data.ToJson(), ch.str(), [callbackFun](const string &data) {
SubAccountResponse obj;
JS::ParseContext parseContext(data);
parseContext.allow_unnasigned_required_members = false;

if (parseContext.parseTo(obj) != JS::Error::NoError)
{
std::string errorStr = parseContext.makeErrorString();
LOG(ERROR) << "Error parsing struct SubAccountResponse error";
LOG(ERROR) << data;
return;
}
callbackFun(obj);
});
}

// 取消订阅账户变动数据
void UnsubAccount(const string &cid = utils::DEFAULT_ID)
{
// 构建频道:account
stringstream ch;
ch << "account";

WSOpData op_data;
op_data.op = "unsub";
op_data.topic = ch.str();
op_data.cid = cid;

Unsub(op_data.ToJson(), ch.str());
}

// sub trigger_order end
// ----------------------------------------------------------------------------------------------------
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#pragma once

#include <string>
#include <vector>
#include <optional>
#include "huobi_futures/json_struct/json_struct.h"

namespace huobi_futures
{
namespace coin_futures
{
namespace ws
{
namespace response_notify
{
struct SubAccountResponse
{
struct CurrencyDetail
{
std::optional<std::string> currency;
std::optional<std::string> equity;
std::optional<std::string> isolated_equity;
std::optional<std::string> available;
std::optional<std::string> withdraw_available;
std::optional<std::string> profit_unreal;
std::optional<std::string> isolated_profit_unreal;
std::optional<std::string> initial_margin;
std::optional<std::string> maintenance_margin;
std::optional<std::string> maintenance_margin_rate;
std::optional<std::string> initial_margin_rate;
std::optional<std::string> voucher;
std::optional<std::string> voucher_value;
std::optional<std::string> created_time;
std::optional<std::string> updated_time;

JS_OBJ(currency, equity, isolated_equity, available, withdraw_available,
profit_unreal, isolated_profit_unreal, initial_margin, maintenance_margin,
maintenance_margin_rate, initial_margin_rate, voucher, voucher_value,
created_time, updated_time);
};

struct AccountData
{
std::optional<std::string> state;
std::optional<std::string> equity;
std::optional<std::string> initial_margin;
std::optional<std::string> maintenance_margin;
std::optional<std::string> maintenance_margin_rate;
std::optional<std::string> profit_unreal;
std::optional<std::string> available_margin;
std::optional<std::string> voucher_value;
std::optional<std::string> created_time;
std::optional<std::string> updated_time;
std::optional<std::string> version;
std::optional<std::vector<CurrencyDetail>> details;

JS_OBJ(state, equity, initial_margin, maintenance_margin, maintenance_margin_rate,
profit_unreal, available_margin, voucher_value, created_time, updated_time,
version, details);
};

std::string op;
std::string topic;
std::optional<int64_t> ts;
std::optional<std::string> event;
std::optional<std::string> uid;
std::optional<std::vector<AccountData>> data;

JS_OBJ(op, topic, ts, event, uid, data);
};
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#pragma once

#include <string>
#include <vector>
#include <optional>
#include "huobi_futures/json_struct/json_struct.h"

namespace huobi_futures
{
namespace coin_futures
{
namespace ws
{
namespace response_notify
{
struct SubAlgoOrdersResponse
{
struct Data
{
std::optional<std::string> id;
std::optional<std::string> algo_id;
std::optional<std::string> algo_client_order_id;
std::optional<std::string> contract_code;
std::optional<std::string> volume;
std::optional<std::string> type;
std::optional<std::string> state;
std::optional<std::string> position_side;
std::optional<std::string> margin_mode;
std::optional<std::string> side;
std::optional<std::string> tp_trigger_price;
std::optional<std::string> tp_order_price;
std::optional<std::string> tp_type;
std::optional<std::string> tp_trigger_price_type;
std::optional<std::string> sl_trigger_price;
std::optional<std::string> sl_order_price;
std::optional<std::string> sl_type;
std::optional<std::string> sl_trigger_price_type;
std::optional<std::string> price;
std::optional<std::string> price_match;
std::optional<std::string> trigger_price;
std::optional<std::string> trigger_price_type;
std::optional<std::string> active_price;
std::optional<std::string> order_price_type;
std::optional<std::string> callback_rate;
std::optional<bool> reduce_only;
std::optional<std::string> actual_volume;
std::optional<std::string> actual_price;
std::optional<std::string> actual_time;
std::optional<std::string> relation_order_id;
std::optional<std::string> created_time;
std::optional<std::string> updated_time;
std::optional<std::string> order_source;

JS_OBJ(id, algo_id, algo_client_order_id, contract_code, volume, type, state,
position_side, margin_mode, side, tp_trigger_price, tp_order_price, tp_type,
tp_trigger_price_type, sl_trigger_price, sl_order_price, sl_type,
sl_trigger_price_type, price, price_match, trigger_price, trigger_price_type,
active_price, order_price_type, callback_rate, reduce_only, actual_volume,
actual_price, actual_time, relation_order_id, created_time, updated_time,
order_source);
};

std::string op;
std::string topic;
std::optional<int64_t> ts;
std::optional<std::string> event;
std::optional<std::string> uid;
std::optional<std::vector<Data>> data;

JS_OBJ(op, topic, ts, event, uid, data);
};
}
}
}
}
67 changes: 66 additions & 1 deletion huobi_futures/linear_swap/restful/AccountClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ typedef huobi_futures::linear_swap::restful::response_account::SwapAccountBalanc
#include "huobi_futures/linear_swap/restful/response/account/SwapMultiAssetsMarginResponse.hpp"
typedef huobi_futures::linear_swap::restful::response_account::SwapMultiAssetsMarginResponse SwapMultiAssetsMarginResponse;

#include "huobi_futures/linear_swap/restful/response/account/SwapAccountBillsResponse.hpp"
typedef huobi_futures::linear_swap::restful::response_account::SwapAccountBillsResponse SwapAccountBillsResponse;

namespace huobi_futures
{
namespace linear_swap
Expand Down Expand Up @@ -1501,13 +1504,75 @@ namespace huobi_futures
path << "?" << option.str();
}
// url
string url = pb->Build("POST", path.str());
string url = pb->Build("GET", path.str());

// post
auto result = url_base::HttpRequest::Instance().Get<FeeDeductionCurrencyResponse>(url);
return result;
}

std::shared_ptr<SwapAccountBillsResponse> SwapGetAccountBills(
const string &contract_code,
const string &margin_mode,
const string &type,
const string &start_time,
const string &end_time,
int64_t from,
int32_t limit,
const string &direct)
{
// path
stringstream path;
path << "/v5/account/bills";

// option - GET请求,参数在URL中
stringstream option;
if (contract_code != "")
{
option << "&contract_code=" << contract_code;
}
if (margin_mode != "")
{
option << "&margin_mode=" << margin_mode;
}
if (type != "")
{
option << "&type=" << type;
}
if (start_time != "")
{
option << "&start_time=" << start_time;
}
if (end_time != "")
{
option << "&end_time=" << end_time;
}
if (from != 0)
{
option << "&from=" << from;
}
if (limit != 0)
{
option << "&limit=" << limit;
}
if (direct != "")
{
option << "&direct=" << direct;
}

if (!option.str().empty())
{
path << "?" << option.str().substr(1);
}

// url
string url = pb->Build("GET", path.str());

// get
auto result = url_base::HttpRequest::Instance().Get<SwapAccountBillsResponse>(url);
return result;
}

std::shared_ptr<QueryEarnProjectListResponse> QueryEarnProjectList(const string &currency, int pageNum, int pageSize)
{
// path
Expand Down
Loading