Dwarves.BinanceSpot (dwarves_binancex v0.1.19)

Link to this section Summary

Functions

Pings binance API. Returns {:ok, %{}} if successful, {:error, reason} otherwise

Universal Transfer (For Master Account).

Link to this section Functions

Link to this function

account_snapshot(params, api_key, api_secret, is_testnet \\ false)

Get Daily Account Snapshot.

Returns {:ok, %{}} or {:error, reason}.

In the case of a error on binance, for example with invalid parameters, {:error, {:binance_error, %{code: code, msg: msg}}} will be returned.

Please read https://binance-docs.github.io/apidocs/spot/en/#daily-account-snapshot-user_data to understand all the parameters

Examples

account_snapshot(%{"type" => "FUTURES", "start_time" => 1642032000000, "end_time" => 1642032000000}, "api_key", "api_secret")

Result:

{:ok,
 %{
    code: 200,
    msg: "",
    snapshotVos: [...]
  }
or
{:error, {:binance_error, %{
      code: -3026,
      msg: "request param 'type' wrong, should be in ('SPOT', 'MARGIN', 'FUTURES')"
    }
  }
}
Link to this function

get_endpoint(is_testnet)

Link to this function

get_swap_histories(api_key, secret_key, params, is_testnet \\ false)

Get swap histories on binance by params

Returns {:ok, []} or {:error, reason}.

In the case of a error on binance, for example with invalid parameters, {:error, {:binance_error, %{code: code, msg: msg}}} will be returned.

Please read https://binance-docs.github.io/apidocs/spot/en/#get-swap-history-user_data to understand all the parameters

Examples

get_swap_histories(
  "api_key",
  "api_secret",
  %{"swapId" => 227709205},
  false
)

Result:

{:ok,
  [
    %Binance.SwapHistory{
      base_asset: "BUSD",
      base_qty: "9.9845313",
      fee: "0.015",
      price: "1.00004694",
      quote_asset: "USDT",
      quote_qty: "10",
      status: 1,
      swap_id: 227709205,
      swap_time: 1661230512920
    }
  ]}
or
{:error, {:binance_error, %{code: -1, msg: ""}}}
Link to this function

ping(is_testnet \\ false)

Pings binance API. Returns {:ok, %{}} if successful, {:error, reason} otherwise

Link to this function

swap(params, api_key, api_secret, is_testnet \\ false)

Swap token

Returns {:ok, %{}} or {:error, reason}.

In the case of a error on binance, for example with invalid parameters, {:error, {:binance_error, %{code: code, msg: msg}}} will be returned.

Please read https://binance-docs.github.io/apidocs/spot/en/#swap-trade to understand all the parameters

Examples

swap(%{"quote_asset" => "BUSD", "base_asset" => "USDT", "quote_qty" => 1000.53}, "api_key", "api_secret")

Result:

{:ok,
 %{
    swapId: 2314
  }
or
{:error, {:binance_error, %{
      code: -1002,
      msg: "You are not authorized to execute this request."
    }
  }
}
Link to this function

universal_transfer(params, api_key, api_secret)

Universal Transfer (For Master Account).

Returns {:ok, %{}} or {:error, reason}.

In the case of a error on binance, for example with invalid parameters, {:error, {:binance_error, %{code: code, msg: msg}}} will be returned.

Please read https://binance-docs.github.io/apidocs/spot/en/#universal-transfer-for-master-account to understand all the parameters

Examples

universal_transfer(%{"from_email" => "email@gmail.com", "to_email" => "email@gmail.com", "from_account_type" => "USDT_FUTURE", "to_account_type" => "SPOT", "asset" => "USDT", "amount" => 100},"api_key",  "secret_key")

Result:

{:ok,
 %{
    tranId: "tranId"
  }
or
{:error, {:binance_error, %{
      code: -1000,
      msg: "No enum constant com.binance.accountsubuser.enums.TranferWay.FUTURE_TO_FUTURE"
    }
  }
}