Git Product home page Git Product logo

binance.ex's Introduction

binance.ex

Hex.pm Version Hex Docs Hex.pm Download Total

Unofficial Elixir wrapper for interacting with the Binance API.

NOTE: v2 is a full rewrite that's now fully auto-generated from the Binance docs. There are breaking changes, and it's not as battle-tested as v1 yet. If you don't need any of the new endpoints, stick to v1 for now.

Installation

  1. The package can be installed by adding binance to your list of dependencies in mix.exs:
def deps do
  [
    {:binance, "~> 2.0.1"}
  ]
end
  1. Add your Binance API credentials to your config.exs file, like so (you can create a new API key here):
config :binance,
  api_key: "xxx",
  secret_key: "xxx",
  end_point: "https://api.binance.us" # Add for the US API end point. The default is for "https://api.binance.com"

Features

  • Fully autogenerated from Binance documentation using metaprogramming
  • Mandatory parameters are parsed into function arguments, optional parameters into opts in true elixir fashion
  • Nice docs and typespecs (although currently with any()) for all endpoints:
iex(24)> h Binance.Trade.post_order

                 def post_order(symbol, side, type, opts \\ [])

  @spec post_order(any(), any(), any(),
          recvWindow: any(),
          newOrderRespType: any(),
          icebergQty: any(),
          trailingDelta: any(),
          stopPrice: any(),
          strategyType: any(),
          strategyId: any(),
          newClientOrderId: any(),
          price: any(),
          quoteOrderQty: any(),
          quantity: any(),
          timeInForce: any(),
          timestamp: any()
        ) :: {:ok, any()} | {:error, any()}

New Order (TRADE)

Send in a new order.

  • LIMIT_MAKER are LIMIT orders that will be rejected if they would
    immediately match and trade as a taker.
  • STOP_LOSS and TAKE_PROFIT will execute a MARKET order when the
    stopPrice is reached.
  • Any LIMIT or LIMIT_MAKER type order can be made an iceberg order by
    sending an icebergQty.
  • Any order with an icebergQty MUST have timeInForce set to GTC.
  • MARKET orders using quantity specifies how much a user wants to buy or
    sell based on the market price.
  • MARKET orders using quoteOrderQty specifies the amount the user wants
    to spend (when buying) or receive (when selling) of the quote asset; the
    correct quantity will be determined based on the market liquidity and
    quoteOrderQty.
  • MARKET orders using quoteOrderQty will not break LOT_SIZE filter rules;
    the order will execute a quantity that will have the notional value as
    close as possible to quoteOrderQty.
  • same newClientOrderId can be accepted only when the previous one is
    filled, otherwise the order will be rejected.

Trigger order price rules against market price for both MARKET and LIMIT
versions:

  • Price above market price: STOP_LOSS BUY, TAKE_PROFIT SELL
  • Price below market price: STOP_LOSS SELL, TAKE_PROFIT BUY

Weight(IP): 1

Details:

  • METHOD: post
  • URL: /api/v3/order

Mandatory params:

  • symbol - Trading symbol, e.g. BNBUSDT
  • side -
  • type - Order type

Optional params:

  • timestamp - timestamp
  • timeInForce - Order time in force
  • quantity - Order quantity
  • quoteOrderQty - Quote quantity
  • price - Order price
  • newClientOrderId - A unique id among open orders. Automatically
    generated if not sent.
  • strategyId -
  • strategyType - The value cannot be less than 1000000
  • stopPrice - Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and
    TAKE_PROFIT_LIMIT orders.
  • trailingDelta - Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and
    TAKE_PROFIT_LIMIT orders.
  • icebergQty - Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to
    create an iceberg order.
  • newOrderRespType - Set the response JSON. MARKET and LIMIT order types
    default to FULL, all other orders default to ACK.
  • recvWindow - The value cannot be greater than 60000

Supported endpoints

Group: BLVT

  • get_blvt_redeem_record (get:/sapi/v1/blvt/redeem/record)
  • get_blvt_subscribe_record (get:/sapi/v1/blvt/subscribe/record)
  • get_blvt_token_info (get:/sapi/v1/blvt/tokenInfo)
  • get_blvt_user_limit (get:/sapi/v1/blvt/userLimit)
  • post_blvt_redeem (post:/sapi/v1/blvt/redeem)
  • post_blvt_subscribe (post:/sapi/v1/blvt/subscribe)

