Class: BTCChina
- Inherits:
-
Object
- Object
- BTCChina
- Defined in:
- lib/btcchina.rb
Instance Method Summary collapse
- #buy(price, amount) ⇒ Object
- #cancel(order_id) ⇒ Object
- #current_price ⇒ Object
- #get_account_info ⇒ Object
- #get_deposit_address ⇒ Object
- #get_market_depth ⇒ Object
-
#initialize(access = '', secret = '') ⇒ BTCChina
constructor
A new instance of BTCChina.
- #sell(price, amount) ⇒ Object
- #ticker ⇒ Object
Constructor Details
#initialize(access = '', secret = '') ⇒ BTCChina
Returns a new instance of BTCChina.
9 10 11 12 |
# File 'lib/btcchina.rb', line 9 def initialize(access='', secret='') @access_key = access @secret_key = secret end |
Instance Method Details
#buy(price, amount) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/btcchina.rb', line 32 def buy(price, amount) price = price.to_f.round(5) amount = amount.to_f.round(8) post_data = initial_post_data post_data['method']='buyOrder' post_data['params']=[price, amount] post_request(post_data) end |
#cancel(order_id) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/btcchina.rb', line 50 def cancel(order_id) post_data = initial_post_data post_data['method']='cancelOrder' post_data['params']=[order_id] post_request(post_data) end |
#current_price ⇒ Object
57 58 59 60 61 62 |
# File 'lib/btcchina.rb', line 57 def current_price market_depth = get_market_depth ask = market_depth['ask'][0]['price'] bid = market_depth['bid'][0]['price'] (ask + bid) / 2 end |
#get_account_info ⇒ Object
14 15 16 17 18 19 |
# File 'lib/btcchina.rb', line 14 def get_account_info post_data = initial_post_data post_data['method'] = 'getAccountInfo' post_data['params'] = [] post_request(post_data) end |
#get_deposit_address ⇒ Object
21 22 23 |
# File 'lib/btcchina.rb', line 21 def get_deposit_address get_account_info['profile']['btc_deposit_address'] end |
#get_market_depth ⇒ Object
25 26 27 28 29 30 |
# File 'lib/btcchina.rb', line 25 def get_market_depth post_data = initial_post_data post_data['method'] = 'getMarketDepth2' post_data['params'] = [] post_request(post_data)["market_depth"] end |
#sell(price, amount) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/btcchina.rb', line 41 def sell(price, amount) price = price.to_f.round(5) amount = amount.to_f.round(8) post_data = initial_post_data post_data['method']='sellOrder' post_data['params']=[price, amount] post_request(post_data) end |
#ticker ⇒ Object
64 65 66 |
# File 'lib/btcchina.rb', line 64 def ticker get_request("https://data.btcchina.com/data/ticker") end |