Class: Huo::Trade
- Inherits:
-
Object
- Object
- Huo::Trade
- Defined in:
- lib/huo/trade.rb
Instance Method Summary collapse
- #buy(options = {}) ⇒ Object
- #buy_market(options = {}) ⇒ Object
- #get(options) ⇒ Object
- #get_account_info ⇒ Object
- #get_orders(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Trade
constructor
A new instance of Trade.
- #order_info ⇒ Object
- #sell(options = {}) ⇒ Object
- #sell_market(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Trade
Returns a new instance of Trade.
12 13 14 15 16 17 |
# File 'lib/huo/trade.rb', line 12 def initialize( = {}) path = [:tokens_path] config = path ? YAML.load_file(path) : {} @access_key = config['access_key'] || [:access_key] @secret_key = config['secret_key'] || [:secret_key] end |
Instance Method Details
#buy(options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/huo/trade.rb', line 30 def buy( = {}) args = { method: __method__, coin_type: 1, price: .fetch(:price), amount: .fetch(:btc_amount, 0.001) } get(args) end |
#buy_market(options = {}) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/huo/trade.rb', line 40 def buy_market( = {}) args = { method: __method__, coin_type: 1, amount: .fetch(:rmb_amount, 1) } get(args) end |
#get(options) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/huo/trade.rb', line 68 def get() params = .fetch(:params, ) digest = .fetch(:digest, params) digest_keys = digest.is_a?(Hash) ? digest.keys : digest = { params: pack_params(params, digest_keys), header: REQUEST_HEADER, accept: :json } response = RestClient.get(REQUEST_URL, ) normalize_json(response) end |
#get_account_info ⇒ Object
19 20 21 |
# File 'lib/huo/trade.rb', line 19 def get_account_info get(method: __method__) end |
#get_orders(options = {}) ⇒ Object
23 24 25 |
# File 'lib/huo/trade.rb', line 23 def get_orders( = {}) get(method: __method__, coin_type: 1) end |
#order_info ⇒ Object
27 28 |
# File 'lib/huo/trade.rb', line 27 def order_info end |
#sell(options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/huo/trade.rb', line 49 def sell( = {}) args = { method: __method__, coin_type: 1, price: .fetch(:price), amount: .fetch(:amount, 0.001) } get(args) end |
#sell_market(options = {}) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/huo/trade.rb', line 59 def sell_market( = {}) args = { method: __method__, coin_type: 1, amount: .fetch(:btc_amount, 0.001) } get(args) end |