Current section
Files
Jump to
Current section
Files
src/glupbit@exchange@withdraw.erl
-module(glupbit@exchange@withdraw).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glupbit/exchange/withdraw.gleam").
-export([withdraw_response_decoder/0, withdraw_coin/2, withdraw_krw/2]).
-export_type([coin_withdraw_request/0, krw_withdraw_request/0, withdraw_response/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" Withdrawal — `POST /withdraws/coin`, `POST /withdraws/krw`.\n").
-type coin_withdraw_request() :: {coin_withdraw_request,
binary(),
binary(),
binary(),
binary(),
gleam@option:option(binary()),
gleam@option:option(binary())}.
-type krw_withdraw_request() :: {krw_withdraw_request,
binary(),
gleam@option:option(binary())}.
-type withdraw_response() :: {withdraw_response,
binary(),
binary(),
gleam@option:option(binary()),
gleam@option:option(binary()),
binary(),
binary(),
binary(),
binary(),
binary()}.
-file("src/glupbit/exchange/withdraw.gleam", 92).
?DOC(" Decoder for WithdrawResponse.\n").
-spec withdraw_response_decoder() -> gleam@dynamic@decode:decoder(withdraw_response()).
withdraw_response_decoder() ->
gleam@dynamic@decode:field(
<<"uuid"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Uuid) ->
gleam@dynamic@decode:field(
<<"currency"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Currency) ->
gleam@dynamic@decode:optional_field(
<<"net_type"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Net_type) ->
gleam@dynamic@decode:optional_field(
<<"txid"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(Txid) ->
gleam@dynamic@decode:field(
<<"state"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(State) ->
gleam@dynamic@decode:field(
<<"created_at"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(Created_at) ->
gleam@dynamic@decode:field(
<<"amount"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(Amount) ->
gleam@dynamic@decode:field(
<<"fee"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(Fee) ->
gleam@dynamic@decode:field(
<<"transaction_type"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(
Transaction_type
) ->
gleam@dynamic@decode:success(
{withdraw_response,
Uuid,
Currency,
Net_type,
Txid,
State,
Created_at,
Amount,
Fee,
Transaction_type}
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
).
-file("src/glupbit/exchange/withdraw.gleam", 75).
-spec post_withdraw(
glupbit@client:auth_client(),
binary(),
list({binary(), binary()})
) -> {ok, glupbit@types:api_response(withdraw_response())} |
{error, glupbit@types:api_error()}.
post_withdraw(C, Path, Pairs) ->
Body = begin
_pipe = Pairs,
_pipe@1 = gleam@list:map(
_pipe,
fun(P) ->
{erlang:element(1, P), gleam@json:string(erlang:element(2, P))}
end
),
gleam@json:object(_pipe@1)
end,
glupbit@client:auth_post(C, Path, Body, Pairs, withdraw_response_decoder()).
-file("src/glupbit/exchange/withdraw.gleam", 44).
?DOC(" Withdraw digital assets. `POST /withdraws/coin`\n").
-spec withdraw_coin(glupbit@client:auth_client(), coin_withdraw_request()) -> {ok,
glupbit@types:api_response(withdraw_response())} |
{error, glupbit@types:api_error()}.
withdraw_coin(C, Req) ->
Pairs = begin
_pipe@2 = [{some, {<<"coin"/utf8>>, erlang:element(2, Req)}},
{some, {<<"net_type"/utf8>>, erlang:element(3, Req)}},
{some, {<<"amount"/utf8>>, erlang:element(4, Req)}},
{some, {<<"address"/utf8>>, erlang:element(5, Req)}},
begin
_pipe = erlang:element(6, Req),
gleam@option:map(
_pipe,
fun(V) -> {<<"secondary_address"/utf8>>, V} end
)
end,
begin
_pipe@1 = erlang:element(7, Req),
gleam@option:map(
_pipe@1,
fun(V@1) -> {<<"transaction_type"/utf8>>, V@1} end
)
end],
gleam@option:values(_pipe@2)
end,
post_withdraw(C, <<"/withdraws/coin"/utf8>>, Pairs).
-file("src/glupbit/exchange/withdraw.gleam", 62).
?DOC(" Withdraw KRW. `POST /withdraws/krw`\n").
-spec withdraw_krw(glupbit@client:auth_client(), krw_withdraw_request()) -> {ok,
glupbit@types:api_response(withdraw_response())} |
{error, glupbit@types:api_error()}.
withdraw_krw(C, Req) ->
Pairs = begin
_pipe@1 = [{some, {<<"amount"/utf8>>, erlang:element(2, Req)}},
begin
_pipe = erlang:element(3, Req),
gleam@option:map(
_pipe,
fun(V) -> {<<"two_factor_type"/utf8>>, V} end
)
end],
gleam@option:values(_pipe@1)
end,
post_withdraw(C, <<"/withdraws/krw"/utf8>>, Pairs).