quadrigacx 0.10.1 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -30
  3. data/Gemfile.lock +4 -3
  4. data/LICENSE.txt +22 -0
  5. data/README.md +144 -9
  6. data/Rakefile +2 -1
  7. data/lib/quadrigacx.rb +11 -28
  8. data/lib/quadrigacx/client.rb +6 -6
  9. data/lib/quadrigacx/client/private.rb +18 -9
  10. data/lib/quadrigacx/client/public.rb +2 -2
  11. data/lib/quadrigacx/request.rb +38 -36
  12. data/lib/quadrigacx/version.rb +1 -3
  13. data/quadrigacx.gemspec +27 -24
  14. data/spec/client_spec.rb +125 -114
  15. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_balance/returns_all_account_balances.yml +56 -0
  16. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_cancel/cancels_an_order.yml +196 -0
  17. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_limit_buy/errors/throws_an_error_when_exceeding_available_balance.yml +440 -0
  18. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_limit_buy/errors/throws_an_error_when_exceeding_balance.yml +440 -0
  19. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_limit_buy/errors/throws_an_error_when_no_price_is_provided.yml +386 -0
  20. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_limit_buy/errors/throws_an_error_when_the_amount_is_too_small.yml +440 -0
  21. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_limit_buy/places_a_USD_limit_buy_order.yml +385 -0
  22. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_limit_buy/places_a_limit_buy_order.yml +338 -0
  23. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_limit_buy/places_a_limit_buy_order_cad.yml +384 -0
  24. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_limit_sell/errors/throws_an_error_when_no_price_is_provided.yml +387 -0
  25. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_limit_sell/places_a_USD_limit_sell_order.yml +385 -0
  26. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_limit_sell/places_a_limit_sell_order.yml +385 -0
  27. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_market_buy/places_a_USD_market_buy_order.yml +107 -0
  28. data/spec/fixtures/vcr_cassettes/{limit_buy_below_minimum_order_value.yml → QuadrigaCX_Client/private/_market_buy/places_a_market_buy_order.yml} +11 -11
  29. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_market_sell/places_a_USD_market_sell_order.yml +107 -0
  30. data/spec/fixtures/vcr_cassettes/{limit_buy_exceeds_available_balance.yml → QuadrigaCX_Client/private/_market_sell/places_a_market_sell_order.yml} +12 -13
  31. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_open_orders/lists_USD_open_orders.yml +495 -0
  32. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_open_orders/lists_open_orders.yml +690 -0
  33. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_user_transactions/returns_a_list_of_USD_transactions.yml +391 -0
  34. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_user_transactions/returns_a_list_of_limited_transactions.yml +64 -0
  35. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_user_transactions/returns_a_list_of_transactions.yml +197 -0
  36. data/spec/fixtures/vcr_cassettes/{limit_buy_above_maximum_order_value.yml → QuadrigaCX_Client/private/_wallet_address/returns_a_wallet_address.yml} +12 -13
  37. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/private/_withdraw/withdraws_bitcoins.yml +54 -0
  38. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/public/_order_book/returns_a_USD_order_book.yml +156 -0
  39. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/public/_order_book/returns_a_list_of_all_open_orders.yml +91 -0
  40. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/public/_order_book/when_using_the_group_option/does_not_group_same_price_orders.yml +286 -0
  41. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/public/_order_book/when_using_the_ungrouped_option/does_not_group_same_price_orders.yml +286 -0
  42. data/spec/fixtures/vcr_cassettes/{ticker.yml → QuadrigaCX_Client/public/_ticker/returns_trading_information.yml} +11 -11
  43. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/public/_transactions/returns_a_list_of_USD_trades.yml +162 -0
  44. data/spec/fixtures/vcr_cassettes/QuadrigaCX_Client/public/_transactions/returns_a_list_of_recent_trades.yml +57 -0
  45. data/spec/spec_helper.rb +8 -1
  46. metadata +99 -67
  47. data/spec/fixtures/vcr_cassettes/balance.yml +0 -55
  48. data/spec/fixtures/vcr_cassettes/cancel.yml +0 -189
  49. data/spec/fixtures/vcr_cassettes/limit_buy.yml +0 -140
  50. data/spec/fixtures/vcr_cassettes/limit_buy_cancel_order.yml +0 -49
  51. data/spec/fixtures/vcr_cassettes/limit_sell_cancel_order.yml +0 -49
  52. data/spec/fixtures/vcr_cassettes/market_buy.yml +0 -53
  53. data/spec/fixtures/vcr_cassettes/open_orders.yml +0 -55
  54. data/spec/fixtures/vcr_cassettes/order_book.yml +0 -123
  55. data/spec/fixtures/vcr_cassettes/order_book_ungrouped.yml +0 -127
  56. data/spec/fixtures/vcr_cassettes/order_book_ungrouped_cancel_order.yml +0 -49
  57. data/spec/fixtures/vcr_cassettes/safe_limit_buy.yml +0 -176
  58. data/spec/fixtures/vcr_cassettes/safe_limit_sell.yml +0 -176
  59. data/spec/fixtures/vcr_cassettes/transactions.yml +0 -55
  60. data/spec/fixtures/vcr_cassettes/user_transactions.yml +0 -208
  61. data/spec/fixtures/vcr_cassettes/user_transactions_limited.yml +0 -57
  62. data/spec/fixtures/vcr_cassettes/wallet_address.yml +0 -49
  63. data/spec/fixtures/vcr_cassettes/withdraw.yml +0 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87dc9a8f727cc5f6e4749da2d2249eb4b9a971f7