Group: BSwap

  • get_bswap_add_liquidity_preview (get:/sapi/v1/bswap/addLiquidityPreview)
  • get_bswap_claimed_history (get:/sapi/v1/bswap/claimedHistory)
  • get_bswap_liquidity (get:/sapi/v1/bswap/liquidity)
  • get_bswap_liquidity_ops (get:/sapi/v1/bswap/liquidityOps)
  • get_bswap_pool_configure (get:/sapi/v1/bswap/poolConfigure)
  • get_bswap_pools (get:/sapi/v1/bswap/pools)
  • get_bswap_quote (get:/sapi/v1/bswap/quote)
  • get_bswap_remove_liquidity_preview (get:/sapi/v1/bswap/removeLiquidityPreview)
  • get_bswap_swap (get:/sapi/v1/bswap/swap)
  • get_bswap_unclaimed_rewards (get:/sapi/v1/bswap/unclaimedRewards)
  • post_bswap_claim_rewards (post:/sapi/v1/bswap/claimRewards)
  • post_bswap_liquidity_add (post:/sapi/v1/bswap/liquidityAdd)
  • post_bswap_liquidity_remove (post:/sapi/v1/bswap/liquidityRemove)
  • post_bswap_swap (post:/sapi/v1/bswap/swap)

Group: C2C

  • get_c2c_order_match_list_user_order_history (get:/sapi/v1/c2c/orderMatch/listUserOrderHistory)

Group: Convert

  • get_convert_asset_info (get:/sapi/v1/convert/assetInfo)
  • get_convert_exchange_info (get:/sapi/v1/convert/exchangeInfo)
  • get_convert_order_status (get:/sapi/v1/convert/orderStatus)
  • get_convert_trade_flow (get:/sapi/v1/convert/tradeFlow)
  • post_convert_accept_quote (post:/sapi/v1/convert/acceptQuote)
  • post_convert_get_quote (post:/sapi/v1/convert/getQuote)

Group: Crypto Loans

  • get_loan_borrow_history (get:/sapi/v1/loan/borrow/history)
  • get_loan_collateral_data (get:/sapi/v1/loan/collateral/data)
  • get_loan_income (get:/sapi/v1/loan/income)
  • get_loan_loanable_data (get:/sapi/v1/loan/loanable/data)
  • get_loan_ltv_adjustment_history (get:/sapi/v1/loan/ltv/adjustment/history)
  • get_loan_ongoing_orders (get:/sapi/v1/loan/ongoing/orders)
  • get_loan_repay_collateral_rate (get:/sapi/v1/loan/repay/collateral/rate)
  • get_loan_repay_history (get:/sapi/v1/loan/repay/history)
  • post_loan_adjust_ltv (post:/sapi/v1/loan/adjust/ltv)
  • post_loan_borrow (post:/sapi/v1/loan/borrow)
  • post_loan_customize_margin_call (post:/sapi/v1/loan/customize/margin_call)
  • post_loan_repay (post:/sapi/v1/loan/repay)

Group: Fiat

  • get_fiat_orders (get:/sapi/v1/fiat/orders)
  • get_fiat_payments (get:/sapi/v1/fiat/payments)

Group: Futures

  • get_futures_loan_adjust_collateral_history (get:/sapi/v1/futures/loan/adjustCollateral/history)
  • get_futures_loan_borrow_history (get:/sapi/v1/futures/loan/borrow/history)
  • get_futures_loan_interest_history (get:/sapi/v1/futures/loan/interestHistory)
  • get_futures_loan_liquidation_history (get:/sapi/v1/futures/loan/liquidationHistory)
  • get_futures_loan_repay_history (get:/sapi/v1/futures/loan/repay/history)
  • get_futures_loan_wallet (get:/sapi/v2/futures/loan/wallet)
  • get_futures_transfer (get:/sapi/v1/futures/transfer)
  • post_futures_transfer (post:/sapi/v1/futures/transfer)

