bitstamper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +15 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +5 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +6 -0
  8. data/Gemfile.lock +66 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +39 -0
  11. data/Rakefile +6 -0
  12. data/bin/console +32 -0
  13. data/bin/setup +8 -0
  14. data/bin/websocket +55 -0
  15. data/bitstamper.gemspec +35 -0
  16. data/credentials.yml.example +9 -0
  17. data/lib/.DS_Store +0 -0
  18. data/lib/bitstamper/configuration.rb +41 -0
  19. data/lib/bitstamper/constants.rb +34 -0
  20. data/lib/bitstamper/errors.rb +11 -0
  21. data/lib/bitstamper/extensions/hash.rb +27 -0
  22. data/lib/bitstamper/models/balance.rb +56 -0
  23. data/lib/bitstamper/models/base.rb +11 -0
  24. data/lib/bitstamper/models/deposit.rb +26 -0
  25. data/lib/bitstamper/models/live_trade.rb +41 -0
  26. data/lib/bitstamper/models/order.rb +48 -0
  27. data/lib/bitstamper/models/order_book.rb +28 -0
  28. data/lib/bitstamper/models/ticker.rb +33 -0
  29. data/lib/bitstamper/models/trading_pair.rb +35 -0
  30. data/lib/bitstamper/models/transaction.rb +37 -0
  31. data/lib/bitstamper/models/user_transaction.rb +55 -0
  32. data/lib/bitstamper/models/withdrawal.rb +53 -0
  33. data/lib/bitstamper/rest/client.rb +102 -0
  34. data/lib/bitstamper/rest/errors.rb +39 -0
  35. data/lib/bitstamper/rest/private/balances.rb +18 -0
  36. data/lib/bitstamper/rest/private/deposits.rb +51 -0
  37. data/lib/bitstamper/rest/private/orders.rb +103 -0
  38. data/lib/bitstamper/rest/private/transactions.rb +19 -0
  39. data/lib/bitstamper/rest/private/withdrawals.rb +53 -0
  40. data/lib/bitstamper/rest/public/currencies.rb +14 -0
  41. data/lib/bitstamper/rest/public/order_book.rb +14 -0
  42. data/lib/bitstamper/rest/public/ticker.rb +30 -0
  43. data/lib/bitstamper/rest/public/trading_pairs.rb +14 -0
  44. data/lib/bitstamper/rest/public/transactions.rb +18 -0
  45. data/lib/bitstamper/utilities.rb +61 -0
  46. data/lib/bitstamper/version.rb +3 -0
  47. data/lib/bitstamper/websocket/client.rb +127 -0
  48. data/lib/bitstamper.rb +72 -0
  49. metadata +231 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 940546c32d17d9d2786fbe9c88a6b8581c830acb438bcd24cda1c33ac59cb92e
