Class: BTCChina

Inherits:
Object
  • Object
show all
Defined in:
lib/btcchina.rb

Instance Method Summary collapse

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_priceObject



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_infoObject



14
15
16
17
18
19
# File 'lib/btcchina.rb', line 14

def 
  post_data = initial_post_data
  post_data['method'] = 'getAccountInfo'
  post_data['params'] = []
  post_request(post_data)
end

#get_deposit_addressObject



21
22
23
# File 'lib/btcchina.rb', line 21

def get_deposit_address
  ['profile']['btc_deposit_address']
end

#get_market_depthObject



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

#tickerObject



64
65
66
# File 'lib/btcchina.rb', line 64

def ticker
  get_request("https://data.btcchina.com/data/ticker")
end