Group: Futures Algo

  • delete_algo_futures_order (delete:/sapi/v1/algo/futures/order)
  • get_algo_futures_historical_orders (get:/sapi/v1/algo/futures/historicalOrders)
  • get_algo_futures_open_orders (get:/sapi/v1/algo/futures/openOrders)
  • get_algo_futures_sub_orders (get:/sapi/v1/algo/futures/subOrders)
  • post_algo_futures_new_order_twap (post:/sapi/v1/algo/futures/newOrderTwap)
  • post_algo_futures_new_order_vp (post:/sapi/v1/algo/futures/newOrderVp)

Group: Gift Card

  • get_giftcard_buy_code_token_limit (get:/sapi/v1/giftcard/buyCode/token-limit)
  • get_giftcard_cryptography_rsa_public_key (get:/sapi/v1/giftcard/cryptography/rsa-public-key)
  • get_giftcard_verify (get:/sapi/v1/giftcard/verify)
  • post_giftcard_buy_code (post:/sapi/v1/giftcard/buyCode)
  • post_giftcard_create_code (post:/sapi/v1/giftcard/createCode)
  • post_giftcard_redeem_code (post:/sapi/v1/giftcard/redeemCode)

Group: Margin

  • delete_margin_order_list (delete:/sapi/v1/margin/orderList)
  • post_margin_isolated_account (post:/sapi/v1/margin/isolated/account)
  • get_margin_open_order_list (get:/sapi/v1/margin/openOrderList)
  • get_margin_max_borrowable (get:/sapi/v1/margin/maxBorrowable)
  • post_margin_order_oco (post:/sapi/v1/margin/order/oco)
  • get_margin_max_transferable (get:/sapi/v1/margin/maxTransferable)
  • get_margin_interest_rate_history (get:/sapi/v1/margin/interestRateHistory)
  • get_margin_interest_history (get:/sapi/v1/margin/interestHistory)
  • get_margin_my_trades (get:/sapi/v1/margin/myTrades)
  • get_margin_transfer (get:/sapi/v1/margin/transfer)
  • post_margin_isolated_transfer (post:/sapi/v1/margin/isolated/transfer)
  • post_margin_loan (post:/sapi/v1/margin/loan)
  • get_margin_loan (get:/sapi/v1/margin/loan)
  • get_margin_account (get:/sapi/v1/margin/account)
  • get_margin_isolated_transfer (get:/sapi/v1/margin/isolated/transfer)
  • get_margin_isolated_pair (get:/sapi/v1/margin/isolated/pair)
  • get_margin_isolated_margin_data (get:/sapi/v1/margin/isolatedMarginData)
  • post_margin_transfer (post:/sapi/v1/margin/transfer)
  • post_margin_order (post:/sapi/v1/margin/order)
  • get_margin_order_list (get:/sapi/v1/margin/orderList)
  • get_margin_order (get:/sapi/v1/margin/order)
  • get_bnb_burn (get:/sapi/v1/bnbBurn)
  • get_margin_all_assets (get:/sapi/v1/margin/allAssets)
  • get_margin_all_orders (get:/sapi/v1/margin/allOrders)
  • get_margin_isolated_account (get:/sapi/v1/margin/isolated/account)
  • get_margin_force_liquidation_rec (get:/sapi/v1/margin/forceLiquidationRec)
  • post_bnb_burn (post:/sapi/v1/bnbBurn)
  • post_margin_repay (post:/sapi/v1/margin/repay)
  • delete_margin_open_orders (delete:/sapi/v1/margin/openOrders)
  • get_margin_pair (get:/sapi/v1/margin/pair)
  • get_margin_all_pairs (get:/sapi/v1/margin/allPairs)
  • get_margin_price_index (get:/sapi/v1/margin/priceIndex)
  • get_margin_trade_coeff (get:/sapi/v1/margin/tradeCoeff)
  • get_margin_isolated_margin_tier (get:/sapi/v1/margin/isolatedMarginTier)
  • get_margin_dribblet (get:/sapi/v1/margin/dribblet)
  • get_margin_repay (get:/sapi/v1/margin/repay)
  • get_margin_cross_margin_data (get:/sapi/v1/margin/crossMarginData)
  • delete_margin_order (delete:/sapi/v1/margin/order)
  • get_margin_all_order_list (get:/sapi/v1/margin/allOrderList)
  • get_margin_isolated_account_limit (get:/sapi/v1/margin/isolated/accountLimit)
  • get_margin_isolated_all_pairs (get:/sapi/v1/margin/isolated/allPairs)
  • get_margin_asset (get:/sapi/v1/margin/asset)
  • get_margin_rate_limit_order (get:/sapi/v1/margin/rateLimit/order)
  • get_margin_open_orders (get:/sapi/v1/margin/openOrders)
  • delete_margin_isolated_account (delete:/sapi/v1/margin/isolated/account)

