Emxc.Global.Spot.V3 (emxc v0.0.3)

Link to this section Summary

API

Create a client for the private endpoints.

Create a client for the public endpoints.

Market Data

Current average price.

Compressed/Aggregate trades.

Exchange information.

Kline/candlestick bars.

Test connectivity to the Rest API.

24hr ticker price change statistics.

Symbol order book ticker.

Symbol price ticker.

Check server time.

Link to this section Types

Link to this type

authorized_option()

@type authorized_option() ::
  {:headers, headers()}
  | {:api_key, String.t()}
  | {:adapter, Tesla.Client.adapter()}
  | {:base_url, String.t()}
Link to this type

average_price_option()

@type average_price_option() :: {:symbol, String.t()}
@type client() :: Tesla.Client.t()
Link to this type

compressed_trades_option()

@type compressed_trades_option() ::
  {:limit, integer()}
  | {:symbol, String.t()}
  | {:startTime, integer()}
  | {:endTime, integer()}
Link to this type

exchange_info_option()

@type exchange_info_option() :: {:symbol, String.t()} | {:symbols, [String.t()]}
@type headers() :: Tesla.Env.headers()
Link to this type

kline_option()

@type kline_option() ::
  {:limit, integer()}
  | {:symbol, String.t()}
  | {:interval, String.t()}
  | {:startTime, integer()}
  | {:endTime, integer()}
Link to this type

order_book_option()

@type order_book_option() :: {:limit, integer()} | {:symbol, String.t()}
Link to this type

public_option()

@type public_option() ::
  {:headers, headers()}
  | {:adapter, Tesla.Client.adapter()}
  | {:base_url, String.t()}
Link to this type

recent_trades_option()

@type recent_trades_option() :: {:limit, integer()} | {:symbol, String.t()}
@type response() :: {:ok, map()} | {:error, any()} | no_return()
Link to this type

ticker_24hr_option()

@type ticker_24hr_option() :: {:symbol, String.t()}
Link to this type

ticker_book_option()

@type ticker_book_option() :: {:symbol, String.t()}
Link to this type

ticker_price_option()

@type ticker_price_option() :: {:symbol, String.t()}

Link to this section API

Link to this function

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 to Tesla.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, [[]]}
      }
Link to this function

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 to Tesla.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

Link to this function

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
Link to this function

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
Link to this function

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"]
Link to this function

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
Link to this function

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
@spec ping(client()) :: response()

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
Link to this function

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
Link to this function

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"
Link to this function

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
Link to this function

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
@spec time(client()) :: response()

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