4
+ data.tar.gz: bd8e5efd83e84a4c96df7623f69d8d69d6044754617dd0e3251065dae3db7a03
5
+ SHA512:
6
+ metadata.gz: 5c78680b19e52019b7430d022bb1fb44c83b6bd9b0642fca768f9489d94824f6287132b8f019c319fafc9b19fe69cbdf90549d8ea9bf8ea87d91514ab3689ef8
7
+ data.tar.gz: 3e1bcad548ac3ee86df0fe6d66cf2137bb743a94b873ae527e6ba9e9df92152d5ad9408fbf396c5e7bcc3b21b36896c9e66098e7834d52a7f6d831d54e012af3
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ credentials.yml
14
+ .ruby-version
15
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sebastian.johnsson@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in bitstamper.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bitstamper (0.1.0)
5
+ faraday (>= 0.13)
6
+ faraday_middleware (>= 0.12.2)
7
+ pusher-client (>= 0.6.2)
8
+ ruby-hmac (>= 0.4.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.5.2)
14
+ public_suffix (>= 2.0.2, < 4.0)
15
+ crack (0.4.3)
16
+ safe_yaml (~> 1.0.0)
17
+ diff-lcs (1.3)
18
+ faraday (0.14.0)
19
+ multipart-post (>= 1.2, < 3)
20
+ faraday_middleware (0.12.2)
21
+ faraday (>= 0.7.4, < 1.0)
22
+ hashdiff (0.3.7)
23
+ json (2.1.0)
24
+ multipart-post (2.0.0)
25
+ public_suffix (3.0.1)
26
+ pusher-client (0.6.2)
27
+ json
28
+ websocket (~> 1.0)
29
+ rake (10.5.0)
30
+ rdoc (6.0.1)
31
+ rspec (3.7.0)
32
+ rspec-core (~> 3.7.0)
33
+ rspec-expectations (~> 3.7.0)
34
+ rspec-mocks (~> 3.7.0)
35
+ rspec-core (3.7.1)
36
+ rspec-support (~> 3.7.0)
37
+ rspec-expectations (3.7.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.7.0)
40
+ rspec-mocks (3.7.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.7.0)
43
+ rspec-support (3.7.0)
44
+ ruby-hmac (0.4.0)
45
+ safe_yaml (1.0.4)
46
+ vcr (4.0.0)
47
+ webmock (3.3.0)
48
+ addressable (>= 2.3.6)
49
+ crack (>= 0.3.2)
50
+ hashdiff
51
+ websocket (1.2.5)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ bitstamper!
58
+ bundler (~> 1.16)
59
+ rake (~> 10.0)
60
+ rdoc (~> 6.0)
61
+ rspec (~> 3.0)
62
+ vcr (~> 4.0)
63
+ webmock (~> 3.1)
64
+
65
+ BUNDLED WITH
66
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Sebastian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Bitstamper Ruby API
2
+
3
+ Ruby client for interacting with Bitstamp. Originally inspired by the bitstamp gem but rewritten from the ground up and also includes additional API endpoints as well as websocket support.
4
+
5
+ Feel free to fork, modify & redistribute under the MIT license.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'bitstamper'
12
+
13
+ ## Create API Key
14
+
15
+ More info at: [https://www.bitstamp.net/article/api-key-implementation/](https://www.bitstamp.net/article/api-key-implementation/)
16
+
17
+ ## Setup
18
+
19
+ ```ruby
20
+ Bitstamper.configure do |config|
21
+ config.key = YOUR_API_KEY
22
+ config.secret = YOUR_API_SECRET
23
+ config.client_id = YOUR_BITSTAMP_USERNAME
24
+ end
25
+ ```
26
+
27
+ If you fail to set your `key` or `secret` or `client_id` a `::Bitstamper::Errors::MissingConfigError`
28
+ will be raised.
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b
34
+ my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
38
+
39
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bitstamper"
5
+ require "yaml"
6
+
7
+ cfg_path = File.join(File.dirname(__FILE__), "../credentials.yml")
8
+
9
+ if ::File.exists?(cfg_path)
10
+ cfg = YAML.load_file(cfg_path).fetch("full_permissions", {})
11
+
12
+ Bitstamper.configure do |config|
13
+ config.key = cfg["key"]
14
+ config.secret = cfg["secret"]
15
+ config.client_id = cfg["client_id"]
16
+
17
+ config.faraday = {
18
+ user_agent: "Bitstamp Ruby",
19
+ verbose: true
20
+ }
21
+ end
22
+ end
23
+
24
+ # You can add fixtures and/or initialization code here to make experimenting
25
+ # with your gem easier. You can also use a different console, if you like.
26
+
27
+ # (If you use this, don't forget to add pry to your Gemfile!)
28
+ # require "pry"
29
+ # Pry.start
30
+
31
+ require "irb"
32
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/websocket ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bitstamper"
5
+
6
+ # Example implementation of websockets
7
+ # Subscribe to channels with subscribe! (product: :btcusd can also be passed to the method to only subscribe to a specific product/trading pair where applicable)
8
+ # Implement your own callbacks to process the incoming data, set the callbacks on the client with client.callbacks[:callback] = lambda
9
+
10
+ class WebsocketWrapper
11
+ def run!
12
+ client = ::Bitstamper::Websocket::Client.new(enable_logging: true)
13
+
14
+ begin
15
+ client.start!
16
+
17
+ client.subscribe!(:live_trades)
18
+ client.subscribe!(:order_book)
19
+ client.subscribe!(:diff_order_book)
20
+ client.subscribe!(:live_orders)
21
+
22
+ client.callbacks[:live_trades] = -> (channel, event, data) { custom_receive(channel, event, data) }
23
+ client.callbacks[:order_book] = -> (channel, event, data) { custom_receive(channel, event, data) }
24
+ client.callbacks[:diff_order_book] = -> (channel, event, data) { custom_receive(channel, event, data) }
25
+
26
+ client.callbacks[:live_orders][:order_created] = -> (channel, event, data) { custom_receive(channel, event, data) }
27
+ client.callbacks[:live_orders][:order_changed] = -> (channel, event, data) { custom_receive(channel, event, data) }
28
+ client.callbacks[:live_orders][:order_deleted] = -> (channel, event, data) { custom_receive(channel, event, data) }
29
+
30
+ client.loop!
31
+ ensure
32
+ client.stop!
33
+ end
34
+ end
35
+
36
+ def custom_receive(channel, event, data)
37
+ puts "\n\nUsing custom callbacks!\n\n"
38
+
39
+ parsed = case channel[:name]
40
+ when /^live_trades/i
41
+ ::Bitstamper::Models::LiveTrade.new(data.symbolize_keys.merge(product: channel[:product]))
42
+ when /^order_book/i
43
+ ::Bitstamper::Models::OrderBook.new(data)
44
+ when /^diff_order_book/i
45
+ ::Bitstamper::Models::OrderBook.new(data)
46
+ when /^live_orders/i
47
+ ::Bitstamper::Models::Order.new(data.merge(event: event))
48
+ end
49
+
50
+ pp parsed
51
+ end
52
+
53
+ end
54
+
55
+ WebsocketWrapper.new.run!
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "bitstamper/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bitstamper"
8
+ spec.version = Bitstamper::VERSION
9
+ spec.authors = ["SebastianJ"]
10
+ spec.email = ["sebastian.johnsson@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby client for Bitstamp's API'}
13
+ spec.description = %q{Rest + Websocket client for interacting with Bitstamp's API'}
14
+ spec.homepage = "https://github.com/SebastianJ/Bitstamper"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "faraday", ">= 0.13"
25
+ spec.add_dependency "faraday_middleware", ">= 0.12.2"
26
+ spec.add_dependency "ruby-hmac", ">= 0.4.0"
27
+ spec.add_dependency "pusher-client", ">= 0.6.2"
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.16"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency "rdoc", "~> 6.0"
33
+ spec.add_development_dependency "vcr", "~> 4.0"
34
+ spec.add_development_dependency "webmock", "~> 3.1"
35
+ end
@@ -0,0 +1,9 @@
1
+ partial_permissions:
2
+ key: "PARTIAL_PERMISSIONS_KEY"
3
+ secret: "PARTIAL_PERMISSIONS_SECRET"
4
+ client_id: "PARTIAL_PERMISSIONS_CLIENT_ID"
5
+
6
+ full_permissions:
7
+ key: "FULL_PERMISSIONS_KEY"
8
+ secret: "FULL_PERMISSIONS_SECRET"
9
+ client_id: "FULL_PERMISSIONS_CLIENT_ID"
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,41 @@
1
+ module Bitstamper
2
+ class Configuration
3
+ attr_accessor :key, :secret, :client_id, :pusher_app_key, :faraday, :products
4
+
5
+ def initialize
6
+ self.key = nil
7
+ self.secret = nil
8
+ self.client_id = nil
9
+
10
+ self.pusher_app_key = "de504dc5763aeef9ff52"
11
+
12
+ self.faraday = {
13
+ adapter: :net_http,
14
+ user_agent: 'Bitstamp Ruby',
15
+ verbose: false
16
+ }
17
+
18
+ self.products = [
19
+ "btceur",
20
+ "eurusd",
21
+ "xrpusd",
22
+ "xrpeur",
23
+ "xrpbtc",
24
+ "ltcusd",
25
+ "ltceur",
26
+ "ltcbtc",
27
+ "ethusd",
28
+ "etheur",
29
+ "ethbtc",
30
+ "bchusd",
31
+ "bcheur",
32
+ "bchbtc"
33
+ ]
34
+ end
35
+
36
+ def verbose_faraday?
37
+ self.faraday.fetch(:verbose, false)
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ module Bitstamper
2
+ module Constants
3
+
4
+ BUY_ORDER = 0
5
+ SELL_ORDER = 1
6
+
7
+ AVAILABLE_CRYPTOS = [
8
+ "btc",
9
+ "eth",
10
+ "xrp",
11
+ "bch",
12
+ "ltc"
13
+ ]
14
+
15
+ TRADEABLE = AVAILABLE_CRYPTOS | ["eur", "usd"]
16
+
17
+ TIME_IN_SECONDS = {
18
+ day: 86400,
19
+ hour: 3600
20
+ }
21
+
22
+ ERRORS = {
23
+ matches: {
24
+ invalid_permissions: "No permission found",
25
+ invalid_order: "Order not found",
26
+ },
27
+
28
+ responses: {
29
+ invalid_permissions: "Not allowed to perform this action - check your API key credentials.",
30
+ }
31
+ }
32
+
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ module Bitstamper
2
+ module Errors
3
+ class Error < StandardError; end;
4
+ class MissingConfigError < Bitstamper::Errors::Error; end;
5
+ class InvalidPermissionsError < Bitstamper::Errors::Error; end;
6
+ class InvalidOrderError < Bitstamper::Errors::Error; end;
7
+ class InvalidAmountError < Bitstamper::Errors::Error; end;
8
+ class InvalidAddressError < Bitstamper::Errors::Error; end;
9
+ class InvalidCurrencyError < Bitstamper::Errors::Error; end;
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ class Hash
2
+
3
+ def symbolize_keys
4
+ transform_keys{ |key| key.to_sym rescue key }
5
+ end
6
+
7
+ def transform_keys
8
+ result = {}
9
+ each_key do |key|
10
+ result[yield(key)] = self[key]
11
+ end
12
+ result
13
+ end
14
+
15
+ def deep_symbolize_keys
16
+ deep_transform_keys{ |key| key.to_sym rescue key }
17
+ end
18
+
19
+ def deep_transform_keys(&block)
20
+ result = {}
21
+ each do |key, value|
22
+ result[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys(&block) : value
23
+ end
24
+ result
25
+ end
26
+
27
+ end
@@ -0,0 +1,56 @@
1
+ module Bitstamper
2
+ module Models
3
+ class Balance
4
+ attr_accessor :currency, :available, :balance, :reserved, :fees
5
+
6
+ def initialize(hash)
7
+ hash.each do |key, value|
8
+ self.send("#{key}=", value) if self.respond_to?(key)
9
+ end
10
+ end
11
+
12
+ def self.parse(hash)
13
+ parsed = []
14
+ groups = {}
15
+
16
+ hash.each do |key, value|
17
+ if key !~ /_fee$/i
18
+ splitted = key.split("_")
19
+
20
+ if splitted.size == 2
21
+ currency = splitted.first
22
+ value_key = splitted.last
23
+
24
+ groups[currency] ||= {}
25
+ groups[currency][value_key] = value&.to_f
26
+ end
27
+ end
28
+ end
29
+
30
+ hash.each do |key, value|
31
+ if key =~ /_fee$/i
32
+ pair = key.split("_")&.first #btceur_fee -> btceur
33
+
34
+ groups.keys.each do |grouped_key|
35
+ if pair =~ /^#{grouped_key}/i
36
+ quote_key = pair.gsub(grouped_key, "")
37
+ groups[grouped_key]["fees"] ||= {}
38
+ groups[grouped_key]["fees"][quote_key] = value&.to_f
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ groups = groups.deep_symbolize_keys
45
+
46
+ groups.each do |key, values|
47
+ values[:currency] = key.to_s.upcase
48
+ parsed << ::Bitstamper::Models::Balance.new(values)
49
+ end
50
+
51
+ return parsed
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,11 @@
1
+ module Bitstamper
2
+ module Models
3
+ class Base
4
+
5
+ def attributes
6
+ Hash[instance_variables.map { |name| [name.to_s.gsub(/^@/, "").to_sym, instance_variable_get(name)] }]
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ module Bitstamper
2
+ module Models
3
+ class Deposit < Base
4
+ attr_accessor :address, :amount, :confirmations
5
+
6
+ MAPPING = {
7
+ "address" => :string,
8
+ "amount" => :float,
9
+ "confirmations" => :integer,
10
+ }
11
+
12
+ def initialize(hash)
13
+ hash.each do |key, value|
14
+ type = ::Bitstamper::Models::Deposit::MAPPING.fetch(key, nil)
15
+ value = value && type ? ::Bitstamper::Utilities::convert_value(value, type) : value
16
+ self.send("#{key}=", value) if self.respond_to?(key)
17
+ end
18
+ end
19
+
20
+ def self.parse(data)
21
+ data&.collect { |item| ::Bitstamper::Models::Deposit.new(item) }
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,41 @@
1
+ module Bitstamper
2
+ module Models
3
+ class LiveTrade
4
+ attr_accessor :id, :buy_order_id, :sell_order_id
5
+ attr_accessor :amount, :amount_str, :price, :price_str
6
+ attr_accessor :epoch, :timestamp
7
+ attr_accessor :type
8
+ attr_accessor :product
9
+
10
+ TYPES = {
11
+ 0 => :buy,
12
+ 1 => :sell
13
+ }
14
+
15
+ MAPPING = {
16
+ id: :string,
17
+ buy_order_id: :string,
18
+ sell_order_id: :string,
19
+ amount: :float,
20
+ amount_str: :string,
21
+ price: :float,
22
+ price_str: :string,
23
+ epoch: :integer,
24
+ timestamp: :time,
25
+ type: :integer,
26
+ product: :string,
27
+ }
28
+
29
+ def initialize(hash)
30
+ hash.each do |key, value|
31
+ type = ::Bitstamper::Models::LiveTrade::MAPPING.fetch(key, nil)
32
+ value = value && type ? ::Bitstamper::Utilities::convert_value(value, type) : value
33
+ self.send("#{key}=", value) if self.respond_to?(key)
34
+ end
35
+
36
+ self.type = TYPES[self.type]
37
+ end
38
+
39
+ end
40
+ end
41
+ end