Group: Market

  • get_agg_trades (get:/api/v3/aggTrades)
  • get_avg_price (get:/api/v3/avgPrice)
  • get_depth (get:/api/v3/depth)
  • get_exchange_info (get:/api/v3/exchangeInfo)
  • get_historical_trades (get:/api/v3/historicalTrades)
  • get_klines (get:/api/v3/klines)
  • get_ping (get:/api/v3/ping)
  • get_ticker (get:/api/v3/ticker)
  • get_ticker_24hr (get:/api/v3/ticker/24hr)
  • get_ticker_book_ticker (get:/api/v3/ticker/bookTicker)
  • get_ticker_price (get:/api/v3/ticker/price)
  • get_time (get:/api/v3/time)
  • get_trades (get:/api/v3/trades)
  • get_ui_klines (get:/api/v3/uiKlines)

Group: Mining

  • get_mining_hash_transfer_config_details_list (get:/sapi/v1/mining/hash-transfer/config/details/list)
  • get_mining_hash_transfer_profit_details (get:/sapi/v1/mining/hash-transfer/profit/details)
  • get_mining_payment_list (get:/sapi/v1/mining/payment/list)
  • get_mining_payment_other (get:/sapi/v1/mining/payment/other)
  • get_mining_payment_uid (get:/sapi/v1/mining/payment/uid)
  • get_mining_pub_algo_list (get:/sapi/v1/mining/pub/algoList)
  • get_mining_pub_coin_list (get:/sapi/v1/mining/pub/coinList)
  • get_mining_statistics_user_list (get:/sapi/v1/mining/statistics/user/list)
  • get_mining_statistics_user_status (get:/sapi/v1/mining/statistics/user/status)
  • get_mining_worker_detail (get:/sapi/v1/mining/worker/detail)
  • get_mining_worker_list (get:/sapi/v1/mining/worker/list)
  • post_mining_hash_transfer_config (post:/sapi/v1/mining/hash-transfer/config)
  • post_mining_hash_transfer_config_cancel (post:/sapi/v1/mining/hash-transfer/config/cancel)

Group: NFT

  • get_nft_history_deposit (get:/sapi/v1/nft/history/deposit)
  • get_nft_history_transactions (get:/sapi/v1/nft/history/transactions)
  • get_nft_history_withdraw (get:/sapi/v1/nft/history/withdraw)
  • get_nft_user_get_asset (get:/sapi/v1/nft/user/getAsset)

Group: Pay

  • get_pay_transactions (get:/sapi/v1/pay/transactions)

Group: Portfolio Margin

  • get_portfolio_account (get:/sapi/v1/portfolio/account)
  • get_portfolio_collateral_rate (get:/sapi/v1/portfolio/collateralRate)
  • get_portfolio_pm_loan (get:/sapi/v1/portfolio/pmLoan)
  • post_portfolio_repay (post:/sapi/v1/portfolio/repay)

Group: Rebate

  • get_rebate_tax_query (get:/sapi/v1/rebate/taxQuery)

