Skip to content

Commit

Permalink
Migrate bithumb private to glaze
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Dec 5, 2024
1 parent 2985b9b commit ce31339
Show file tree
Hide file tree
Showing 15 changed files with 803 additions and 447 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ if(NOT glaze)

FetchContent_Declare(
glaze
URL https://github.com/stephenberry/glaze/archive/refs/tags/v4.0.1.tar.gz
URL_HASH SHA256=0026aca33201ee6d3a820fb5926f36ba8c838bfd3120e2e179b0eee62b5bd231
URL https://github.com/stephenberry/glaze/archive/refs/tags/v4.0.2.tar.gz
URL_HASH SHA256=65f01a479c786a21141dc1a77cbb9d4af63beed70fbd6bf42bba4c7c3c62943c
)

list(APPEND fetchContentPackagesToMakeAvailable glaze)
Expand Down
7 changes: 3 additions & 4 deletions src/api/exchanges/include/bithumbprivateapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
#include <unordered_map>

#include "cachedresult.hpp"
#include "cct_json-container.hpp"
#include "curlhandle.hpp"
#include "exchangeprivateapi.hpp"
#include "exchangeprivateapitypes.hpp"
#include "timedef.hpp"
#include "timepoint-schema.hpp"
#include "tradeinfo.hpp"

