-module(glupbit@types). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/glupbit/types.gleam"). -export([market/1, market_to_string/1, market_decoder/0, order_side_to_string/1, order_side_from_string/1, order_type_to_string/1, order_type_from_string/1, order_state_to_string/1, order_state_from_string/1, change_to_string/1, change_from_string/1, time_in_force_to_string/1, time_in_force_from_string/1, smp_type_to_string/1, smp_type_from_string/1]). -export_type([market/0, order_side/0, order_type/0, order_state/0, change/0, time_in_force/0, smp_type/0, rate_limit/0, api_error/0, api_response/1]). -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( " Shared domain types for the Glupbit Upbit API client.\n" "\n" " Contains market identifiers, order enums, error types, and the\n" " `ApiResponse` wrapper used by all API call functions.\n" ). -opaque market() :: {market, binary()}. -type order_side() :: bid | ask. -type order_type() :: limit | price | market_sell | best. -type order_state() :: wait | watch | done | cancel. -type change() :: rise | even | fall. -type time_in_force() :: ioc | fok | post_only. -type smp_type() :: cancel_maker | cancel_taker | reduce. -type rate_limit() :: {rate_limit, binary(), integer(), integer()}. -type api_error() :: {http_error, gleam@httpc:http_error()} | {upbit_error, integer(), binary(), binary()} | {decode_error, list(gleam@dynamic@decode:decode_error())} | {rate_limited, rate_limit()} | {auth_error, binary()}. -type api_response(YWP) :: {api_response, YWP, gleam@option:option(rate_limit())}. -file("src/glupbit/types.gleam", 22). ?DOC(" Create a Market, validating `\"QUOTE-BASE\"` format.\n"). -spec market(binary()) -> {ok, market()} | {error, nil}. market(Code) -> case gleam@string:split(Code, <<"-"/utf8>>) of [Quote, Base] when (Quote =/= <<""/utf8>>) andalso (Base =/= <<""/utf8>>) -> {ok, {market, Code}}; _ -> {error, nil} end. -file("src/glupbit/types.gleam", 30). ?DOC(" Convert a Market back to its string code.\n"). -spec market_to_string(market()) -> binary(). market_to_string(M) -> {market, Code} = M, Code. -file("src/glupbit/types.gleam", 36). ?DOC(" Decode a Market from a JSON string field.\n"). -spec market_decoder() -> gleam@dynamic@decode:decoder(market()). market_decoder() -> _pipe = {decoder, fun gleam@dynamic@decode:decode_string/1}, gleam@dynamic@decode:map(_pipe, fun(Field@0) -> {market, Field@0} end). -file("src/glupbit/types.gleam", 48). -spec order_side_to_string(order_side()) -> binary(). order_side_to_string(Side) -> case Side of bid -> <<"bid"/utf8>>; ask -> <<"ask"/utf8>> end. -file("src/glupbit/types.gleam", 55). -spec order_side_from_string(binary()) -> {ok, order_side()} | {error, nil}. order_side_from_string(S) -> case S of <<"bid"/utf8>> -> {ok, bid}; <<"ask"/utf8>> -> {ok, ask}; _ -> {error, nil} end. -file("src/glupbit/types.gleam", 73). -spec order_type_to_string(order_type()) -> binary(). order_type_to_string(Ord_type) -> case Ord_type of limit -> <<"limit"/utf8>>; price -> <<"price"/utf8>>; market_sell -> <<"market"/utf8>>; best -> <<"best"/utf8>> end. -file("src/glupbit/types.gleam", 82). -spec order_type_from_string(binary()) -> {ok, order_type()} | {error, nil}. order_type_from_string(S) -> case S of <<"limit"/utf8>> -> {ok, limit}; <<"price"/utf8>> -> {ok, price}; <<"market"/utf8>> -> {ok, market_sell}; <<"best"/utf8>> -> {ok, best}; _ -> {error, nil} end. -file("src/glupbit/types.gleam", 102). -spec order_state_to_string(order_state()) -> binary(). order_state_to_string(State) -> case State of wait -> <<"wait"/utf8>>; watch -> <<"watch"/utf8>>; done -> <<"done"/utf8>>; cancel -> <<"cancel"/utf8>> end. -file("src/glupbit/types.gleam", 111). -spec order_state_from_string(binary()) -> {ok, order_state()} | {error, nil}. order_state_from_string(S) -> case S of <<"wait"/utf8>> -> {ok, wait}; <<"watch"/utf8>> -> {ok, watch}; <<"done"/utf8>> -> {ok, done}; <<"cancel"/utf8>> -> {ok, cancel}; _ -> {error, nil} end. -file("src/glupbit/types.gleam", 130). -spec change_to_string(change()) -> binary(). change_to_string(Change) -> case Change of rise -> <<"RISE"/utf8>>; even -> <<"EVEN"/utf8>>; fall -> <<"FALL"/utf8>> end. -file("src/glupbit/types.gleam", 138). -spec change_from_string(binary()) -> {ok, change()} | {error, nil}. change_from_string(S) -> case S of <<"RISE"/utf8>> -> {ok, rise}; <<"EVEN"/utf8>> -> {ok, even}; <<"FALL"/utf8>> -> {ok, fall}; _ -> {error, nil} end. -file("src/glupbit/types.gleam", 156). -spec time_in_force_to_string(time_in_force()) -> binary(). time_in_force_to_string(Tif) -> case Tif of ioc -> <<"ioc"/utf8>>; fok -> <<"fok"/utf8>>; post_only -> <<"post_only"/utf8>> end. -file("src/glupbit/types.gleam", 164). -spec time_in_force_from_string(binary()) -> {ok, time_in_force()} | {error, nil}. time_in_force_from_string(S) -> case S of <<"ioc"/utf8>> -> {ok, ioc}; <<"fok"/utf8>> -> {ok, fok}; <<"post_only"/utf8>> -> {ok, post_only}; _ -> {error, nil} end. -file("src/glupbit/types.gleam", 182). -spec smp_type_to_string(smp_type()) -> binary(). smp_type_to_string(Smp) -> case Smp of cancel_maker -> <<"cancel_maker"/utf8>>; cancel_taker -> <<"cancel_taker"/utf8>>; reduce -> <<"reduce"/utf8>> end. -file("src/glupbit/types.gleam", 190). -spec smp_type_from_string(binary()) -> {ok, smp_type()} | {error, nil}. smp_type_from_string(S) -> case S of <<"cancel_maker"/utf8>> -> {ok, cancel_maker}; <<"cancel_taker"/utf8>> -> {ok, cancel_taker}; <<"reduce"/utf8>> -> {ok, reduce}; _ -> {error, nil} end.