cexio 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +27 -18
  2. data/cexio.gemspec +1 -1
  3. data/lib/cexio.rb +15 -10
  4. data/lib/cexio/version.rb +1 -1
  5. metadata +3 -2
data/README.md CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
24
24
 
25
25
  ###2. Add "require 'cexio'")
26
26
 
27
- ###3. Create class
27
+ ###3. Create class
28
28
  ```ruby
29
29
  api = CEX::API(username, api_key, api_secret)
30
30
  ```
@@ -39,12 +39,12 @@ api_secret - your API secret code
39
39
  ```
40
40
  1. couple = ("GHS\BTC" | "BF1\BTC") currency pair
41
41
  2. since = integer return trades with tid >= since
42
- 3. order_id = integer
42
+ 3. order_id = integer
43
43
  4. ptype = ("sell" | "buy") type of order
44
- 5. amount = float
44
+ 5. amount = float
45
45
  6. price = float
46
46
  ```
47
-
47
+
48
48
  ####b) API methods
49
49
  ```
50
50
  1. ticker(couple = 'GHS/BTC') - get ticker
@@ -55,9 +55,9 @@ api_secret - your API secret code
55
55
  6. cancel_order(order_id) - cancel order №order_id
56
56
  7. place_order(ptype = 'buy', amount = 1, price = 1, couple = 'GHS/BTC') - create order
57
57
  ```
58
-
58
+
59
59
  ####c) Full API documentation: https://cex.io/api
60
-
60
+
61
61
  ###5. Examples
62
62
 
63
63
  ####Connect and get balance:
@@ -71,15 +71,15 @@ puts cex.balance
71
71
 
72
72
  ```
73
73
  ```json
74
- {'timestamp': '1383379054', 'BTC': {'available': '0.04614310', 'orders': '0.00170000'}, 'GHS': {'available': '0.02000000'}}
74
+ {"timestamp": "1383379054", "BTC": {"available": "0.04614310", "orders": "0.00170000"}, "GHS": {"available": "0.02000000"}}
75
75
  ```
76
76
 
77
77
  ####Get balance:
78
- ```ruby
78
+ ```ruby
79
79
  puts cex.balance
80
80
  ```
81
81
  ```json
82
- {'timestamp': '1383379054', 'BTC': {'available': '0.04614310', 'orders': '0.00170000'}, 'GHS': {'available': '0.02000000'}}
82
+ {"timestamp": "1383379054", "BTC": {"available": "0.04614310", "orders": "0.00170000"}, "GHS": {"available": "0.02000000"}}
83
83
  ```
84
84
 
85
85
  ####Get API ticker:
@@ -87,39 +87,48 @@ puts cex.balance
87
87
  puts cex.ticker('GHS/BTC')
88
88
  ```
89
89
  ```json
90
- {u'volume': '7154.78339022', 'last': '0.1078', 'timestamp': '1383379041', 'bid': '0.10778', 'high': '0.10799999', 'low': '0.10670076', 'ask': '0.10780000000000001'}
90
+ {"volume": "7154.78339022", "last": "0.1078", "timestamp": "1383379041", "bid": "0.10778", "high": "0.10799999", "low": "0.10670076", "ask": "0.10780000000000001"}
91
91
  ```
92
92
 
93
93
  ####Get order book:
94
94
  ```ruby
95
- puts cex.order_book('BF1/BTC')
95
+ puts cex.order_book("BF1/BTC")
96
96
  ```
97
97
  ```json
98
- {'timestamp': '1383378967', 'bids': [['1.7', '0.30100000'], ['1.67', '0.00011000'], ['0.8', '0.02070000'], ['0.1002', '0.27748002'], ['0.1', '0.10000000'], ['0.011', '0.30500000'], ['0.009', '1.00000000'], ['0.00171', '0.00100000'], ['0.0012', '1.00000000'], ['0.00116819', '0.50000000'], ['0.001002', '33.00000000'], ['0.001001', '53.00000000'], ['0.001', '3.00000000'], ['0.00097626', '36.00000000'], ['0.0006', '85.00000000'], ['0.00058409', '0.50000000'], ['0.0004889', '0.06823960'], ['0.0003', '1.00000000'], ['0.00029204', '0.90000000'], ['0.0001', '101.00000000']], 'asks': []}
98
+ {"timestamp": "1383378967", "bids": [["1.7", "0.30100000"], ["1.67", "0.00011000"], ["0.8", "0.02070000"], ["0.1002", "0.27748002"], ["0.1", "0.10000000"], ["0.011", "0.30500000"], ["0.009", "1.00000000"], ["0.00171", "0.00100000"], ["0.0012", "1.00000000"], ["0.00116819", "0.50000000"], ["0.001002", "33.00000000"], ["0.001001", "53.00000000"], ["0.001", "3.00000000"], ["0.00097626", "36.00000000"], ["0.0006", "85.00000000"], ["0.00058409", "0.50000000"], ["0.0004889", "0.06823960"], ["0.0003", "1.00000000"], ["0.00029204", "0.90000000"], ["0.0001", "101.00000000"]], "asks": []}
99
99
  ```
100
100
 
101
+ ####Trade history:
102
+ ```ruby
103
+ puts cex.trade_history(1,'BTC/GHS')
104
+ ```
105
+ ```json
106
+ [{"amount": "0.00000010", "price": "0.00849979", "date": "1398221957", "tid": 3628072}, {"amount": "0.00000010", "price": "0.00849979", "date": "1398221957", "tid": 3628072}]
107
+ ```
108
+ Note: The first parameter is the `since` and is not optional, you will get a 5xx if you do not include it.
101
109
  ####Get your current active orders:
102
110
  ```ruby
