Skip to content

Commit

Permalink
[Upbit] Addition of net_type required parameter for withdraw-apply
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Jan 4, 2024
1 parent afedf38 commit c8b734c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
19 changes: 11 additions & 8 deletions src/api/exchanges/src/upbitprivateapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ UpbitPrivate::UpbitPrivate(const CoincenterInfo& config, UpbitPublic& upbitPubli
bool UpbitPrivate::validateApiKey() {
json ret =
PrivateQuery(_curlHandle, _apiKey, HttpRequestType::kGet, "/v1/api_keys", CurlPostData(), IfError::kNoThrow);
auto errorIt = ret.find("error");
return errorIt == ret.end() && !ret.empty();
return !ret.empty() && ret.find("error") == ret.end();
}

CurrencyExchangeFlatSet UpbitPrivate::TradableCurrenciesFunc::operator()() {
Expand Down Expand Up @@ -173,17 +172,20 @@ CurrencyExchangeFlatSet UpbitPrivate::TradableCurrenciesFunc::operator()() {
}

BalancePortfolio UpbitPrivate::queryAccountBalance(const BalanceOptions& balanceOptions) {
BalancePortfolio ret;
bool withBalanceInUse =
const bool withBalanceInUse =
balanceOptions.amountIncludePolicy() == BalanceOptions::AmountIncludePolicy::kWithBalanceInUse;
CurrencyCode equiCurrency = balanceOptions.equiCurrency();
const CurrencyCode equiCurrency = balanceOptions.equiCurrency();

BalancePortfolio ret;
for (const json& accountDetail : PrivateQuery(_curlHandle, _apiKey, HttpRequestType::kGet, "/v1/accounts")) {
CurrencyCode currencyCode(accountDetail["currency"].get<std::string_view>());
MonetaryAmount availableAmount(accountDetail["balance"].get<std::string_view>(), currencyCode);
const CurrencyCode currencyCode(accountDetail["currency"].get<std::string_view>());
const MonetaryAmount availableAmount(accountDetail["balance"].get<std::string_view>(), currencyCode);

this->addBalance(ret, availableAmount, equiCurrency);

if (withBalanceInUse) {
MonetaryAmount amountInUse(accountDetail["locked"].get<std::string_view>(), currencyCode);
const MonetaryAmount amountInUse(accountDetail["locked"].get<std::string_view>(), currencyCode);

this->addBalance(ret, amountInUse, equiCurrency);
}
}
Expand Down Expand Up @@ -597,6 +599,7 @@ InitiatedWithdrawInfo UpbitPrivate::launchWithdraw(MonetaryAmount grossAmount, W
MonetaryAmount withdrawFee = _exchangePublic.queryWithdrawalFeeOrZero(currencyCode);
MonetaryAmount netEmittedAmount = grossAmount - withdrawFee;
CurlPostData withdrawPostData{{"currency", currencyCode.str()},
{"net_type", currencyCode.str()},
{"amount", netEmittedAmount.amountStr()},
{"address", destinationWallet.address()}};
if (destinationWallet.hasTag()) {
Expand Down
5 changes: 4 additions & 1 deletion src/api/exchanges/test/commonapi_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ class TestAPI {
// if (exchangePrivateOpt) {
// json d;
// for (const auto &c : currencies) {
// d[string(c.standardStr())] = *exchangePrivateOpt->queryWithdrawalFee(c.standardCode()).amountStr();
// const auto optFeeAmount = exchangePrivateOpt->queryWithdrawalFee(c.standardCode());
// if (optFeeAmount) {
// d[c.standardStr()] = optFeeAmount->amountStr();
// }
// }
// std::cout << d.dump(2) << '\n';
// }
Expand Down

0 comments on commit c8b734c

Please sign in to comment.