Emxc.Global.Spot.V3 (emxc v0.0.3)
Link to this section Summary
Market Data
Current average price.
Compressed/Aggregate trades.
Exchange information.
Kline/candlestick bars.
Order book.
Test connectivity to the Rest API.
Recent trades.
24hr ticker price change statistics.
Symbol order book ticker.
Symbol price ticker.
Check server time.
Link to this section Types
authorized_option()
@type authorized_option() :: {:headers, headers()} | {:api_key, String.t()} | {:adapter, Tesla.Client.adapter()} | {:base_url, String.t()}
average_price_option()
@type average_price_option() :: {:symbol, String.t()}
client()
@type client() :: Tesla.Client.t()
compressed_trades_option()
exchange_info_option()
headers()
@type headers() :: Tesla.Env.headers()
kline_option()
order_book_option()
public_option()
@type public_option() :: {:headers, headers()} | {:adapter, Tesla.Client.adapter()} | {:base_url, String.t()}
recent_trades_option()
response()
ticker_24hr_option()
@type ticker_24hr_option() :: {:symbol, String.t()}
ticker_book_option()
@type ticker_book_option() :: {:symbol, String.t()}
ticker_price_option()
@type ticker_price_option() :: {:symbol, String.t()}
Link to this section API
authorized_client(opts \\ [])
@spec authorized_client(Tesla.Env.headers()) :: client()
Create a client for the private endpoints.
options
Options
:base_url
- The base URL to be used for the client. Defaults to"https://api.mexc.com"
.:headers
- A list of headers to be sent with each request.:adapter
- The adapter to be used for the client. Defaults toTesla.Adapter.Hackney
.:api_key
- The API key to be used for the client. Defaults to"api_key"
.
example
Example
iex> Emxc.Global.Spot.V3.authorized_client()
%Tesla.Client{
fun: nil,
pre: [
{Tesla.Middleware.BaseUrl, :call,
["https://api.mexc.com"]},
{Tesla.Middleware.JSON, :call, [[]]},
{Tesla.Middleware.Headers, :call,
[
[
{"X-MEXC-APIKEY", "api_key"},
{"Content-Type", "application/json"}
]
]}
],
post: [],
adapter: {Tesla.Adapter.Hackney, :call, [[]]}
}
public_client(opts \\ [])
@spec public_client([public_option()]) :: client()
Create a client for the public endpoints.
options
Options
:base_url
- The base URL to be used for the client. Defaults to"https://api.mexc.com"
.:headers
- A list of headers to be sent with each request.:adapter
- The adapter to be used for the client. Defaults toTesla.Adapter.Hackney
.
example
Example
iex> Emxc.Global.Spot.V3.public_client()
%Tesla.Client{
fun: nil,
pre: [
{Tesla.Middleware.BaseUrl, :call,
["https://api.mexc.com"]},
{Tesla.Middleware.JSON, :call, [[]]},
{Tesla.Middleware.Headers, :call,
[[{"Content-Type", "application/json"}]]}
],
post: [],
adapter: {Tesla.Adapter.Hackney, :call, [[]]}
}
Link to this section Market Data
average_price(client, opts \\ [])
@spec average_price(client(), [average_price_option()]) :: response()
Current average price.
options
Options
:symbol
- The symbol to get the average price for.
example
Example
iex> alias Emxc.Global.Spot.V3, as: Spot
iex> {:ok, response} = Spot.public_client() |> Spot.average_price(symbol: "BTCUSDT")
iex> response.result["price"] > 0
...> && Decimal.gt?(Decimal.new(response.result["price"]), 0)
true
compressed_trades(client, opts \\ [])
@spec compressed_trades(client(), [compressed_trades_option()]) :: response()
Compressed/Aggregate trades.
options
Options
:limit
- Default 500; max 1000.:symbol
- The symbol to get trades for.:startTime
- Timestamp in ms to get aggregate trades from INCLUSIVE.:endTime
- Timestamp in ms to get aggregate trades until INCLUSIVE.
example
Example
iex> alias Emxc.Global.Spot.V3, as: Spot
iex> {:ok, response} = Spot.public_client() |> Spot.compressed_trades(symbol: "BTCUSDT", limit: 1)
iex> response.result |> length()
1
exchange_info(client, opts \\ [])
@spec exchange_info(client(), [exchange_info_option()]) :: response()
Exchange information.
options
Options
:symbol
- The symbol to get the exchange information for.:symbols
- A list of symbols to get the exchange information for.
example
Example
iex> alias Emxc.Global.Spot.V3, as: Spot
iex> {:ok, response} = Spot.public_client() |> Spot.exchange_info(symbols: "BTCUSDT,SNTUSDT")
iex> response.result["symbols"] |> Enum.map(& &1["symbol"]) |> Enum.sort()
["BTCUSDT", "SNTUSDT"]
kline(client, opts \\ [])
@spec kline(client(), [kline_option()]) :: response()
Kline/candlestick bars.
options
Options
:limit
- Default 500; max 1000.:symbol
- The symbol to get klines for.:interval
- The interval to get klines for. One of:1m
,5m
,15m
,30m
,60m
,4h
,1d
,1M
.:startTime
- The start time to get klines for. In milliseconds.:endTime
- The end time to get klines for. In milliseconds.
example
Example
iex> alias Emxc.Global.Spot.V3, as: Spot
iex> {:ok, response} = Spot.public_client() |> Spot.kline(symbol: "BTCUSDT", interval: "1m", limit: 1)
iex> response.result |> length()
1
order_book(client, opts \\ [])
@spec order_book(client(), [order_book_option()]) :: response()
Order book.
options
Options
:limit
- Default 100; max 1000.:symbol
- The symbol to get the order book for.
example
Example
iex> alias Emxc.Global.Spot.V3, as: Spot
iex> {:ok, response} = Spot.public_client() |> Spot.order_book(symbol: "BTCUSDT", limit: 1)
iex> response.result["bids"] |> length() |> then(& &1 == response.result["asks"] |> length())
true
ping(client)
Test connectivity to the Rest API.
example
Example
iex> alias Emxc.Global.Spot.V3, as: Spot
iex> {:ok, response} = Spot.public_client() |> Spot.ping()
iex> response.status
200
recent_trades(client, opts \\ [])
@spec recent_trades(client(), [recent_trades_option()]) :: response()
Recent trades.
options
Options
:limit
- Default 500; max 1000.:symbol
- The symbol to get trades for.
example
Example
iex> alias Emxc.Global.Spot.V3, as: Spot
iex> {:ok, response} = Spot.public_client() |> Spot.recent_trades(symbol: "BTCUSDT", limit: 1)
iex> response.result |> length()
1
ticker_24hr(client, opts \\ [])
@spec ticker_24hr(client(), [ticker_24hr_option()]) :: response()
24hr ticker price change statistics.
options
Options
:symbol
- The symbol to get the ticker for.- If no symbol is provided, all tickers will be returned in a list.
example
Example
iex> alias Emxc.Global.Spot.V3, as: Spot
iex> {:ok, response} = Spot.public_client() |> Spot.ticker_24hr(symbol: "BTCUSDT")
iex> response.result["symbol"]
"BTCUSDT"
ticker_book(client, opts \\ [])
@spec ticker_book(client(), [ticker_book_option()]) :: response()
Symbol order book ticker.
options
Options
:symbol
- The symbol to get the ticker for.- If no symbol is provided, all tickers will be returned in a list.
example
Example
iex> alias Emxc.Global.Spot.V3, as: Spot
iex> {:ok, response} = Spot.public_client() |> Spot.ticker_book(symbol: "BTCUSDT")
iex> response.result["symbol"] == "BTCUSDT" && response.result["bidPrice"] > 0
true
ticker_price(client, opts \\ [])
@spec ticker_price(client(), [ticker_price_option()]) :: response()
Symbol price ticker.
options
Options
:symbol
- The symbol to get the ticker for.- If no symbol is provided, all tickers will be returned in a list.
example
Example
iex> alias Emxc.Global.Spot.V3, as: Spot
iex> {:ok, response} = Spot.public_client() |> Spot.ticker_price(symbol: "BTCUSDT")
iex> response.result["symbol"] == "BTCUSDT" && response.result["price"] > 0
true
time(client)
Check server time.
example
Example
iex> alias Emxc.Global.Spot.V3, as: Spot
iex> {:ok, response} = Spot.public_client() |> Spot.time()
iex> response.result["serverTime"] <= :calendar.universal_time()
true