Dwarves.BinanceFutures (dwarves_binancex v0.1.6)
Link to this section Summary
Functions
Change initial leverage
Creates a batch orders on binance.Max 5 orders
Creates a new order on binance
Searches and normalizes the symbol as it is listed on binance.
get account info from binance
Get all symbols and current prices listed in binance
get exchange info from binance
Creates a new limit buy order
Creates a new limit sell order
Creates a new market buy order
Creates a new market sell order
Pings binance API. Returns {:ok, %{}}
if successful, {:error, reason}
otherwise
Link to this section Functions
change_leverage(params, api_secret, api_key, is_testnet \\ false)
Change initial leverage
Symbol can be a binance symbol in the form of "ETHBTC"
or %Binance.TradePair{}
.
Returns {:ok, %{}}
or {:error, reason}
Examples
change_leverage(%{
"symbol" => "BTCUSDT", "leverage" => 5},
"api_secret",
"api_key",
true)
Result: {:ok, %{"leverage" => 5, "maxNotionalValue" => "50000000", "symbol" => "BTCUSDT"}}
create_batch_orders(params, api_secret, api_key, is_testnet \\ false)
Creates a batch orders on binance.Max 5 orders
Returns {:ok, [%{order} or %{code: code, msg: msg}]}
.
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/futures/en/#place-multiple-orders-trade to understand all the parameters
Examples
create_batch_orders(%{
"batch_orders" => [
%{"symbol" => "BTCUSDT", "quantity" => 1, "side" => "BUY", "type" => "MARKET"},
%{"symbol" => "ETHUSDT", "quantity" => 1, "side" => "BUY", "type" => "MARKET"}
]
},
"api_secret",
"api_key",
true)
Result:
{:ok,
[
%{"code" => -2019, "msg" => "Margin is insufficient."},
%{
"orderId" => 809666629,
"origQty" => "1",
"origType" => "MARKET",
"positionSide" => "BOTH",
"price" => "0",
"side" => "BUY",
"status" => "NEW",
"symbol" => "ETHUSDT",
"type" => "MARKET",
...
}
]}
create_order(params, api_secret, api_key, is_testnet \\ false)
Creates a new order on 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://www.binance.com/restapipub.html#user-content-account-endpoints to understand all the parameters
Examples
create_order(
%{"symbol" => "BTCUSDT", "quantity" => 1, "side" => "BUY", "type" => "MARKET"},
"api_secret",
"api_key",
true)
Result:
{:ok,
%{
"orderId" => 809666629,
"origQty" => "1",
"origType" => "MARKET",
"positionSide" => "BOTH",
"price" => "0",
"side" => "BUY",
"status" => "NEW",
"symbol" => "BTCUSDT",
"type" => "MARKET",
...
}
}
or
{:error, {:binance_error, %{code: -2019, msg: "Margin is insufficient."}}}
find_symbol(tp)
Searches and normalizes the symbol as it is listed on binance.
To retrieve this information, a request to the binance API is done. The result is then cached to ensure the request is done only once.
Order of which symbol comes first, and case sensitivity does not matter.
Returns {:ok, "SYMBOL"}
if successfully, or {:error, reason}
otherwise.
Examples
These 3 calls will result in the same result string:
find_symbol(%Binance.TradePair{from: "ETH", to: "REQ"})
find_symbol(%Binance.TradePair{from: "REQ", to: "ETH"})
find_symbol(%Binance.TradePair{from: "rEq", to: "eTH"})
Result: {:ok, "REQETH"}
get_account_info(api_key, secret_key, is_testnet \\ false)
get 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/futures/en/#account-information-v2-user_data to understand all the parameters
Examples
get_account_info("api_key", "api_secret", true)
Result:
{:ok,
%{
"timezone": "UTC",
"serverTime": 1640141838081,
"futuresType": "U_MARGINED",
"symbols": [...],
...
}
}
or
{:error, {:binance_error, %{code: -2019, msg: "Margin is insufficient."}}}
get_all_orders(api_key, secret_key, is_testnet \\ false)
get_all_prices(is_testnet \\ false)
Get all symbols and current prices listed in binance
Returns {:ok, [%Binance.SymbolPrice{}]}
or {:error, reason}
.
Example
{:ok,
[%Binance.SymbolPrice{price: "0.07579300", symbol: "ETHBTC"},
%Binance.SymbolPrice{price: "0.01670200", symbol: "LTCBTC"},
%Binance.SymbolPrice{price: "0.00114550", symbol: "BNBBTC"},
%Binance.SymbolPrice{price: "0.00640000", symbol: "NEOBTC"},
%Binance.SymbolPrice{price: "0.00030000", symbol: "123456"},
%Binance.SymbolPrice{price: "0.04895000", symbol: "QTUMETH"},
...]}
get_exchange_info(is_testnet \\ false)
get exchange 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/futures/en/#exchange-information to understand all the parameters
Examples
get_exchange_info(true)
Result:
{:ok,
%{
"timezone": "UTC",
"serverTime": 1640141838081,
"futuresType": "U_MARGINED",
"symbols": [...],
...
}
}
or
{:error, {:binance_error, %{code: -2019, msg: "Margin is insufficient."}}}
get_open_orders(api_key, secret_key, is_testnet \\ false)
order_limit_buy(params, api_secret, api_key, is_testnet \\ false)
Creates a new limit buy order
Symbol can be a binance symbol in the form of "ETHBTC"
or %Binance.TradePair{}
.
Returns {:ok, %{}}
or {:error, reason}
order_limit_sell(params, api_secret, api_key, is_testnet \\ false)
Creates a new limit sell order
Symbol can be a binance symbol in the form of "ETHBTC"
or %Binance.TradePair{}
.
Returns {:ok, %{}}
or {:error, reason}
order_market_buy(params, api_secret, api_key, is_testnet \\ false)
Creates a new market buy order
Symbol can be a binance symbol in the form of "ETHBTC"
or %Binance.TradePair{}
.
Returns {:ok, %{}}
or {:error, reason}
order_market_sell(params, api_secret, api_key, is_testnet \\ false)
Creates a new market sell order
Symbol can be a binance symbol in the form of "ETHBTC"
or %Binance.TradePair{}
.
Returns {:ok, %{}}
or {:error, reason}
parse_account_info(arg)
parse_batch_orders_response(arg)
parse_exchange_info(arg)
parse_order_response(arg)
ping(is_testnet \\ false)
Pings binance API. Returns {:ok, %{}}
if successful, {:error, reason}
otherwise