Group: Savings

  • get_lending_daily_product_list (get:/sapi/v1/lending/daily/product/list)
  • get_lending_daily_token_position (get:/sapi/v1/lending/daily/token/position)
  • get_lending_daily_user_left_quota (get:/sapi/v1/lending/daily/userLeftQuota)
  • get_lending_daily_user_redemption_quota (get:/sapi/v1/lending/daily/userRedemptionQuota)
  • get_lending_project_list (get:/sapi/v1/lending/project/list)
  • get_lending_project_position_list (get:/sapi/v1/lending/project/position/list)
  • get_lending_union_account (get:/sapi/v1/lending/union/account)
  • get_lending_union_interest_history (get:/sapi/v1/lending/union/interestHistory)
  • get_lending_union_purchase_record (get:/sapi/v1/lending/union/purchaseRecord)
  • get_lending_union_redemption_record (get:/sapi/v1/lending/union/redemptionRecord)
  • post_lending_customized_fixed_purchase (post:/sapi/v1/lending/customizedFixed/purchase)
  • post_lending_daily_purchase (post:/sapi/v1/lending/daily/purchase)
  • post_lending_daily_redeem (post:/sapi/v1/lending/daily/redeem)
  • post_lending_position_changed (post:/sapi/v1/lending/positionChanged)

Group: Staking

  • get_staking_personal_left_quota (get:/sapi/v1/staking/personalLeftQuota)
  • get_staking_position (get:/sapi/v1/staking/position)
  • get_staking_product_list (get:/sapi/v1/staking/productList)
  • get_staking_staking_record (get:/sapi/v1/staking/stakingRecord)
  • post_staking_purchase (post:/sapi/v1/staking/purchase)
  • post_staking_redeem (post:/sapi/v1/staking/redeem)
  • post_staking_set_auto_staking (post:/sapi/v1/staking/setAutoStaking)

Group: Sub-Account

  • post_sub_account_transfer_sub_to_master (post:/sapi/v1/sub-account/transfer/subToMaster)
  • get_sub_account_futures_position_risk (get:/sapi/v2/sub-account/futures/positionRisk)
  • post_sub_account_margin_enable (post:/sapi/v1/sub-account/margin/enable)
  • get_sub_account_transfer_sub_user_history (get:/sapi/v1/sub-account/transfer/subUserHistory)
  • get_capital_deposit_sub_address (get:/sapi/v1/capital/deposit/subAddress)
  • get_sub_account_futures_internal_transfer (get:/sapi/v1/sub-account/futures/internalTransfer)
  • get_sub_account_margin_account_summary (get:/sapi/v1/sub-account/margin/accountSummary)
  • post_sub_account_futures_transfer (post:/sapi/v1/sub-account/futures/transfer)
  • get_sub_account_assets (get:/sapi/v3/sub-account/assets)
  • post_sub_account_margin_transfer (post:/sapi/v1/sub-account/margin/transfer)
  • get_sub_account_sub_transfer_history (get:/sapi/v1/sub-account/sub/transfer/history)
  • get_managed_subaccount_asset (get:/sapi/v1/managed-subaccount/asset)
  • get_managed_subaccount_account_snapshot (get:/sapi/v1/managed-subaccount/accountSnapshot)
  • post_sub_account_universal_transfer (post:/sapi/v1/sub-account/universalTransfer)
  • post_sub_account_futures_internal_transfer (post:/sapi/v1/sub-account/futures/internalTransfer)
  • get_sub_account_list (get:/sapi/v1/sub-account/list)
  • post_sub_account_sub_account_api_ip_restriction_ip_list (post:/sapi/v1/sub-account/subAccountApi/ipRestriction/ipList)
  • get_sub_account_sub_account_api_ip_restriction (get:/sapi/v1/sub-account/subAccountApi/ipRestriction)
  • post_managed_subaccount_deposit (post:/sapi/v1/managed-subaccount/deposit)
  • get_sub_account_spot_summary (get:/sapi/v1/sub-account/spotSummary)
  • get_sub_account_api_restrictions_ip_restriction_third_party_list (get:/sapi/v1/sub-account/apiRestrictions/ipRestriction/thirdPartyList)
  • post_sub_account_virtual_sub_account (post:/sapi/v1/sub-account/virtualSubAccount)
  • get_sub_account_universal_transfer (get:/sapi/v1/sub-account/universalTransfer)
  • post_managed_subaccount_withdraw (post:/sapi/v1/managed-subaccount/withdraw)
  • post_sub_account_sub_account_api_ip_restriction (post:/sapi/v2/sub-account/subAccountApi/ipRestriction)
  • get_sub_account_status (get:/sapi/v1/sub-account/status)
  • delete_sub_account_sub_account_api_ip_restriction_ip_list (delete:/sapi/v1/sub-account/subAccountApi/ipRestriction/ipList)
  • post_sub_account_blvt_enable (post:/sapi/v1/sub-account/blvt/enable)
  • get_sub_account_futures_account (get:/sapi/v2/sub-account/futures/account)
  • get_capital_deposit_sub_hisrec (get:/sapi/v1/capital/deposit/subHisrec)
  • get_sub_account_margin_account (get:/sapi/v1/sub-account/margin/account)
  • get_sub_account_futures_account_summary (get:/sapi/v2/sub-account/futures/accountSummary)
  • post_sub_account_transfer_sub_to_sub (post:/sapi/v1/sub-account/transfer/subToSub)
  • post_sub_account_futures_enable (post:/sapi/v1/sub-account/futures/enable)

