Packages

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

Current section

Files

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

src/glupbit@quotation@candle.erl

-module(glupbit@quotation@candle).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glupbit/quotation/candle.gleam").
-export([candle_decoder/0, get_seconds/4, get_minutes/5, get_days/4, get_weeks/4, get_months/4, get_years/4]).
-export_type([minute_unit/0, candle/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(" OHLCV candle data — seconds, minutes, days, weeks, months, years.\n").
-type minute_unit() :: min1 |
min3 |
min5 |
min10 |
min15 |
min30 |
min60 |
min240.
-type candle() :: {candle,
binary(),
binary(),
binary(),
float(),
float(),
float(),
float(),
integer(),
float(),
float(),
gleam@option:option(float()),
gleam@option:option(float()),
gleam@option:option(float()),
gleam@option:option(float()),
gleam@option:option(integer())}.
-file("src/glupbit/quotation/candle.gleam", 127).
-spec minute_unit_to_string(minute_unit()) -> binary().
minute_unit_to_string(Unit) ->
case Unit of
min1 ->
<<"1"/utf8>>;
min3 ->
<<"3"/utf8>>;
min5 ->
<<"5"/utf8>>;
min10 ->
<<"10"/utf8>>;
min15 ->
<<"15"/utf8>>;
min30 ->
<<"30"/utf8>>;
min60 ->
<<"60"/utf8>>;
min240 ->
<<"240"/utf8>>
end.
-file("src/glupbit/quotation/candle.gleam", 140).
-spec build_query(
glupbit@types:market(),
gleam@option:option(binary()),
gleam@option:option(integer())
) -> list({binary(), binary()}).
build_query(Market, To, Count) ->
_pipe@2 = [{some,
{<<"market"/utf8>>, glupbit@types:market_to_string(Market)}},
begin
_pipe = To,
gleam@option:map(_pipe, fun(T) -> {<<"to"/utf8>>, T} end)
end,
begin
_pipe@1 = Count,
gleam@option:map(
_pipe@1,
fun(C) -> {<<"count"/utf8>>, erlang:integer_to_binary(C)} end
)
end],
gleam@option:values(_pipe@2).
-file("src/glupbit/quotation/candle.gleam", 154).
?DOC(" Decoder for Candle JSON object.\n").
-spec candle_decoder() -> gleam@dynamic@decode:decoder(candle()).
candle_decoder() ->
gleam@dynamic@decode:field(
<<"market"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Market) ->
gleam@dynamic@decode:field(
<<"candle_date_time_utc"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Candle_date_time_utc) ->
gleam@dynamic@decode:field(
<<"candle_date_time_kst"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Candle_date_time_kst) ->
gleam@dynamic@decode:field(
<<"opening_price"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_float/1},
fun(Opening_price) ->
gleam@dynamic@decode:field(
<<"high_price"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_float/1},
fun(High_price) ->
gleam@dynamic@decode:field(
<<"low_price"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_float/1},
fun(Low_price) ->
gleam@dynamic@decode:field(
<<"trade_price"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_float/1},
fun(Trade_price) ->
gleam@dynamic@decode:field(
<<"timestamp"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_int/1},
fun(Timestamp) ->
gleam@dynamic@decode:field(
<<"candle_acc_trade_price"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_float/1},
fun(
Candle_acc_trade_price
) ->
gleam@dynamic@decode:field(
<<"candle_acc_trade_volume"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_float/1},
fun(
Candle_acc_trade_volume
) ->
gleam@dynamic@decode:optional_field(
<<"prev_closing_price"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_float/1}
),
fun(
Prev_closing_price
) ->
gleam@dynamic@decode:optional_field(
<<"change_price"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_float/1}
),
fun(
Change_price
) ->
gleam@dynamic@decode:optional_field(
<<"change_rate"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_float/1}
),
fun(
Change_rate
) ->
gleam@dynamic@decode:optional_field(
<<"converted_trade_price"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_float/1}
),
fun(
Converted_trade_price
) ->
gleam@dynamic@decode:optional_field(
<<"unit"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_int/1}
),
fun(
Unit
) ->
gleam@dynamic@decode:success(
{candle,
Market,
Candle_date_time_utc,
Candle_date_time_kst,
Opening_price,
High_price,
Low_price,
Trade_price,
Timestamp,
Candle_acc_trade_price,
Candle_acc_trade_volume,
Prev_closing_price,
Change_price,
Change_rate,
Converted_trade_price,
Unit}
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
).
-file("src/glupbit/quotation/candle.gleam", 112).
-spec fetch(
glupbit@client:public_client(),
binary(),
glupbit@types:market(),
gleam@option:option(binary()),
gleam@option:option(integer())
) -> {ok, glupbit@types:api_response(list(candle()))} |
{error, glupbit@types:api_error()}.
fetch(C, Path, Market, To, Count) ->
glupbit@client:public_get(
C,
Path,
build_query(Market, To, Count),
gleam@dynamic@decode:list(candle_decoder())
).
-file("src/glupbit/quotation/candle.gleam", 44).
?DOC(" `GET /candles/seconds`\n").
-spec get_seconds(
glupbit@client:public_client(),
glupbit@types:market(),
gleam@option:option(binary()),
gleam@option:option(integer())
) -> {ok, glupbit@types:api_response(list(candle()))} |
{error, glupbit@types:api_error()}.
get_seconds(C, Market, To, Count) ->
fetch(C, <<"/candles/seconds"/utf8>>, Market, To, Count).
-file("src/glupbit/quotation/candle.gleam", 54).
?DOC(" `GET /candles/minutes/{unit}`\n").
-spec get_minutes(
glupbit@client:public_client(),
minute_unit(),
glupbit@types:market(),
gleam@option:option(binary()),
gleam@option:option(integer())
) -> {ok, glupbit@types:api_response(list(candle()))} |
{error, glupbit@types:api_error()}.
get_minutes(C, Unit, Market, To, Count) ->
fetch(
C,
<<"/candles/minutes/"/utf8, (minute_unit_to_string(Unit))/binary>>,
Market,
To,
Count
).
-file("src/glupbit/quotation/candle.gleam", 71).
?DOC(" `GET /candles/days`\n").
-spec get_days(
glupbit@client:public_client(),
glupbit@types:market(),
gleam@option:option(binary()),
gleam@option:option(integer())
) -> {ok, glupbit@types:api_response(list(candle()))} |
{error, glupbit@types:api_error()}.
get_days(C, Market, To, Count) ->
fetch(C, <<"/candles/days"/utf8>>, Market, To, Count).
-file("src/glupbit/quotation/candle.gleam", 81).
?DOC(" `GET /candles/weeks`\n").
-spec get_weeks(
glupbit@client:public_client(),
glupbit@types:market(),
gleam@option:option(binary()),
gleam@option:option(integer())
) -> {ok, glupbit@types:api_response(list(candle()))} |
{error, glupbit@types:api_error()}.
get_weeks(C, Market, To, Count) ->
fetch(C, <<"/candles/weeks"/utf8>>, Market, To, Count).
-file("src/glupbit/quotation/candle.gleam", 91).
?DOC(" `GET /candles/months`\n").
-spec get_months(
glupbit@client:public_client(),
glupbit@types:market(),
gleam@option:option(binary()),
gleam@option:option(integer())
) -> {ok, glupbit@types:api_response(list(candle()))} |
{error, glupbit@types:api_error()}.
get_months(C, Market, To, Count) ->
fetch(C, <<"/candles/months"/utf8>>, Market, To, Count).
-file("src/glupbit/quotation/candle.gleam", 101).
?DOC(" `GET /candles/years`\n").
-spec get_years(
glupbit@client:public_client(),
glupbit@types:market(),
gleam@option:option(binary()),
gleam@option:option(integer())
) -> {ok, glupbit@types:api_response(list(candle()))} |
{error, glupbit@types:api_error()}.
get_years(C, Market, To, Count) ->
fetch(C, <<"/candles/years"/utf8>>, Market, To, Count).