Bingex.Swap (Bingex v0.1.7)

Provides an interface to interact with the BingX Swap API.

This module allows users to perform various trading operations, including placing orders, retrieving account balances, managing leverage, and querying market data. It handles authentication, request signing, and response processing to ensure seamless communication with the BingX Swap API.

Key features:

  • Place and test orders
  • Manage positions and leverage settings
  • Retrieve account balances and order history
  • Fetch market data, contracts, and quotes
  • Query server time for request synchronization

All requests requiring authentication will be signed using an API key and secret key.

Summary

Functions

Requests to cancel all orders by their market symbol (ex. BTC-USDT) with account credentials.

Request to close all positions by market symbol (ex. BTC-USDT) with account credentials.

Requests to get current swap balance.

Request the opening leverage and available positions of the user in the specified symbol contract.

Request to get all user's orders (pending, active, ...) by an optional period (start_time, end_time) and an optional limit of returned amount of orders with account credentials.

Request to the positions state of perpetual contracts by with account credentials.

Request to the position history of perpetual contracts by an optional period (start_time, end_time) with account credentials.

Requests to get current server time.

Requests to place an order using order data with account credentials.

Requests to place bunch of orders using list of order data with account credentials.

Requests to place a test order using order data with account credentials.

Request to set user's leverage amount by market symbol, position side and account credentials. Position side can be either :crossed or :isolated. Currently, BingX allows leverage from 1 to 125.

Request to set user's margin mode by market symbol and account credentials. Margin mode can be either :crossed or :isolated.

Functions

cancel_all_orders(symbol, api_key, secret_key)

Requests to cancel all orders by their market symbol (ex. BTC-USDT) with account credentials.

close_all_positions(symbol, api_key, secret_key)

Request to close all positions by market symbol (ex. BTC-USDT) with account credentials.

get_balance(api_key, secret_key)

Requests to get current swap balance.

get_contracts(symbol \\ nil)

get_leverage(symbol, api_key, secret_key)

@spec get_leverage(
  symbol :: binary(),
  api_key :: binary(),
  secret_key :: binary()
) ::
  {:ok, Bingex.API.Reply.t(nil), Bingex.Types.request_metadata()}
  | {:error, Bingex.API.Error.t(), Bingex.Types.request_metadata()}
  | {:error, Bingex.HTTP.Error.t(), Bingex.Types.failed_request_metadata()}

Request the opening leverage and available positions of the user in the specified symbol contract.

get_orders_history(symbol, start_time \\ nil, end_time \\ nil, limit \\ 50, api_key, secret_key)

@spec get_orders_history(
  symbol :: binary(),
  start_time :: nil | non_neg_integer(),
  end_time :: nil | non_neg_integer(),
  limit :: non_neg_integer(),
  api_key :: binary(),
  secret_key :: binary()
) ::
  {:ok, Bingex.API.Reply.t(Bingex.Swap.GetOrdersHistoryData.t()),
   Bingex.Types.request_metadata()}
  | {:error, Bingex.API.Error.t(), Bingex.Types.request_metadata()}
  | {:error, Bingex.HTTP.Error.t(), Bingex.Types.failed_request_metadata()}

Request to get all user's orders (pending, active, ...) by an optional period (start_time, end_time) and an optional limit of returned amount of orders with account credentials.

get_positions(symbol, api_key, secret_key)

@spec get_positions(
  symbol :: binary(),
  api_key :: binary(),
  secret_key :: binary()
) ::
  {:ok, Bingex.API.Reply.t(), Bingex.Types.request_metadata()}
  | {:error, Bingex.API.Error.t(), Bingex.Types.request_metadata()}
  | {:error, Bingex.HTTP.Error.t(), Bingex.Types.failed_request_metadata()}

Request to the positions state of perpetual contracts by with account credentials.

get_positions_history(symbol, start_time, end_time, api_key, secret_key)

@spec get_positions_history(
  symbol :: binary(),
  start_time :: non_neg_integer(),
  end_time :: non_neg_integer(),
  api_key :: binary(),
  secret_key :: binary()
) ::
  {:ok, Bingex.API.Reply.t(), Bingex.Types.request_metadata()}
  | {:error, Bingex.API.Error.t(), Bingex.Types.request_metadata()}
  | {:error, Bingex.HTTP.Error.t(), Bingex.Types.failed_request_metadata()}

Request to the position history of perpetual contracts by an optional period (start_time, end_time) with account credentials.

get_quotes(symbol \\ nil)

get_server_time()

Requests to get current server time.

place_order(order, api_key, secret_key)

Requests to place an order using order data with account credentials.

place_orders(orders, api_key, secret_key)

Requests to place bunch of orders using list of order data with account credentials.

place_test_order(order, api_key, secret_key)

Requests to place a test order using order data with account credentials.

set_leverage(symbol, position_side, leverage, api_key, secret_key)

Request to set user's leverage amount by market symbol, position side and account credentials. Position side can be either :crossed or :isolated. Currently, BingX allows leverage from 1 to 125.

set_margin_mode(symbol, margin_mode, api_key, secret_key)

@spec set_margin_mode(
  symbol :: binary(),
  Bingex.Order.margin_mode(),
  api_key :: binary(),
  secret_key :: binary()
) ::
  {:ok, Bingex.API.Reply.t(), Bingex.Types.request_metadata()}
  | {:error, Bingex.API.Error.t(), Bingex.Types.request_metadata()}
  | {:error, Bingex.HTTP.Error.t(), Bingex.Types.failed_request_metadata()}

Request to set user's margin mode by market symbol and account credentials. Margin mode can be either :crossed or :isolated.