Group: Trade

  • delete_open_orders (delete:/api/v3/openOrders)
  • delete_order (delete:/api/v3/order)
  • delete_order_list (delete:/api/v3/orderList)
  • get_account (get:/api/v3/account)
  • get_all_order_list (get:/api/v3/allOrderList)
  • get_all_orders (get:/api/v3/allOrders)
  • get_my_trades (get:/api/v3/myTrades)
  • get_open_order_list (get:/api/v3/openOrderList)
  • get_open_orders (get:/api/v3/openOrders)
  • get_order (get:/api/v3/order)
  • get_order_list (get:/api/v3/orderList)
  • get_rate_limit_order (get:/api/v3/rateLimit/order)
  • post_order (post:/api/v3/order)
  • post_order_cancel_replace (post:/api/v3/order/cancelReplace)
  • post_order_oco (post:/api/v3/order/oco)
  • post_order_test (post:/api/v3/order/test)

Group: User Data Stream

  • delete_user_data_stream (delete:/sapi/v1/userDataStream)
  • delete_user_data_stream_isolated (delete:/sapi/v1/userDataStream/isolated)
  • post_user_data_stream (post:/sapi/v1/userDataStream)
  • post_user_data_stream_isolated (post:/sapi/v1/userDataStream/isolated)
  • put_user_data_stream (put:/sapi/v1/userDataStream)
  • put_user_data_stream_isolated (put:/sapi/v1/userDataStream/isolated)

Group: Wallet

  • get_account_api_restrictions (get:/sapi/v1/account/apiRestrictions)
  • get_account_api_trading_status (get:/sapi/v1/account/apiTradingStatus)
  • get_account_snapshot (get:/sapi/v1/accountSnapshot)
  • get_account_status (get:/sapi/v1/account/status)
  • get_asset_asset_detail (get:/sapi/v1/asset/assetDetail)
  • get_asset_asset_dividend (get:/sapi/v1/asset/assetDividend)
  • get_asset_convert_transfer_query_by_page (get:/sapi/v1/asset/convert-transfer/queryByPage)
  • get_asset_dribblet (get:/sapi/v1/asset/dribblet)
  • get_asset_ledger_transfer_cloud_mining_query_by_page (get:/sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage)
  • get_asset_trade_fee (get:/sapi/v1/asset/tradeFee)
  • get_asset_transfer (get:/sapi/v1/asset/transfer)
  • get_capital_config_getall (get:/sapi/v1/capital/config/getall)
  • get_capital_deposit_address (get:/sapi/v1/capital/deposit/address)
  • get_capital_deposit_hisrec (get:/sapi/v1/capital/deposit/hisrec)
  • get_capital_withdraw_history (get:/sapi/v1/capital/withdraw/history)
  • get_system_status (get:/sapi/v1/system/status)
  • post_account_disable_fast_withdraw_switch (post:/sapi/v1/account/disableFastWithdrawSwitch)
  • post_account_enable_fast_withdraw_switch (post:/sapi/v1/account/enableFastWithdrawSwitch)
  • post_asset_convert_transfer (post:/sapi/v1/asset/convert-transfer)
  • post_asset_dust (post:/sapi/v1/asset/dust)
  • post_asset_dust_btc (post:/sapi/v1/asset/dust-btc)
  • post_asset_get_funding_asset (post:/sapi/v1/asset/get-funding-asset)
  • post_asset_get_user_asset (post:/sapi/v3/asset/getUserAsset)
  • post_asset_transfer (post:/sapi/v1/asset/transfer)
  • post_capital_withdraw_apply (post:/sapi/v1/capital/withdraw/apply)