4
- data.tar.gz: aa49fdb5c2851d458aacd553d69d80d13335278f
3
+ metadata.gz: 565de7d0bcdfd3b98d27fbd90bf391a4200a5fb0
4
+ data.tar.gz: d94ceaf268848220b477e90fe08f989ad35be137
5
5
  SHA512:
6
- metadata.gz: 30d28d85cce4ff896ef52e42ac09598fb1066f7506dc40814a49b4611b6ad516b871a75df948c543801131a15e5b54ae46857415a842a986a2ab58c868cd6501
7
- data.tar.gz: d4f22e10b82b5f0d0dc4c71cad5b0103bd3928cab809d4f22e782de47c86847cac3cef07934f82a38267defcad96d73f343d24c5e4f0b841957d82bf963e7b3d
6
+ metadata.gz: ddd9327a61471d74a17767a8537f3877f39913990e54076aee5bedbdfef6ebb9d97930670667c9d9cca9f3152e744ccc27e67c2dded54859ced9996d840d84c9
7
+ data.tar.gz: ed0d5fa33d2751ccb443caa5a66f82373d94a9a29a722e0a9d263d2c91fbfed8455c2cd031f54dd9295193e8ea9bf1079afd7d7f017d792074b87966a477fdc3
data/.gitignore CHANGED
@@ -1,36 +1,16 @@
1
- *.gem
2
- *.rbc
3
- /.config
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
4
5
  /coverage/
5
- /InstalledFiles
6
+ /doc/
6
7
  /pkg/
7
8
  /spec/reports/
8
- /test/tmp/
9
- /test/version_tmp/
10
9
  /tmp/
11
-
12
- ## Specific to RubyMotion:
13
- .dat*
14
- .repl_history
15
- build/
16
-
17
- ## Documentation cache and generated files:
18
- /.yardoc/
19
- /_yardoc/
20
- /doc/
21
- /rdoc/
22
-
23
- ## Environment normalisation:
24
- /.bundle/
25
- /lib/bundler/man/
26
-
27
- # for a library or gem, you might want to ignore these files since the code is
28
- # intended to run in multiple environments; otherwise, check them in:
29
- # Gemfile.lock
30
- # .ruby-version
31
- # .ruby-gemset
32
-
33
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
- .rvmrc
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
35
15
 