namespace cct {
Expand Down Expand Up @@ -71,11 +70,11 @@ class BithumbPrivate : public ExchangePrivate {

struct CurrencyOrderInfo {
struct MonetaryAmountWithTs {
int64_t ts;
schema::TimePoint ts;
MonetaryAmount val;
};
struct DecimalsWithTs {
int64_t ts;
schema::TimePoint ts;
int8_t val;
};

Expand Down
3 changes: 0 additions & 3 deletions src/api/exchanges/include/bithumbpublicapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <string_view>

#include "cachedresult.hpp"
#include "cct_json-container.hpp"
#include "curlhandle.hpp"
#include "currencyexchange.hpp"
#include "exchange-asset-config.hpp"
Expand All @@ -30,8 +29,6 @@ class BithumbPublic : public ExchangePublic {
static constexpr auto kStatusUnexpectedError = -1;
static constexpr auto kStatusNotPresentError = -2;

static int64_t StatusCodeFromJsonResponse(const json::container& jsonResponse);

BithumbPublic(const CoincenterInfo& config, FiatConverter& fiatConverter, CommonAPI& commonAPI);

bool healthCheck() override;
Expand Down
1 change: 0 additions & 1 deletion src/api/exchanges/include/huobiprivateapi.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "cachedresult.hpp"
#include "cct_json-container.hpp"
#include "curlhandle.hpp"
#include "exchangeprivateapi.hpp"
#include "exchangeprivateapitypes.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/api/exchanges/include/kucoinprivateapi.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "cachedresult.hpp"
#include "cct_json-container.hpp"
#include "curlhandle.hpp"
#include "exchangeprivateapi.hpp"
#include "exchangeprivateapitypes.hpp"
Expand Down
258 changes: 258 additions & 0 deletions src/api/exchanges/src/bithumb-schema.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
#pragma once

#include <cstdint>
#include <unordered_map>
#include <variant>

#include "cct_string.hpp"
#include "cct_vector.hpp"
#include "market.hpp"
#include "timepoint-schema.hpp"

namespace cct::api {
template <class T>
using has_status_t = decltype(std::declval<T>().status);

} // namespace cct::api

namespace cct::schema::bithumb {

// PUBLIC

// https://apidocs.bithumb.com/reference/%EB%A7%88%EC%BC%93%EC%BD%94%EB%93%9C-%EC%A1%B0%ED%9A%8C
struct V1MarketAllElement {
Market market;
};

using V1MarketAll = vector<V1MarketAllElement>;

// https://apidocs.bithumb.com/v1.2.0/reference/%ED%98%84%EC%9E%AC%EA%B0%80-%EC%A0%95%EB%B3%B4-%EC%A1%B0%ED%9A%8C-all

struct V1AssetStatus {
struct CurrencyData {
int withdrawal_status;
int deposit_status;
};

std::unordered_map<CurrencyCode, CurrencyData> data;

string status;
};

// https://apidocs.bithumb.com/v1.2.0/reference/%EC%9E%85%EC%B6%9C%EA%B8%88-%EC%A7%80%EC%9B%90-%ED%98%84%ED%99%A9-copy

struct V1NetworkInfo {
struct CurrencyData {
CurrencyCode net_type;
string net_name;

auto operator<=>(const CurrencyData&) const = default;

using trivially_relocatable = is_trivially_relocatable<string>::type;
};

vector<CurrencyData> data;

string status;
};

// https://apidocs.bithumb.com/v1.2.0/reference/%ED%98%B8%EA%B0%80-%EC%A0%95%EB%B3%B4-%EC%A1%B0%ED%9A%8C-all

struct OrderbookData {
struct Order {
MonetaryAmount price;
MonetaryAmount quantity;

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

vector<Order> bids;
vector<Order> asks;

CurrencyCode order_currency;
CurrencyCode payment_currency;
};

struct SingleOrderbook {
OrderbookData data;
string status;
};

struct MultiOrderbook {
using Obj = std::variant<string, OrderbookData>;

std::unordered_map<string, Obj> data;
string status;
};

// https://apidocs.bithumb.com/v1.2.0/reference/%ED%98%84%EC%9E%AC%EA%B0%80-%EC%A0%95%EB%B3%B4-%EC%A1%B0%ED%9A%8C-all

struct Ticker {
struct Data {
string date;
MonetaryAmount units_traded_24H;
};

Data data;
string status;
};

// https://apidocs.bithumb.com/v1.2.0/reference/%EC%B5%9C%EA%B7%BC-%EC%B2%B4%EA%B2%B0-%EB%82%B4%EC%97%AD

enum class TransactionTypeEnum : int8_t { bid, ask };

struct TransactionHistory {
struct Data {
MonetaryAmount units_traded;
MonetaryAmount price;
TransactionTypeEnum type;
string transaction_date;

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

using trivially_relocatable = is_trivially_relocatable<string>::type;
};

vector<Data> data;
string status;
};

// PRIVATE

// https://apidocs.bithumb.com/v1.2.0/reference/%EB%B3%B4%EC%9C%A0%EC%9E%90%EC%82%B0-%EC%A1%B0%ED%9A%8C

struct InfoBalance {
string status;
string message;

using Data = std::unordered_map<string, MonetaryAmount>;

Data data;
};

// https://apidocs.bithumb.com/v1.2.0/reference/%EC%9E%85%EA%B8%88%EC%A7%80%EA%B0%91-%EC%A3%BC%EC%86%8C-%EC%A1%B0%ED%9A%8C

struct InfoWalletAddress {
string status;
string message;

struct Data {
string wallet_address;
};
Data data;
};

// https://apidocs.bithumb.com/v1.2.0/reference/%EA%B1%B0%EB%9E%98-%EC%A3%BC%EB%AC%B8%EB%82%B4%EC%97%AD-%EC%A1%B0%ED%9A%8C

struct InfoOrders {
string status;
string message;

struct OrderDetails {
std::variant<string, int64_t> order_date;
string order_id;
CurrencyCode payment_currency;
MonetaryAmount units;
MonetaryAmount units_remaining;
MonetaryAmount price;
TransactionTypeEnum type;

using trivially_relocatable = is_trivially_relocatable<string>::type;

auto operator<=>(const OrderDetails&) const = default;
};
vector<OrderDetails> data;
};

// https://apidocs.bithumb.com/v1.2.0/reference/%EA%B1%B0%EB%9E%98-%EC%B2%B4%EA%B2%B0%EB%82%B4%EC%97%AD-%EC%A1%B0%ED%9A%8C

struct UserTransactions {
string status;
string message;

struct UserTransaction {
CurrencyCode order_currency;
CurrencyCode payment_currency;
std::variant<string, int64_t> transfer_date;
string search;
MonetaryAmount units;
MonetaryAmount price;
MonetaryAmount fee;
MonetaryAmount order_balance;
MonetaryAmount payment_balance;
CurrencyCode fee_currency;

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

vector<UserTransaction> data;
};

// https://apidocs.bithumb.com/v1.2.0/reference/%EC%BD%94%EC%9D%B8-%EC%B6%9C%EA%B8%88%ED%95%98%EA%B8%B0-%EA%B0%9C%EC%9D%B8

struct BtcWithdrawal {
string status;
string message;
};

// https://apidocs.bithumb.com/v1.2.0/reference/%EC%A7%80%EC%A0%95%EA%B0%80-%EC%A3%BC%EB%AC%B8%ED%95%98%EA%B8%B0

struct Trade {
string status;
string message;
string order_id;

struct ExtraStringField {
string val;
TimePoint ts;
};
struct ExtraIntField {
int64_t val{};
TimePoint ts;
};

struct ExtraData {
ExtraIntField nbDecimals;
ExtraStringField minOrderPrice;
ExtraStringField maxOrderPrice;
ExtraStringField minOrderSize;
};

ExtraData extra_data; // not part of the API
};

// https://apidocs.bithumb.com/v1.2.0/reference/%EC%A3%BC%EB%AC%B8-%EC%B7%A8%EC%86%8C%ED%95%98%EA%B8%B0

struct TradeCancel {
string status;
string message;
};

// https://apidocs.bithumb.com/v1.2.0/reference/%EA%B1%B0%EB%9E%98-%EC%A3%BC%EB%AC%B8%EB%82%B4%EC%97%AD-%EC%83%81%EC%84%B8-%EC%A1%B0%ED%9A%8C

struct InfoOrderDetail {
string status;
string message;

struct Data {
struct Contract {
MonetaryAmount units;
MonetaryAmount price;
MonetaryAmount fee;
CurrencyCode fee_currency;

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

vector<Contract> contract;
};
Data data;
};

} // namespace cct::schema::bithumb

template <>
struct glz::meta<::cct::schema::bithumb::TransactionTypeEnum> {
using enum ::cct::schema::bithumb::TransactionTypeEnum;
static constexpr auto value = enumerate(bid, ask);
};
Loading

0 comments on commit ce31339

Please sign in to comment.