Skip to content

Commit

Permalink
[Huobi Private] - Migrate to glaze json
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Dec 17, 2024
1 parent 131f874 commit 1d09f82
Show file tree
Hide file tree
Showing 8 changed files with 410 additions and 217 deletions.
8 changes: 4 additions & 4 deletions src/api/common/include/binance-common-schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
namespace cct::schema::binance {

struct NetworkListElement {
bool isDefault{};
bool depositEnable{};
bool withdrawEnable{};
bool isDefault;
bool depositEnable;
bool withdrawEnable;
MonetaryAmount withdrawFee;

auto operator<=>(const NetworkListElement&) const = default;
};

struct NetworkCoinData {
string coin;
bool isLegalMoney{};
bool isLegalMoney;
SmallVector<NetworkListElement, 4> networkList;

using trivially_relocatable =
Expand Down
36 changes: 18 additions & 18 deletions src/api/exchanges/include/binance-schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct V3Ticker24hr {
struct V3Trade {
MonetaryAmount price;
MonetaryAmount qty;
int64_t time{};
int64_t time;
bool isBuyerMaker;

using trivially_relocatable = is_trivially_relocatable<string>::type;
Expand Down Expand Up @@ -172,13 +172,13 @@ struct V1CapitalDepositAddressListElement {
// https://binance-docs.github.io/apidocs/spot/en/#cancel-all-open-orders-on-a-symbol-trade
struct V3GetAllOrder {
string symbol;
int64_t time{};
OrderId orderId{};
int64_t time;
OrderId orderId;
MonetaryAmount executedQty;
MonetaryAmount price;
string side;
MonetaryAmount origQty;
int64_t updateTime{};
int64_t updateTime;

using trivially_relocatable = is_trivially_relocatable<string>::type;

Expand All @@ -189,19 +189,19 @@ using V3GetAllOrders = vector<V3GetAllOrder>;

// https://binance-docs.github.io/apidocs/spot/en/#cancel-all-open-orders-on-a-symbol-trade
struct V3CancelOrder {
OrderId orderId{};
OrderId orderId;
};

using V3CancelAllOrders = vector<V3CancelOrder>;

// https://binance-docs.github.io/apidocs/spot/en/#deposit-history-supporting-network-user_data
struct V1CapitalDeposit {
int64_t status{-1};
int64_t status = -1;
string coin;
string id;
string address;
double amount{};
int64_t insertTime{};
double amount;
int64_t insertTime;

using trivially_relocatable = is_trivially_relocatable<string>::type;
};
Expand All @@ -210,13 +210,13 @@ using V1CapitalDepositHisRec = vector<V1CapitalDeposit>;

// https://binance-docs.github.io/apidocs/spot/en/#withdraw-history-supporting-network-user_data
struct V1CapitalWithdraw {
int64_t status{-1};
int64_t status = -1;
string coin;
string id;
double amount{};
double transactionFee{};
int64_t applyTime{};
int64_t completeTime{};
double amount;
double transactionFee;
int64_t applyTime;
int64_t completeTime;

using trivially_relocatable = is_trivially_relocatable<string>::type;
};
Expand All @@ -226,15 +226,15 @@ using V1CapitalWithdrawHistory = vector<V1CapitalWithdraw>;
// https://binance-docs.github.io/apidocs/spot/en/#asset-detail-user_data
struct V1AssetDetail {
MonetaryAmount withdrawFee;
bool withdrawStatus{};
bool withdrawStatus;
};

using V1AssetDetailMap = std::unordered_map<string, V1AssetDetail>;

// https://binance-docs.github.io/apidocs/spot/en/#dust-transfer-user_data

struct V1AssetDustResult {
OrderId tranId{};
OrderId tranId;
MonetaryAmount transferedAmount;

using trivially_relocatable = is_trivially_relocatable<string>::type;
Expand All @@ -256,14 +256,14 @@ struct V3NewOrderFills {
MonetaryAmount qty;
MonetaryAmount commission;
CurrencyCode commissionAsset;
OrderId orderId{};
OrderId orderId;

auto operator<=>(const V3NewOrderFills&) const = default;
};

struct V3NewOrder {
string status;
OrderId orderId{};
OrderId orderId = -1;
SmallVector<V3NewOrderFills, 1> fills;

using trivially_relocatable = is_trivially_relocatable<string>::type;
Expand All @@ -273,7 +273,7 @@ struct V3NewOrder {

struct V3GetOrder {
string status;
int64_t time{};
int64_t time;

using trivially_relocatable = is_trivially_relocatable<string>::type;
};
Expand Down
224 changes: 224 additions & 0 deletions src/api/exchanges/include/huobi-schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,234 @@ struct MarketTrade {
Tick tick;
};

// PRIVATE

// https://huobiapi.github.io/docs/spot/v1/en/#get-all-accounts-of-the-current-user

struct V1AccountAccounts {
string status;

struct Item {
int64_t id;
string state;

using trivially_relocatable = is_trivially_relocatable<string>::type;

auto operator<=>(const Item&) const = default;
};

vector<Item> data;
};

// https://huobiapi.github.io/docs/spot/v1/en/#get-account-balance-of-a-specific-account

struct V1AccountAccountsBalance {
string status;

struct Data {
struct Item {
string type;
string currency;
MonetaryAmount balance;

using trivially_relocatable = is_trivially_relocatable<string>::type;

auto operator<=>(const Item&) const = default;
};

vector<Item> list;
};

Data data;
};

// https://huobiapi.github.io/docs/spot/v1/en/#query-deposit-address

struct V2AccountDepositAddress {
string status;

struct Item {
string address;
string addressTag;

using trivially_relocatable = is_trivially_relocatable<string>::type;

auto operator<=>(const Item&) const = default;
};

vector<Item> data;
};

// https://huobiapi.github.io/docs/spot/v1/en/#search-past-orders

// https://huobiapi.github.io/docs/spot/v1/en/#search-historical-orders-within-48-hours

struct V1Orders {
string status;

struct Item {
string symbol;
MonetaryAmount fieldAmount; // field-amount
MonetaryAmount price;
string type;
int64_t createdAt; // created-at
int64_t id;
int64_t finishedAt; // finished-at

using trivially_relocatable = is_trivially_relocatable<string>::type;

auto operator<=>(const Item&) const = default;
};

vector<Item> data;
};

// https://huobiapi.github.io/docs/spot/v1/en/#get-all-open-orders

struct V1OrderOpenOrders {
string status;

struct Item {
string symbol;
MonetaryAmount amount;
MonetaryAmount price;
MonetaryAmount filledAmount; // filled-amount
int64_t createdAt; // created-at
int64_t id;
string type;

using trivially_relocatable = is_trivially_relocatable<string>::type;

auto operator<=>(const Item&) const = default;
};

vector<Item> data;
};

// https://huobiapi.github.io/docs/spot/v1/en/#search-for-existed-withdraws-and-deposits

struct V1QueryDepositWithdraw {
string status;

struct Item {
string state;
string currency;
int64_t id;
double amount;
double fee;
int64_t updatedAt; // updated-at

using trivially_relocatable = is_trivially_relocatable<string>::type;

auto operator<=>(const Item&) const = default;
};

vector<Item> data;
};

// https://huobiapi.github.io/docs/spot/v1/en/#submit-cancel-for-multiple-orders-by-ids

struct V1OrderOrdersBatchCancel {
string status;
};

// https://huobiapi.github.io/docs/spot/v1/en/#place-a-new-order

struct V1OrderOrdersPlace {
string status;
string data;
};

// https://huobiapi.github.io/docs/spot/v1/en/#submit-cancel-for-an-order

struct V1OrderOrdersSubmitCancel {
string status;
};

// https://huobiapi.github.io/docs/spot/v1/en/#get-the-order-detail-of-an-order

struct V1OrderOrdersDetail {
string status;

struct Data {
string state;

MonetaryAmount fieldAmount; // field-amount
MonetaryAmount fieldCashAmount; // field-cash-amount
MonetaryAmount fieldFees; // field-fees

MonetaryAmount filledAmount; // filled-amount
MonetaryAmount filledCashAmount; // filled-cash-amount
MonetaryAmount filledFees; // filled-fees

using trivially_relocatable = is_trivially_relocatable<string>::type;

auto operator<=>(const Data&) const = default;
};

Data data;
};

// https://huobiapi.github.io/docs/spot/v1/en/#query-withdraw-address

struct V1QueryWithdrawAddress {
string status;

struct Item {
string address;
string addressTag;
string note;

using trivially_relocatable = is_trivially_relocatable<string>::type;

auto operator<=>(const Item&) const = default;
};

vector<Item> data;
};

// https://huobiapi.github.io/docs/spot/v1/en/#create-a-withdraw-request

struct V1DwWithdrawApiCreate {
string status;
int64_t data;
};

} // namespace cct::schema::huobi

template <>
struct glz::meta<::cct::schema::huobi::MarketHistoryTrade::Trade::TradeData::Direction> {
using enum ::cct::schema::huobi::MarketHistoryTrade::Trade::TradeData::Direction;
static constexpr auto value = enumerate(buy, sell);
};

template <>
struct glz::meta<::cct::schema::huobi::V1Orders::Item> {
using T = ::cct::schema::huobi::V1Orders::Item;
static constexpr auto value =
object("symbol", &T::symbol, "field-amount", &T::fieldAmount, "price", &T::price, "type", &T::type, "created-at",
&T::createdAt, "id", &T::id, "finished-at", &T::finishedAt);
};

template <>
struct glz::meta<::cct::schema::huobi::V1OrderOpenOrders::Item> {
using T = ::cct::schema::huobi::V1OrderOpenOrders::Item;
static constexpr auto value = object("symbol", &T::symbol, "amount", &T::amount, "price", &T::price, "filled-amount",
&T::filledAmount, "created-at", &T::createdAt, "id", &T::id, "type", &T::type);
};

template <>
struct glz::meta<::cct::schema::huobi::V1QueryDepositWithdraw::Item> {
using T = ::cct::schema::huobi::V1QueryDepositWithdraw::Item;
static constexpr auto value = object("state", &T::state, "currency", &T::currency, "id", &T::id, "amount", &T::amount,
"fee", &T::fee, "updated-at", &T::updatedAt);
};

template <>
struct glz::meta<::cct::schema::huobi::V1OrderOrdersDetail::Data> {
using T = ::cct::schema::huobi::V1OrderOrdersDetail::Data;
static constexpr auto value =
object("state", &T::state, "field-amount", &T::fieldAmount, "field-cash-amount", &T::fieldCashAmount,
"field-fees", &T::fieldFees, "filled-amount", &T::filledAmount, "filled-cash-amount", &T::filledCashAmount,
"filled-fees", &T::filledFees);
};
4 changes: 3 additions & 1 deletion src/api/exchanges/include/huobiprivateapi.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <cstdint>

#include "cachedresult.hpp"
#include "curlhandle.hpp"
#include "exchangeprivateapi.hpp"
Expand Down Expand Up @@ -57,7 +59,7 @@ class HuobiPrivate : public ExchangePrivate {
void cancelOrderProcess(OrderIdView orderId);

struct AccountIdFunc {
int operator()();
int64_t operator()();

CurlHandle& _curlHandle;
const APIKey& _apiKey;
Expand Down
2 changes: 1 addition & 1 deletion src/api/exchanges/src/bithumb-schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ struct Trade {
TimePoint ts;
};
struct ExtraIntField {
int64_t val{};
int64_t val;
TimePoint ts;
};

Expand Down
Loading

0 comments on commit 1d09f82

Please sign in to comment.