Dwarves.BinanceSpot (dwarves_binancex v0.1.23)
Link to this section Summary
Functions
Get Daily Account Snapshot.
get spot account info from binance
Get swap histories on binance by params
Pings binance API. Returns {:ok, %{}}
if successful, {:error, reason}
otherwise
Get swap quote
Universal Transfer (For Master Account).
Link to this section Functions
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')"
}
}
}
get_account_info(api_key, secret_key, is_testnet \\ false)
get spot account info from binance
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/#account-information-user_data to understand all the parameters
Examples
get_account_info("api_key", "api_secret", true)
Result:
{:ok,
%Binance.SpotAccount{
maker_commission: 15,
taker_commission: 15,
buyer_commission: 0,
seller_commission: 0,
can_trade: true,
can_withdraw: true,
can_deposit: true,
brokered: false,
update_time: 123456789,
account_type: "SPOT",
"balances": [
%Binance.SpotBalance{
"asset": "BTC",
"free": "4723846.89208129",
"locked": "0.00000000"
},
%Binance.SpotBalance{
"asset": "LTC",
"free": "4763368.68006011",
"locked": "0.00000000"
}
],
"permissions": [
"SPOT"
]
}
}
or
{:error, {:binance_error, %{code: -2019, msg: "Margin is insufficient."}}}
get_endpoint(is_testnet)
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: ""}}}
parse_account_info(arg)
ping(is_testnet \\ false)
Pings binance API. Returns {:ok, %{}}
if successful, {:error, reason}
otherwise
quote(params, api_key, api_secret, is_testnet \\ false)
Get swap quote
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/#request-quote-user_data to understand all the parameters
Examples
quote(%{"quote_asset" => "BUSD", "base_asset" => "USDT", "quote_qty" => 300000}, "api_key", "api_secret")
Result:
{:ok,
%Binance.SwapQuote{
quote_asset: "USDT",
base_asset: "BUSD",
quote_qty: 300000,
base_qty: 299975,
price: 1.00008334,
slippage: 0.00007245,
fee: 120
}
or
{:error, {:binance_error, %{
code: -1002,
msg: "You are not authorized to execute this request."
}
}
}
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."
}
}
}
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"
}
}
}