36
16
  .env
data/Gemfile.lock CHANGED
@@ -1,8 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- quadrigacx (0.9.0)
5
- hashie (~> 3.3)
4
+ quadrigacx (0.12.2)
6
5
  json (~> 1.8)
7
6
  rest-client (~> 1.7)
8
7
 
@@ -20,12 +19,12 @@ GEM
20
19
  unf (>= 0.0.5, < 1.0.0)
21
20
  dotenv (1.0.2)
22
21
  gem-release (0.7.3)
23
- hashie (3.4.2)
24
22
  http-cookie (1.0.2)
25
23
  domain_name (~> 0.5)
26
24
  json (1.8.3)
27
25
  mime-types (2.6.1)
28
26
  netrc (0.10.3)
27
+ rake (10.4.2)
29
28
  rest-client (1.8.0)
30
29
  http-cookie (>= 1.0.2, < 2.0)
31
30
  mime-types (>= 1.16, < 3.0)
@@ -55,10 +54,12 @@ PLATFORMS
55
54
  ruby
56
55
 
57
56
  DEPENDENCIES
57
+ bundler (~> 1.7)
58
58
  byebug (~> 5.0)
59
59
  dotenv (~> 1.0)
60
60
  gem-release (~> 0.7)
61
61
  quadrigacx!
62
+ rake (~> 10.0)
62
63
  rspec (~> 3.1)
63
64
  vcr (~> 2.9)
64
65
  webmock (~> 1.20)
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Maros Hluska
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,15 +1,150 @@
1
- # QuadrigaCX
1
+ # Quadrigacx
2
2
 
3
- Ruby wrapper for the QuadrigaCX API
3
+ Ruby wrapper for the QuadrigaCX API.
4
4
 
