Giter Site home page Giter Site logo

btce's Introduction

BTCE

btce is an implementation of the BTC-e API for Erlang systems. The API is divided into three logical categories: the query API, the trading API, and the key management API.

Important Info

  • Due to httpc dependencies (ssl, inets, crypto) the btce library must be started prior to use (btce:start()).

  • A valid BTC-e api key is required for all trading API calls. See BTC-e for more information.

  • The BTC-e trading API uses an incrementing nonce to avoid replay attacks. Concurrently executed trade API calls should use unique API keys to avoid race conditions.

Query API Example

1> btce:start().
ok
2> btce:ticker(btc_usd).
{ok,[{high,101.699},
     {low,92.198},
     {avg,96.9485},
     {vol,685126.89766},
     {vol_cur,7046.95461},
     {last,97.894},
     {buy,97.893},
     {sell,97.498},
     {updated,1372125701},
     {server_time,1372125703}]}

Trade API Example

1> btce:start().
ok
2> %% stores api key in a DETS table, only needs to be done once .... ever
2> btce:add_key(my_api_key, "PUBLIC KEY", "PRIVATE KEY", [{default, true}]).
ok
3> %% trade API calls use the default key (unless overridden)
3> btce:info()
{ok, [{funds,
       [{usd,210.76262},
        {rur,0},
        {eur,0},
        {btc,0.},
        {ltc,200.179},
        {nmc,0},
        {nvc,0},
        {trc,0},
        {ppc,0},
        {ftc,0},
        {cnc,0}]},
      {rights,[{info,1},{trade,1},{withdraw,0}]},
      {transaction_count,8392},
      {open_orders,5},
      {server_time,1368442771}]

4> %% buy 1.23 BTC at 90.01 USD using a different API key
4> btce:trade(btc_usd, buy, 90.01, 1.23, [{api_key, different_key}]).
{ok,[{received,1.23},
     {remains,0},
     {order_id,0},
     {funds,
      [{usd,100.05032},
       {rur,0},
       {eur,0},
       {btc,1.23},
       {ltc,200.179},
       {nmc,0},
       {nvc,0},
       {trc,0},
       {ppc,0},
       {ftc,0},
       {cnc,0}]}]}

Types

pair()   = btc_usd | btc_rur | btc_eur | btc_cnh | btc_gbp |
           ltc_btc | ltc_usd | ltc_rur | ltc_eur | ltc_cnh |
           ltc_gbp | nmc_btc | nmc_usd | nvc_btc | nvc_usd |
           usd_rur | eur_usd | eur_rur | usd_cnh | gbp_usd |
           trc_btc | ppc_btc | ppc_usd | ftc_btc | xpm_btc.
rate()   = float().
amount() = float().

Query API

ticker/1

Retrieve ticker for given currency pair.

ticker(pair()) -> {error, term()} | {ok,[{high, float()},
                                         {low, float()},
                                         {avg, float()},
                                         {vol, float()},
                                         {vol_cur, float()},
                                         {last, float()},
                                         {buy, float()},
                                         {sell, float()},
                                         {updated, non_neg_integer()},
                                         {server_time,non_neg_integer()}]}.

depth/1

Retrieve the order book for currency pair.

depth(pair()) -> {error, term()} | {ok,[{asks, list([float(), float()])},
                                        {bids, list([float(), float()])}]}.

fee/1

Retrieve the exchange fee for currency pair.

fee(pair()) -> {error, term()} | {ok, float()}.

trades/1

Returns the most recent trades for currency pair.

trades(pair()) -> {error, term()} | {ok, list([{date, non_neg_integer()},
                                               {price, float()},
                                               {amount, float()},
                                               {tid, non_neg_integer()},
                                               {price_currency, binary()},
                                               {item, binary()},
                                               {trade_type,<<"ask">> |
                                                           <<"bid">>}])}.

Trade API

info/0, info/1

Returns profile information including current funds, key privileges, and order counts.

trade/4, trade/5

Buy or sell a currency pair at a given rate and amount.

trade(pair(), buy | sell, rate(), amount()) -> {error, term()} | {ok, ...}.

orders/0, orders/1

Return orders opened, filled, or canceled using the provided API key.

cancel_order/1, cancel_order/2

Cancel an order.

Helper Methods

pairs/0

Return a list of supported currency pairs.

pairs()-> list(pair()).

pip/1

Return the smallest price (or rate) change for a given currency pair.

pip(pair()) -> float().

start/0

Key Management API

add_key/3, add_key/4,

del_key/1,

get_key/0, get_key/1,

set_default_key/1,

TODO

  • update to support latest currency pairs
  • better documentation
  • add remaining trade API methods (trans_history, trade_history)
  • add more tests (use PropEr)

btce's People

Contributors

jhlywa avatar teleratec avatar

Watchers

James Cloos avatar Maksim Kiselev avatar

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.