buttercoin 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 37d4b26bd20a48864072e98700ed55f99e47e0b2
4
+ data.tar.gz: 375dd0952b314fab656284327519509f63642667
5
+ SHA512:
6
+ metadata.gz: 7b38089791aa009e24142438011d7f48bd7ab3ca716fd173f5e0e05bd9348065eef5956cd9aea21068b5313dac68fcd83d3d9b91d84f2756476013ee0d080d5b
7
+ data.tar.gz: 91bfdeb55d7806faf77ecb1efc8a52cd3b32ed2c2d2de1ef231f114414a0e1519a8c1c81f4abcc635b55e089dd03ee72f49455560248762338178b8f7a70f93f
@@ -0,0 +1,7 @@
1
+ *.bundle
2
+ tmp
3
+ .env
4
+ log
5
+ *.gem
6
+ coverage
7
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - jruby-19mode
7
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Digital Currencies Exchange FinTech
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.
@@ -0,0 +1,302 @@
1
+ Buttercoin Ruby SDK Gem Library
2
+ ===================
3
+ Easy integration with the Buttercoin Trading Platform through our API.
4
+
5
+ Installation
6
+ --------------------------
7
+ Add to your Gemfile:
8
+
9
+ gem 'buttercoin'
10
+
11
+ or install from Rubygems:
12
+
13
+ gem install buttercoin
14
+
15
+ Usage
16
+ -----
17
+
18
+ When you first create a new `Buttercoin::Client` instance you can pass `:public_key`, `:private_key`, and `:mode` as configuration settings. These are optional and can be later specified through Setter methods.
19
+
20
+ For authenticated API Resources, the `:public_key` and `:secret_key` are required and can also be passed to the factory method in the configuration array. The `mode` configuration setting defaults to `'production'`.
21
+
22
+ For a list of required and available parameters as well as code samples for the different API Endpoints, please consult the Buttercoin
23
+ [API Reference Docs](https://developer.buttercoin.com).
24
+
25
+ #### Set Keys via the Environment
26
+
27
+ In order to keep sensitive data out of your codebase, we recommend you use environment variables to set keys. If you're using [foreman](http://ddollar.github.com/foreman/), add this to your `.env` file:
28
+
29
+ BUTTERCOIN_PUBLIC_KEY=5ti8pqwejqfcla4se1d7whydryoso5z8
30
+ BUTTERCOIN_SECRET_KEY=JCfcasdfinmKtdHgIlwXi3SEMJoCf4Bg
31
+ BUTTERCOIN_MODE=staging
32
+
33
+ You can also create a script to export the variables before you start your server.
34
+
35
+ To deploy on Heroku, see [this example](https://devcenter.heroku.com/articles/config-vars).
36
+
37
+ #### Configuring the Client
38
+
39
+ Create a unique Buttercoin Webservice Client as follows:
40
+
41
+ Setting | Property Name | Description
42
+ --- | --- | ---
43
+ Public Key | `:public_key` | Your Buttercoin API Public Key
44
+ Secret Key | `:secret_key` | Your Buttercoin API Secret Key
45
+ Mode | `:mode` | Your development environment (default: `'production'`, set to `'staging'` to test with testnet bitcoins)
46
+
47
+ ###### Example
48
+ ```ruby
49
+ client = Buttercoin::Client.new(:public_key => '5ti8pqwejqfcla4se1d7whydryoso5z8',
50
+ :secret_key => 'JCfcasdfinmKtdHgIlwXi3SEMJoCf4Bg',
51
+ :mode => 'staging')
52
+ ```
53
+
54
+ #### Configuration can be updated to reuse the same Client:
55
+ You can reconfigure the Buttercoin Client configuration options through available getters and setters. You can get and set the following options:
56
+ `:public_key`, `:private_key` & `:mode`
57
+
58
+ ###### Example
59
+ ```ruby
60
+ client.secret_key;
61
+ client.secret_key = '<new_secret_key>'
62
+ ```
63
+
64
+ **Tips**
65
+
66
+ A note on the `timestamp` param sent to all client methods:
67
+ This param must always be increasing, and within 5 minutes of Buttercoin server times (GMT). This is to prevent replay attacks on your data.
68
+
69
+ Before every call, get a new timestamp. (You need only set the timezone once)
70
+
71
+ ```ruby
72
+ timestamp = ((Time.now.to_f * 1e3).round).to_i
73
+ client.get_key(timestamp)
74
+ ```
75
+
76
+ Additionally, for convenience, if you don't include the timestamp parameter, it will default to the current timestamp.
77
+
78
+ ```ruby
79
+ client.get_key()
80
+ ```
81
+
82
+ ### Get Data
83
+
84
+ ###### Unauthenticated
85
+
86
+ **Get Order Book**
87
+ Return a `Hashie::Mash` of current orders in the Buttercoin order book
88
+
89
+ ```ruby
90
+ client.get_order_book()
91
+ ```
92
+
93
+ **Get Ticker**
94
+ Return the current bid, ask, and last sell prices on the Buttercoin platform
95
+
96
+ ```ruby
97
+ client.get_ticker()
98
+ ```
99
+
100
+ ###### Authenticated
101
+
102
+ **Key Permissions**
103
+ Returns `Hashie::Mash` of permissions associated with this key
104
+
105
+ ```ruby
106
+ client.get_key(timestamp)
107
+ ```
108
+
109
+ **Balances**
110
+ Returns `Hashie::Mash` of balances for this account
111
+
112
+ ```ruby
113
+ client.get_balances(timestamp)
114
+ ```
115
+
116
+ **Deposit Address**
117
+ Returns bitcoin address `string` to deposit your funds into the Buttercoin platform
118
+
119
+ ```ruby
120
+ client.get_deposit_address(timestamp)
121
+ ```
122
+
123
+ **Get Orders**
124
+ Returns `Hashie::Mash` containing information about buy and sell orders
125
+
126
+ Valid params include (must be added to array in this order)
127
+
128
+ Name | Param | Description
129
+ --- | --- | ---
130
+ Status | `status` | enum: `['opened', 'partial-filled', 'filled', 'canceled']`
131
+ Side | `side` | enum: `['buy', 'sell']`
132
+ Order Type | `orderType` | enum: `['market', 'limit']`
133
+ Date Min | `dateMin` | format: ISO-8601, e.g. `'2014-05-06T13:15:30Z'`
134
+ Date Max | `dateMax` | format: ISO-8601, e.g. `'2014-05-06T13:15:30Z'`
135
+
136
+ ```ruby
137
+ // query for multiple orders
138
+ order_params = [ "status" => "canceled", "side" => "sell" ]
139
+
140
+ client.get_orders(orderParams, timestamp)
141
+
142
+ // single order by id
143
+ order_id = '<order_id>'
144
+
145
+ client.get_order_by_id(order_id, timestamp)
146
+
147
+ // single order by url
148
+ url = 'https://api.buttercoin.com/v1/orders/{order_id}'
149
+
150
+ client.get_order_by_url(url, timestamp)
151
+ ```
152
+
153
+ **Get Transaction**
154
+ Returns `Hashie::Mash` containing information about deposit and withdraw action
155
+
156
+ Valid params include (must be added to array in this order):
157
+
158
+ Name | Param | Description
159
+ --- | --- | ---
160
+ Status | `status` | enum: `['pending', 'processing', 'funded', 'canceled', 'failed']`
161
+ Transaction Type | `transactionType` | enum: `['deposit', 'withdrawal']`
162
+ Date Min | `dateMin` | format: ISO-8601, e.g. `'2014-05-06T13:15:30Z'`
163
+ Date Max | `dateMax` | format: ISO-8601, e.g. `'2014-05-06T13:15:30Z'`
164
+
165
+ ```ruby
166
+ // query for multiple transactions
167
+ trxn_params = [ "status" => "funded", "transactionType" => "deposit" ]
168
+
169
+ client.get_transactions(trxn_params, timestamp)
170
+
171
+ trxn_id = '53a22ce164f23e7301a4fee5';
172
+
173
+ client.get_transaction_by_id(trxn_id, timestamp)
174
+
175
+ // single transaction by url
176
+ url = 'https://api.buttercoin.com/v1/orders/{order_id}'
177
+
178
+ client.get_transaction_by_url(url, timestamp)
179
+ ```
180
+
181
+ ### Create New Actions
182
+
183
+ **Create Order**
184
+
185
+ Valid order params include:
186
+
187
+ Name | Param | Description
188
+ --- | --- | ---
189
+ Instrument | `instrument` | enum: `['BTC_USD, USD_BTC']`
190
+ Side | `side` | enum: `['buy', 'sell']`, required `true`
191
+ Order Type | `orderType` | enum: `['limit', 'market']`, required `true`
192
+ Price | `price` | `string`, required `false`
193
+ Quantity | `quantity` | `string`, required `false`
194
+
195
+ ```ruby
196
+ // create a hash with the following params
197
+ order = {
198
+ :instrument => "BTC_USD",
199
+ :side => "buy",
200
+ :orderType => "limit",
201
+ :price => "700.00"
202
+ :quantity => "5"
203
+ }
204
+
205
+ client.create_order(order, timestamp)
206
+ ```
207
+
208
+ **Create Transaction**
209
+
210
+ Deposit transaction params include:
211
+
212
+ Name | Param | Description
213
+ --- | --- | ---
214
+ Method | `method` | enum: `['wire']`, required `true`
215
+ Currency | `currency` | enum: `['USD']`, required `true`
216
+ Amount | `amount` | `string`, required `true`
217
+
218
+ ```ruby
219
+ // create deposit
220
+ trxn = {
221
+ :method => "wire",
222
+ :currency => "USD",
223
+ :amount => "5002"
224
+ }
225
+
226
+ client.create_deposit(trxn, timestamp)
227
+ ```
228
+
229
+ Withdrawal transaction params include:
230
+
231
+ Name | Param | Description
232
+ --- | --- | ---
233
+ Method | `method` | enum: `['check']`, required `true`
234
+ Currency | `currency` | enum: `['USD']`, required `true`
235
+ Amount | `amount` | `string`, required `true`
236
+
237
+ ```ruby
238
+ // create withdrawal
239
+ trxn = {
240
+ :method => "check",
241
+ :currency => "USD",
242
+ :amount => "900.23"
243
+ }
244
+
245
+ client.create_withdrawal(trxn, timestamp)
246
+ ```
247
+ Send bitcoin transaction params include:
248
+
249
+ Name | Param | Description
250
+ --- | --- | ---
251
+ Currency | `currency` | `['USD']`, required `true`
252
+ Amount | `amount` | `string`, required `true`
253
+ Destination | `destination` | address to which to send currency `string`, required `true`
254
+
255
+ ```ruby
256
+ // send bitcoins to an address
257
+ trxn = {
258
+ :currency => "BTC",
259
+ :amount => "100.231231",
260
+ :destination => "<bitcoin_address>"
261
+ }
262
+
263
+ client.send_bitcoins(trxn, timestamp)
264
+ ```
265
+
266
+
267
+ ### Cancel Actions
268
+
269
+ All successful cancel calls to the API return a response status of `204` with a human readable success message
270
+
271
+ **Cancel Order**
272
+ Cancel a pending buy or sell order
273
+
274
+ ```ruby
275
+ client.cancel_order(order_id, timestamp)
276
+ ```
277
+
278
+ **Cancel Transaction**
279
+ Cancel a pending deposit or withdraw action
280
+
281
+ ```ruby
282
+ client.cancel_transaction(trxn_id, timestamp)
283
+ ```
284
+
285
+ ## Further Reading
286
+
287
+ [Buttercoin - Website](https://www.buttercoin.com)
288
+ [Buttercoin API Docs](https://developer.buttercoin.com)
289
+
290
+ ## Contributing
291
+
292
+ This is an open source project and we love involvement from the community! Hit us up with pull requests and issues.
293
+
294
+ The aim is to take your great ideas and make everyone's experience using Buttercoin even more powerful. The more contributions the better!
295
+
296
+ ## Release History
297
+
298
+ ### 0.0.1
299
+
300
+ - First release.
301
+
302
+ ## License
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run Rspec unit tests"
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.pattern = "spec/buttercoin/**/*_spec.rb"
7
+ end
8
+
9
+ task :default => :spec
10
+ task :test => [:spec]
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'buttercoin/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "buttercoin"
8
+ gem.version = Buttercoin::VERSION
9
+ gem.authors = ["Kevin Adams"]
10
+ gem.email = ["kevin@buttercoin.com"]
11
+ gem.description = ["Ruby Gem to connect to the Buttercoin API"]
12
+ gem.summary = ["Buttercoin API Ruby SDK"]
13
+ gem.homepage = "https://developer.buttercoin.com/"
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency "simplecov", "~> 0.9.0", ">= 0.9.0"
22
+ gem.add_development_dependency "fakeweb", "~> 1.3", ">= 1.3"
23
+
24
+ gem.add_dependency "httparty", "~> 0.13.1", ">= 0.13.1"
25
+ gem.add_dependency "hashie", "~> 3.2.0", ">= 3.2.0"
26
+ end
@@ -0,0 +1,78 @@
1
+ require "forwardable"
2
+ require "logger"
3
+ require "json"
4
+ require "buttercoin/client"
5
+
6
+ module Buttercoin
7
+ class Error < RuntimeError
8
+ attr_accessor :original_error
9
+ def initialize(message, _original_error=nil)
10
+ self.original_error = _original_error
11
+ super(message)
12
+ end
13
+
14
+ def to_s
15
+ "Buttercoin Exception: #{super}"
16
+ end
17
+ end
18
+
19
+ class ConfigurationError < Error; end
20
+ class HttpError < Error; end
21
+ class BadRequestError < HttpError; end
22
+ class AuthenticationError < HttpError; end
23
+ class NotFoundError < HttpError; end
24
+
25
+ class << self
26
+ extend Forwardable
27
+
28
+ def_delegators :default_client,
29
+ :public_key, :public_key=,
30
+ :secret_key, :secret_key=,
31
+ :mode, :mode=
32
+
33
+ def_delegators :default_client,
34
+ :get_ticker,
35
+ :get_order_book
36
+
37
+ def_delegators :default_client,
38
+ :get_key,
39
+ :get_balances,
40
+ :get_deposit_address
41
+
42
+ def_delegators :default_client,
43
+ :get_order_by_url,
44
+ :get_order_by_id,
45
+ :get_orders,
46
+ :create_order,
47
+ :cancel_order
48
+
49
+ def_delegators :default_client,
50
+ :get_transaction,
51
+ :get_transaction_by_id,
52
+ :get_transactions,
53
+ :create_deposit,
54
+ :create_withdrawal,
55
+ :send_bitcoin,
56
+ :cancel_transaction
57
+
58
+ attr_writer :logger
59
+
60
+ def logger
61
+ @logger ||= lambda {
62
+ logger = Logger.new($stdout)
63
+ logger.level = Logger::INFO
64
+ logger
65
+ }.call
66
+ end
67
+
68
+ private
69
+
70
+ def default_client
71
+ @default_client ||= Buttercoin::Client.new(
72
+ :public_key => ENV['BUTTERCOIN_PUBLIC_KEY'],
73
+ :secret_key => ENV['BUTTERCOIN_SECRET_KEY'],
74
+ :mode => ENV['BUTTERCOIN_MODE'],
75
+ )
76
+ end
77
+ end
78
+ end