Current section
Files
Jump to
Current section
Files
src/glupbit@quotation@trade.erl
-module(glupbit@quotation@trade).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glupbit/quotation/trade.gleam").
-export([trade_decoder/0, get_recent_trades/6]).
-export_type([trade/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(" Recent trade history — `GET /trades/ticks`.\n").
-type trade() :: {trade,
binary(),
binary(),
binary(),
integer(),
float(),
float(),
float(),
float(),
binary(),
integer()}.
-file("src/glupbit/quotation/trade.gleam", 53).
?DOC(" Decoder for a Trade JSON object.\n").
-spec trade_decoder() -> gleam@dynamic@decode:decoder(trade()).
trade_decoder() ->
gleam@dynamic@decode:field(
<<"market"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Market) ->
gleam@dynamic@decode:field(
<<"trade_date_utc"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Trade_date_utc) ->
gleam@dynamic@decode:field(
<<"trade_time_utc"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Trade_time_utc) ->
gleam@dynamic@decode:field(
<<"timestamp"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(Timestamp) ->
gleam@dynamic@decode:field(
<<"trade_price"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_float/1},
fun(Trade_price) ->
gleam@dynamic@decode:field(
<<"trade_volume"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_float/1},
fun(Trade_volume) ->
gleam@dynamic@decode:field(
<<"prev_closing_price"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_float/1},
fun(Prev_closing_price) ->
gleam@dynamic@decode:field(
<<"change_price"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_float/1},
fun(
Change_price
) ->
gleam@dynamic@decode:field(
<<"ask_bid"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(
Ask_bid
) ->
gleam@dynamic@decode:field(
<<"sequential_id"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_int/1},
fun(
Sequential_id
) ->
gleam@dynamic@decode:success(
{trade,
Market,
Trade_date_utc,
Trade_time_utc,
Timestamp,
Trade_price,
Trade_volume,
Prev_closing_price,
Change_price,
Ask_bid,
Sequential_id}
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
).
-file("src/glupbit/quotation/trade.gleam", 27).
?DOC(" Get recent trades for a market.\n").
-spec get_recent_trades(
glupbit@client:public_client(),
glupbit@types:market(),
gleam@option:option(integer()),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(integer())
) -> {ok, glupbit@types:api_response(list(trade()))} |
{error, glupbit@types:api_error()}.
get_recent_trades(C, Market, Count, To, Cursor, Days_ago) ->
Query = begin
_pipe@4 = [{some,
{<<"market"/utf8>>, glupbit@types:market_to_string(Market)}},
begin
_pipe = Count,
gleam@option:map(
_pipe,
fun(N) ->
{<<"count"/utf8>>, erlang:integer_to_binary(N)}
end
)
end,
begin
_pipe@1 = To,
gleam@option:map(_pipe@1, fun(T) -> {<<"to"/utf8>>, T} end)
end,
begin
_pipe@2 = Cursor,
gleam@option:map(
_pipe@2,
fun(Cur) -> {<<"cursor"/utf8>>, Cur} end
)
end,
begin
_pipe@3 = Days_ago,
gleam@option:map(
_pipe@3,
fun(D) ->
{<<"daysAgo"/utf8>>, erlang:integer_to_binary(D)}
end
)
end],
gleam@option:values(_pipe@4)
end,
glupbit@client:public_get(
C,
<<"/trades/ticks"/utf8>>,
Query,
gleam@dynamic@decode:list(trade_decoder())
).