103
- puts cex.current_orders('BF1/BTC')
111
+ puts cex.current_orders("BF1/BTC")
104
112
  ```
105
113
  ```json
106
- [{'price': '1.7', 'amount': '0.00100000', 'time': '1383378514737', 'type': 'buy', 'id': '6219104', 'pending': '0.00100000'}]
114
+ [{"price": "1.7", "amount": "0.00100000", "time": "1383378514737", "type": "buy", "id": "6219104", "pending": "0.00100000"}]
107
115
  ```
116
+ Note: you can use either `current_orders` or `open_orders`.
108
117
 
109
118
  ####Place new order:
110
119
  ```ruby
111
- puts cex.place_order('buy', 0.001, 1.7, 'BF1/BTC')
120
+ puts cex.place_order("buy", 0.001, 1.7, "BF1/BTC")
112
121
  ```
113
122
  ```json
114
- {'price': '1.7', 'amount': '0.00100000', 'time': 1383378987622, 'type': 'buy', 'id': '6219145', 'pending': '0.00100000'}
123
+ {"price": "1.7", "amount": "0.00100000", "time": 1383378987622, "type": "buy", "id": "6219145", "pending": "0.00100000"}
115
124
  ```
116
125
 
117
126
  ####Place another order (GHS/BTC):
118
127
  ```ruby
119
- puts cex.place_order('buy', 0.01, 0.10789, 'GHS/BTC')
128
+ puts cex.place_order("buy", 0.01, 0.10789, "GHS/BTC")
120
129
  ```
121
130
  ```json
122
- {'price': '0.10789', 'amount': '0.01000000', 'time': 1383379024072, 'type': 'buy', 'id': '6219150', 'pending': '0.00000000'}
131
+ {"price": "0.10789", "amount": "0.01000000", "time": 1383379024072, "type": "buy", "id": "6219150", "pending": "0.00000000"}
123
132
  ```
124
133
 
125
134
  ####Cancel order:
data/cexio.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'cexio/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "cexio"
8
8
  spec.version = Cexio::VERSION
9
- spec.authors = ["t0pep0"]
9
+ spec.authors = ["t0pep0","fernandohur"]
10
10
  spec.email = ["t0pep0.gentoo@gmail.com"]
11
11
  spec.description = "Gem for acsess to api cex.io"
12
12
  spec.summary = "Cex.io api library"
data/lib/cexio.rb CHANGED
@@ -9,6 +9,7 @@ require "addressable/uri"
9
9
 
10
10
  module CEX
11
11
 
12
+
12
13
  class API
13
14
  attr_accessor :api_key, :api_secret, :username, :nonce_v
14
15
 
@@ -18,15 +19,21 @@ class API
18
19
  self.api_secret = api_secret
19
20
  end
20
21
 
21
- def api_call(method, param = {}, priv = false, couple = '')
22
- url = 'https://cex.io/api/'+method+'/'
23
- url = url + couple + '/' if couple != ''
22
+ def api_call(method, param = {}, priv = false, action = '', is_json = true)
23
+ url = "https://cex.io/api/#{ method }/#{ action }"
24
24
  if priv
25
25
  self.nonce
26
26
  param.merge!(:key => self.api_key, :signature => self.signature.to_s, :nonce => self.nonce_v)
27
27
  end
28
28
  answer = self.post(url, param)
29
- JSON.parse(answer)
29
+
30
+ # unfortunately, the API does not always respond with JSON, so we must only
31
+ # parse as JSON if is_json is true.
32
+ if is_json
33
+ JSON.parse(answer)
34
+ else
35
+ answer
36
+ end
30
37
  end
31
38
 
32
39
  def ticker(couple = 'GHS/BTC')
@@ -50,7 +57,7 @@ class API
50
57
  end
51
58
 
52
59
  def cancel_order(order_id)
53
- self.api_call('cancel_order', {:id => order_id.to_s}, true)
60
+ self.api_call('cancel_order', {:id => order_id.to_s}, true, '',false)
54
61
  end
55
62
 
56
63
  def place_order(ptype = 'buy', amount = 1, price =1, couple = 'GHS/BTC')
@@ -58,17 +65,15 @@ class API
58
65
  end
59
66
 
60
67
  def hashrate
61
- self.api_call('ghash.io/hashrate', {}, true)
68
+ self.api_call('ghash.io', {}, true, 'hashrate')
62
69
  end
63
70
 
64
71
  def workers_hashrate
65
- self.api_call('ghash.io/workers', {}, true)
72
+ self.api_call('ghash.io', {}, true, 'workers')
66
73
  end
67
74
 
68
-
69
-
70
75
  def nonce
71
- self.nonce_v = Time.now.to_i.to_s
76
+ self.nonce_v = (Time.now.to_f * 1000000).to_i.to_s
72
77
  end
73
78
 
74
79
  def signature
data/lib/cexio/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cexio
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cexio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - t0pep0
9
+ - fernandohur
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-02-03 00:00:00.000000000 Z
13
+ date: 2014-05-05 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: bundler