binance_api v0.1.5 Binance
Main module that interacts with Binance
Link to this section Summary
Functions
Get all account orders; active, canceled, or filled
Cancel an active order
Creates a new order on binance
Fetches user account from binance
Get all symbols and current prices listed in binance
Retrieves the bids & asks of the order book up to the depth for the given symbol
Check an order’s status
Get binance server time in unix epoch
Retrieves the current ticker information for the given trade pair
Get all open orders on a symbol. Careful when accessing this with no symbol
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
Get all account orders; active, canceled, or filled.
Returns {:ok, %Binance.OrderResponse{}}
or {:error, reason}
## Examples
iex> Binance.all_orders "ADBTC"
{:ok,
[
%Binance.OrderResponse{
client_order_id: "web_a26a41e71ca641e8812a444436e7b7cb",
executed_qty: "3897.00000000",
iceberg_qty: "0.00000000",
is_working: true,
order_id: 31501417,
orig_qty: "3897.00000000",
price: "0.00002606",
side: "BUY",
status: "FILLED",
stop_price: "0.00000000",
symbol: "ADABTC",
time: 1526363552351,
time_in_force: "GTC",
transact_time: nil,
type: "LIMIT"
},
%Binance.OrderResponse{
client_order_id: "web_0119daab853b4e129edfea4345cbda17",
executed_qty: "0.00000000",
iceberg_qty: "0.00000000",
is_working: true,
order_id: 44700734,
orig_qty: "3893.00000000",
price: "0.00003249",
side: "SELL",
status: "NEW",
stop_price: "0.00000000",
symbol: "ADABTC",
time: 1531958591439,
time_in_force: "GTC",
transact_time: nil,
type: "LIMIT"
}
]}
Cancel an active order.
Returns {:ok, %Binance.OrderResponse{}}
or {:error, reason}
Examples
iex> Binance.cancel_order "ADABTC", 18845701
{:ok,
%Binance.OrderResponse{
client_order_id: "gO3U4DaFxcAgolV0nunw2U",
executed_qty: nil,
iceberg_qty: nil,
is_working: nil,
order_id: 18845701,
orig_qty: nil,
price: nil,
side: nil,
status: nil,
stop_price: nil,
symbol: "ADABTC",
time: nil,
time_in_force: nil,
transact_time: nil,
type: nil
}}
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
Fetches user account from binance
Returns {:ok, %Binance.Account{}}
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://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#account-information-user_data to understand API
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"},
...]}
Retrieves the bids & asks of the order book up to the depth for the given symbol
Returns {:ok, %{bids: [...], asks: [...], lastUpdateId: 12345}}
or {:error, reason}
Example
{:ok,
%Binance.OrderBook{
asks: [
["8400.00000000", "2.04078100", []],
["8405.35000000", "0.50354700", []],
["8406.00000000", "0.32769800", []],
["8406.33000000", "0.00239000", []],
["8406.51000000", "0.03241000", []]
],
bids: [
["8393.00000000", "0.20453200", []],
["8392.57000000", "0.02639000", []],
["8392.00000000", "1.40893300", []],
["8390.09000000", "0.07047100", []],
["8388.72000000", "0.04577400", []]
],
last_update_id: 113634395
}
}
Check an order’s status.
Returns {:ok, %Binance.OrderResponse{}}
or {:error, reason}
## Examples
iex> Binance.get_order "ADABTC", 44730730
{:ok,
%Binance.OrderResponse{
client_order_id: "web_0019daab853b4e129edfea4345cbda17",
executed_qty: "0.00000000",
iceberg_qty: "0.00000000",
is_working: true,
order_id: 44730730,
orig_qty: "3893.00000000",
price: "0.00003249",
side: "SELL",
status: "NEW",
stop_price: "0.00000000",
symbol: "ADABTC",
time: 1531958591439,
time_in_force: "GTC",
transact_time: nil,
type: "LIMIT"
}}
Get binance server time in unix epoch.
Returns {:ok, time}
if successful, {:error, reason}
otherwise
Example
{:ok, 1515390701097}
Retrieves the current ticker information for the given trade pair.
Symbol can be a binance symbol in the form of "ETHBTC"
or %TradePair{}
.
Returns {:ok, %Binance.Ticker{}}
or {:error, reason}
Example
{:ok,
%Binance.Ticker{ask_price: "0.07548800", bid_price: "0.07542100",
close_time: 1515391124878, count: 661676, first_id: 16797673,
high_price: "0.07948000", last_id: 17459348, last_price: "0.07542000",
low_price: "0.06330000", open_price: "0.06593800", open_time: 1515304724878,
prev_close_price: "0.06593800", price_change: "0.00948200",
price_change_percent: "14.380", volume: "507770.18500000",
weighted_avg_price: "0.06946930"}}
Get all open orders on a symbol. Careful when accessing this with no symbol.
Returns {:ok, %Binance.OrderResponse{}}
or {:error, reason}
Examples
iex(52)> Binance.open_orders "ADABTC"
{:ok,
[
%Binance.OrderResponse{
client_order_id: "web_0319daab853b4e129edfea4345cbda17",
executed_qty: "0.00000000",
iceberg_qty: "0.00000000",
is_working: true,
order_id: 44730734,
orig_qty: "3893.00000000",
price: "0.00003249",
side: "SELL",
status: "NEW",
stop_price: "0.00000000",
symbol: "ADABTC",
time: 1531958591439,
time_in_force: "GTC",
transact_time: nil,
type: "LIMIT"
}
]}
Creates a new limit buy order
Symbol can be a binance symbol in the form of "ETHBTC"
or %TradePair{}
.
Returns {:ok, %{}}
or {:error, reason}
Creates a new limit sell order
Symbol can be a binance symbol in the form of "ETHBTC"
or %TradePair{}
.
Returns {:ok, %{}}
or {:error, reason}
Creates a new market buy order
Symbol can be a binance symbol in the form of "ETHBTC"
or %TradePair{}
.
Returns {:ok, %{}}
or {:error, reason}
Creates a new market sell order
Symbol can be a binance symbol in the form of "ETHBTC"
or %TradePair{}
.
Returns {:ok, %{}}
or {:error, reason}
Pings binance API. Returns {:ok, %{}}
if successful, {:error, reason}
otherwise