Group: VIP Loans

  • get_loan_vip_collateral_account (get:/sapi/v1/loan/vip/collateral/account)
  • get_loan_vip_ongoing_orders (get:/sapi/v1/loan/vip/ongoing/orders)
  • get_loan_vip_repay_history (get:/sapi/v1/loan/vip/repay/history)
  • post_loan_vip_repay (post:/sapi/v1/loan/vip/repay)

Caveats

  • Most endpoints don't have proper response structs assigned to them yet due to them not being available in the docs, this will change over time
  • Typespec for arguments is currently any(), same reason: lack of types in the definition used

Usage

Documentation available at https://hexdocs.pm/binance (make sure you have 2.0.0 selected)

Get all prices

iex> Binance.Market.get_ticker_price
{:ok,
 [
   %Binance.Structs.SymbolPrice{symbol: "ETHBTC", price: "0.06275000"},
   %Binance.Structs.SymbolPrice{symbol: "LTCBTC", price: "0.00363100"},
   %Binance.Structs.SymbolPrice{symbol: "BNBBTC", price: "0.00804100"},
   %Binance.Structs.SymbolPrice{symbol: "NEOBTC", price: "0.00031420"},
   %Binance.Structs.SymbolPrice{symbol: "QTUMETH", price: "0.00147800"},
   %Binance.Structs.SymbolPrice{symbol: "EOSETH", price: "0.00039460"},
   %Binance.Structs.SymbolPrice{symbol: "SNTETH", price: "0.00001240"},
   %Binance.Structs.SymbolPrice{symbol: "BNTETH", price: "0.00020200"},
   %Binance.Structs.SymbolPrice{symbol: "BCCBTC", price: "0.07908100"},
   %Binance.Structs.SymbolPrice{symbol: "GASBTC", price: "0.00008800"},
   %Binance.Structs.SymbolPrice{symbol: "BNBETH", price: "0.12810000"},
   %Binance.Structs.SymbolPrice{symbol: "BTCUSDT", price: "30526.74000000"},
   %Binance.Structs.SymbolPrice{symbol: "ETHUSDT", price: "1915.16000000"},
   ...
 ]}

Buy 0.01 BNB for the current market price

iex> Binance.Trade.post_order "BNBUSDT", "BUY", "MARKET", quantity: 0.01

Earn

Get all earn positions

iex> Binance.Staking.get_staking_position "STAKING"

Get all earn products

iex> Binance.Staking.get_staking_product_list "STAKING"

Redeem all flexible staked assets

with {:ok, positions} <- Binance.Savings.get_lending_daily_token_position("") do 
  positions
  |> Enum.map(
    &Binance.Savings.post_lending_daily_redeem(&1.productId, &1.totalAmount, "FAST"
    )
  )
end

License

MIT

binance.ex's People

Contributors

amacgregor avatar asmodehn avatar ccjr avatar cdesch avatar cinderella-man avatar dependabot[bot] avatar dvcrn avatar gilacost avatar jakuj avatar juanpabloaj avatar luizparreira avatar mikaak avatar rupurt avatar voleoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

binance.ex's Issues

Setup publish to hex through CI

While migrating from travis to github ci, I forgot the auto-publish to hex.

Add a new CI step to publish to hex when there is a new tag

Compile -> Runtime Configuration ?

Hi everyone, I am opening this issue to start a conversation regarding compiled / runtime configuration.

