Packages

Type-safe Gleam client library for the Upbit cryptocurrency exchange API

Current section

Files

Jump to
glupbit src glupbit@quotation@ticker.erl
Raw

src/glupbit@quotation@ticker.erl

-module(glupbit@quotation@ticker).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glupbit/quotation/ticker.gleam").
-export([ticker_decoder/0, get_tickers/2, get_all_tickers/2]).
-export_type([ticker/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(" Current price snapshots — `GET /ticker` and `GET /ticker/all`.\n").
-type ticker() :: {ticker,
binary(),
binary(),
binary(),
binary(),
binary(),
integer(),
float(),
float(),
float(),
float(),
float(),
binary(),
float(),
float(),
float(),
float(),
float(),
float(),
float(),
float(),
float(),
float(),
binary(),
float(),
binary(),
integer()}.
-file("src/glupbit/quotation/ticker.gleam", 12).
?DOC(" Decode a JSON number as Float, accepting both float and int values.\n").
-spec number() -> gleam@dynamic@decode:decoder(float()).
number() ->
gleam@dynamic@decode:one_of(
{decoder, fun gleam@dynamic@decode:decode_float/1},
[begin
_pipe = {decoder, fun gleam@dynamic@decode:decode_int/1},
gleam@dynamic@decode:map(_pipe, fun erlang:float/1)
end]
).
-file("src/glupbit/quotation/ticker.gleam", 76).
?DOC(" Decoder for a Ticker JSON object.\n").
-spec ticker_decoder() -> gleam@dynamic@decode:decoder(ticker()).
ticker_decoder() ->
gleam@dynamic@decode:field(
<<"market"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Market) ->
gleam@dynamic@decode:field(
<<"trade_date"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Trade_date) ->
gleam@dynamic@decode:field(
<<"trade_time"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Trade_time) ->
gleam@dynamic@decode:field(
<<"trade_date_kst"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(Trade_date_kst) ->
gleam@dynamic@decode:field(
<<"trade_time_kst"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(Trade_time_kst) ->
gleam@dynamic@decode:field(
<<"trade_timestamp"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_int/1},
fun(Trade_timestamp) ->
gleam@dynamic@decode:field(
<<"opening_price"/utf8>>,
number(),
fun(Opening_price) ->
gleam@dynamic@decode:field(
<<"high_price"/utf8>>,
number(),
fun(High_price) ->
gleam@dynamic@decode:field(
<<"low_price"/utf8>>,
number(),
fun(
Low_price
) ->
gleam@dynamic@decode:field(
<<"trade_price"/utf8>>,
number(
),
fun(
Trade_price
) ->
gleam@dynamic@decode:field(
<<"prev_closing_price"/utf8>>,
number(
),
fun(
Prev_closing_price
) ->
gleam@dynamic@decode:field(
<<"change"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(
Change
) ->
gleam@dynamic@decode:field(
<<"change_price"/utf8>>,
number(
),
fun(
Change_price
) ->
gleam@dynamic@decode:field(
<<"change_rate"/utf8>>,
number(
),
fun(
Change_rate
) ->
gleam@dynamic@decode:field(
<<"signed_change_price"/utf8>>,
number(
),
fun(
Signed_change_price
) ->
gleam@dynamic@decode:field(
<<"signed_change_rate"/utf8>>,
number(
),
fun(
Signed_change_rate
) ->
gleam@dynamic@decode:field(
<<"trade_volume"/utf8>>,
number(
),
fun(
Trade_volume
) ->
gleam@dynamic@decode:field(
<<"acc_trade_price"/utf8>>,
number(
),
fun(
Acc_trade_price
) ->
gleam@dynamic@decode:field(
<<"acc_trade_price_24h"/utf8>>,
number(
),
fun(
Acc_trade_price_24h
) ->
gleam@dynamic@decode:field(
<<"acc_trade_volume"/utf8>>,
number(
),
fun(
Acc_trade_volume
) ->
gleam@dynamic@decode:field(
<<"acc_trade_volume_24h"/utf8>>,
number(
),
fun(
Acc_trade_volume_24h
) ->
gleam@dynamic@decode:field(
<<"highest_52_week_price"/utf8>>,
number(
),
fun(
Highest_52_week_price
) ->
gleam@dynamic@decode:field(
<<"highest_52_week_date"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(
Highest_52_week_date
) ->
gleam@dynamic@decode:field(
<<"lowest_52_week_price"/utf8>>,
number(
),
fun(
Lowest_52_week_price
) ->
gleam@dynamic@decode:field(
<<"lowest_52_week_date"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(
Lowest_52_week_date
) ->
gleam@dynamic@decode:field(
<<"timestamp"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_int/1},
fun(
Timestamp
) ->
gleam@dynamic@decode:success(
{ticker,
Market,
Trade_date,
Trade_time,
Trade_date_kst,
Trade_time_kst,
Trade_timestamp,
Opening_price,
High_price,
Low_price,
Trade_price,
Prev_closing_price,
Change,
Change_price,
Change_rate,
Signed_change_price,
Signed_change_rate,
Trade_volume,
Acc_trade_price,
Acc_trade_price_24h,
Acc_trade_volume,
Acc_trade_volume_24h,
Highest_52_week_price,
Highest_52_week_date,
Lowest_52_week_price,
Lowest_52_week_date,
Timestamp}
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
).
-file("src/glupbit/quotation/ticker.gleam", 49).
?DOC(" Get tickers for specific trading pairs.\n").
-spec get_tickers(glupbit@client:public_client(), list(glupbit@types:market())) -> {ok,
glupbit@types:api_response(list(ticker()))} |
{error, glupbit@types:api_error()}.
get_tickers(C, Markets) ->
Codes = begin
_pipe = Markets,
_pipe@1 = gleam@list:map(_pipe, fun glupbit@types:market_to_string/1),
gleam@string:join(_pipe@1, <<","/utf8>>)
end,
glupbit@client:public_get(
C,
<<"/ticker"/utf8>>,
[{<<"markets"/utf8>>, Codes}],
gleam@dynamic@decode:list(ticker_decoder())
).
-file("src/glupbit/quotation/ticker.gleam", 63).
?DOC(" Get all tickers filtered by quote currency (e.g., `\"KRW\"`, `\"BTC\"`).\n").
-spec get_all_tickers(glupbit@client:public_client(), list(binary())) -> {ok,
glupbit@types:api_response(list(ticker()))} |
{error, glupbit@types:api_error()}.
get_all_tickers(C, Currencies) ->
glupbit@client:public_get(
C,
<<"/ticker/all"/utf8>>,
[{<<"quote_currencies"/utf8>>,
gleam@string:join(Currencies, <<","/utf8>>)}],
gleam@dynamic@decode:list(ticker_decoder())
).