5
- `gem install quadrigacx`
5
+ ## Installation
6
6
 
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'quadrigacx'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install quadrigacx
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'quadrigacx'
25
+
26
+ QuadrigaCX.configure do |config|
27
+ config.client_id = 'your-client-id'
28
+ config.api_key = 'your-api-key'
29
+ config.api_secret = 'your-api-secret'
30
+ end
31
+
32
+ client = QuadrigaCX::Client.new
33
+ ```
34
+
35
+ ### Public Methods
36
+
37
+ #### Ticker
38
+
39
+ Return trading information.
40
+
41
+ ```ruby
42
+ ticker = client.ticker
43
+ ```
44
+
45
+ #### Order Book
46
+
47
+ List all open orders.
48
+
49
+ ```ruby
50
+ order_book = client.order_book
51
+ order_book_ungrouped = client.order_book(group: 0)
52
+ ```
53
+
54
+ #### Transactions
55
+
56
+ Return descending JSON list of recent trades.
57
+
58
+ ```ruby
59
+ transactions = client.transactions
60
+ ```
61
+
62
+ ### Private Methods
63
+
64
+ #### Balance
65
+
66
+ List all account balances.
67
+
68
+ ```ruby
69
+ balance = client.balance
70
+ ```
71
+
72
+ #### Limit Buy
73
+
74
+ Place a limit buy order. Returns JSON describing the order.
75
+
76
+ ```ruby
77
+ order = client.limit_buy(price: 200, amount: 1)
7
78
  ```
8
- client = QuadrigaCX::Client.new(
9
- api_key: 'API_KEY',
10
- api_secret: 'API_SECRET',
11
- client_id: 'CLIENT_ID',
12
- )
13
79
 
14
- puts client.balance
80
+ #### Limit Sell
81
+
82
+ Place a limit sell order. Returns JSON describing the order.
83
+
84
+ ```ruby
85
+ order = client.limit_sell(price: 200, amount: 1)
86
+ ```
87
+
88
+ #### Market Buy
89
+
90
+ Place a market order. Returns JSON describing the order.
91
+
92
+ ```ruby
93
+ order = client.market_buy(amount: 5.00)
94
+ ```
95
+
96
+ #### Market Sell
97
+
98
+ Place a market order. Returns JSON describing the order.
99
+
100
+ ```ruby
101
+ order = client.market_sell(amount: 0.01)
102
+ ```
103
+
104
+ #### Cancel
105
+
106
+ Cancel an order.
107
+
108
+ ```ruby
109
+ client.cancel(order.id)
110
+ ```
111
+
112
+ #### Withdraw
113
+
114
+ Withdraw bitcoins.
115
+
116
+ ```ruby
117
+ response = client.withdraw(amount: 1, address: '1FAs1ywa3pqS6S5mvypXjCtHAzwCkymNUX')
118
+ ```
119
+
120
+ #### Open Orders
121
+
122
+ Return a JSON list of open orders.
123
+
124
+ ```ruby
125
+ response = client.open_orders
126
+ ```
127
+
128
+ #### Wallet Address
129
+
130
+ Return a bitcoin deposit address.
131
+
132
+ ```ruby
133
+ response = client.wallet_address
134
+ ```
135
+
136
+ #### User Transactions
137
+
138
+ Return a list of user transactions.
139
+
140
+ ```ruby
141
+ response = client.user_transactions
15
142
  ```
143
+
144
+ ## Contributing
145
+
146
+ 1. Fork it ( https://github.com/[my-github-username]/quadrigacx/fork )
147
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
148
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
149
+ 4. Push to the branch (`git push origin my-new-feature`)
150
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1 +1,2 @@
1
- require 'bundler/gem_tasks'
1
+ require "bundler/gem_tasks"
2
+
data/lib/quadrigacx.rb CHANGED
@@ -1,36 +1,19 @@
1
- require 'quadrigacx/request'
2
- require 'quadrigacx/client'
3
- require 'quadrigacx/version'
4
- require 'quadrigacx/error'
5
-
6
1
  module QuadrigaCX
7
- @@options = {}
8
-
9
- # Define a global configuration
10
- #
11
- # options[:api_key]
12
- # options[:api_secret]
13
- #
14
- def self.configure options={}
15
- unless options.kind_of?(Hash)
16
- raise ArgumentError, "Options hash required"
17
- end
2
+ autoload :Error, 'quadrigacx/error'
3
+ autoload :Request, 'quadrigacx/request'
4
+ autoload :Client, 'quadrigacx/client'
5
+ autoload :Version, 'quadrigacx/version'
18
6
 
19
- @@options[:client_id] = options[:client_id]
20
- @@options[:api_key] = options[:api_key]
21
- @@options[:api_secret] = options[:api_secret]
22
- @@options
7
+ class << self
8
+ attr_accessor :configuration
23
9
  end
24
10
 
25
- # Returns global configuration hash
26
- #
27
- def self.configuration
28
- @@options
11
+ def self.configure
12
+ self.configuration ||= Configuration.new
13
+ yield(configuration)
29
14
  end
30
15
 
31
- # Resets the global configuration
32
- #
33
- def self.reset_configuration
34
- @@options = {}
16
+ class Configuration
17
+ attr_accessor :client_id, :api_key, :api_secret
35
18
  end
36
19
  end
@@ -1,11 +1,11 @@
1
- require_relative 'client/public'
2
- require_relative 'client/private'
3
-
4
1
  module QuadrigaCX
2
+ autoload :Public, 'quadrigacx/client/public'
3
+ autoload :Private, 'quadrigacx/client/private'
4
+
5
5
  class Client
6
- include QuadrigaCX::Request
7
- include QuadrigaCX::Public
8
- include QuadrigaCX::Private
6
+ include Request
7
+ include Public
8
+ include Private
9
9
 
10
10
  attr_reader :api_key, :api_secret, :client_id
11
11
 
@@ -1,12 +1,12 @@
1
1
  module QuadrigaCX
2
2
  module Private
3
- # List all account balances
3
+ # List all account balances.
4
4
  #
5
5
  def balance
6
6
  request(:post, '/balance')
7
7
  end
8
8
 
9
- # Places a limit buy order. Returns JSON describing the order
9
+ # Place a limit buy order. Returns JSON describing the order.
10
10
  #
11
11
  # amount - amount of major currency
12
12
  # price - price to buy at
@@ -16,7 +16,7 @@ module QuadrigaCX
16
16
  request(:post, '/buy', params)
17
17
  end
18
18
 
19
- # Places a limit sell order. Returns JSON describing the order
19
+ # Place a limit sell order. Returns JSON describing the order.
20
20
  #
21
21
  # amount - amount of major currency
22
22
  # price - price to sell at
@@ -26,7 +26,7 @@ module QuadrigaCX
26
26
  request(:post, '/sell', params)
27
27
  end
28
28
 
29
- # Places a market order. Returns JSON describing the order
29
+ # Place a market order. Returns JSON describing the order.
30
30
  #
31
31
  # amount - amount of minor currency to spend
32
32
  # book - optional, if not specified, will default to btc_cad
@@ -34,14 +34,22 @@ module QuadrigaCX
34
34
  request(:post, '/buy', params)
35
35
  end
36
36
 
37
- # Cancels an order
37
+ # Place a market order. Returns JSON describing the order.
38
+ #
39
+ # amount - amount of minor currency to spend
40
+ # book - optional, if not specified, will default to btc_cad
41
+ def market_sell params={}
42
+ request(:post, '/sell', params)
43
+ end
44
+
45
+ # Cancel an order.
38
46
  #
39
47
  # id – a 64 characters long hexadecimal string taken from the list of orders
40
48
  def cancel params={}
41
49
  request(:post, '/cancel_order', params)
42
50
  end
43
51
 
44
- # Withdraw bitcoins
52
+ # Withdraw bitcoins.
45
53
  #
46
54
  # amount – The amount to withdraw
47
55
  # address – The bitcoin address we will send the amount to
@@ -49,19 +57,20 @@ module QuadrigaCX
49
57
  request(:post, '/bitcoin_withdrawal', params)
50
58
  end
51
59
 
52
- # Returns a JSON list of open orders
60
+ # Return a JSON list of open orders.
53
61
  #
54
62
  # book - optional, if not specified, will default to btc_cad
55
63
  def open_orders params={}
56
64
  request(:post, '/open_orders', params)
57
65
  end
58
66
 
59
- # Returns a bitcoin deposit address for funding your account
67
+ # Return a bitcoin deposit address.
60
68
  def wallet_address params={}
61
69
  request(:post, '/bitcoin_deposit_address', params)
62
70
  end
63
71
 
64
- # Returns a descending list of user transactions
72
+ # Return a list of user transactions.
73
+ #
65
74
  # offset - optional, skip that many transactions before beginning to return results. Default: 0.
66
75
  # limit - optional, limit result to that many transactions. Default: 100.
67
76
  # sort - optional, sorting by date and time (asc - ascending; desc - descending). Default: desc.
@@ -7,7 +7,7 @@ module QuadrigaCX
7
7
  request(:get, '/ticker', params)
8
8
  end
9
9
 
10
- # List all open orders
10
+ # List all open orders.
11
11
  #
12
12
  # book - optional, book to return orders for. Default btc_cad.
13
13
  # group - optional, group orders with the same price (0 - false; 1 - true). Default: 1.
@@ -15,7 +15,7 @@ module QuadrigaCX
15
15
  request(:get, '/order_book', params)
16
16
  end
17
17
 
18
- # Returns descending JSON list of recent trades
18
+ # Return descending JSON list of recent trades.
19
19
  #
20
20
  # book - optional, book to return orders for (default btc_cad)
21
21
  # time - optional, time frame for transaction export ("minute" - 1 minute, "hour" - 1 hour). Default: hour.