Few reasons for this :

  • I wanted to test the behaviour of the code when the endpoint is not reachable, with bypass, but the endpoint is currently set at compile time, and cannot be changed while tests are running.
  • I wanted to test authenticated/anonymous requests, but the apikey/secret is currently set at compile time, and, just like the endpoint, cannot be changed at runtime.
  • I want to have my apikey/secret in a file in user's home, not in a config.exs (danger of accidental commit). I plan to use vapor to configure processes on application startup.
  • I want to use binance.ex in a multiprocess app...
  1. adding a private function to the module where we call Application.get_env(), instead of a module tag would make it changeable at runtime. Although not practical it would work fine in monoprocess situations (only one configuration possible) and would allow testing different configurations.

  2. Would be better: functions need more parameters for tests (or user code) to be able to change endpoint/apikey/secret on call which will make this code usable in a multiprocess situation (one process can connect to one account, another to a different account for instance, they would crash independently, etc.).

Regarding 2., in my specific usecase, I am currently thinking to have one process for public requests, another one for authenticated requests (only this process would be started with apikey and secret). Call rates will be different, public requests can probably be cached for a short time (don't modify the real world), authenticated clients can crash and respawn independently, etc.

Adding these parameters to functions can make the API more complex, so we should think about how to do this without degrading the dev experience...

I see a couple of options:

  • pass a datastructure to all api functions, such as :
%Binance.Connection{ endpoint: _, apikey: _ , secret: _ }
  • have an agent holding that "connection" data, configurable at runtime, and providing the same api.
  • there are probably other options, but I am not sure which one would be "simple and intuitive enough" for devs here. Python async http clients have "session" concept that may also be useful here: https://docs.aiohttp.org/en/stable/#client-example

What do you think about 1. ? I can do a quick PR, if this is something you are interested in.

What do you think about 2. ?

Also, let me know of any other issue that would be useful that would be useful to work on and fall into this "configuration" topic. I am currently working on this on my code, so I can probably contribute something similar here.

Cheers !

`:exvcr` configuration issues

Currently, when using the master branch, I have this warning when running tests

$ mix test
Compiling 17 files (.ex)
Generated binance app
You have configured application :exvcr in your configuration file,
but the application is not available.

This usually means one of:

  1. You have not added the application as a dependency in a mix.exs file.

  2. You are configuring an application that does not really exist.

Please ensure :exvcr exists or remove the configuration.

...........................

Finished in 7.1 seconds
27 tests, 0 failures

Randomized with seed 257469

On my elixir setup, this can be fixed by removing the applications: section in the MixProject in mix.exs
More info on this topic : https://www.amberbit.com/blog/2017/9/22/elixir-applications-vs-extra_applications-guide/

Also :exvcr commands are not accessible simply

$ mix vcr.check
Compiling 17 files (.ex)
Generated binance app
** (Mix) The task "vcr.check" could not be found

This can be fixed by allowing the dependency to be used in the :dev environment as well.

Not sure if there will be unintended side effects to these changes however ?

The PR is there #45

:crypto.hmac/3 removed in OTP 24

I'm using Elixir 1.12.0 (compiled with Erlang/OTP 24) and get the following error:

(UndefinedFunctionError) function :crypto.hmac/3 is undefined or private

According to https://erlang.org/doc/apps/crypto/new_api.html hmac/3 and hmac/4 have been deprecated in 23.0 and removed in OTP 24.0. The replacement would be mac/3 or mac4.

If it's important to maintain backward compatibility below 22.1 I suspect something like Kernel.function_exported?(:crypto, :mac, 3) could be used to determine which function to use (although I have no idea if this is standard practice).

Happy to submit a pull request!

Support for multiple API keys

First of all, thank you a lot for creating this wrapper! It helps me a lot.

I'm making an application that acts on behalf of multiple users. Currently api key and secret are global, stored in config. I'd love to be able to make requests using different credentials.

If I'll find time I'll try to create a PR, but just wanted to create an issue to let you know such feature would be very useful :)

Add `GET /api/v1/klines` endpoint

I started writing a wrapper around Binance's API to get historical data, and stumbled upon this repo. Would you be interested if I implemented the endpoint here?

Public CI

Do you have any preference for a public CI? e.g. CircleCI, Travis etc...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.