bitbot-trader 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +7 -0
  6. data/Gemfile +10 -0
  7. data/Gemfile.devtools +55 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +28 -0
  10. data/Rakefile +4 -0
  11. data/bitbot-trader.gemspec +22 -0
  12. data/config/devtools.yml +4 -0
  13. data/config/flay.yml +3 -0
  14. data/config/flog.yml +2 -0
  15. data/config/mutant.yml +3 -0
  16. data/config/reek.yml +103 -0
  17. data/config/yardstick.yml +2 -0
  18. data/examples/account_info.rb +16 -0
  19. data/examples/open_orders.rb +16 -0
  20. data/lib/bitbot/trader.rb +32 -0
  21. data/lib/bitbot/trader/account.rb +29 -0
  22. data/lib/bitbot/trader/amount.rb +15 -0
  23. data/lib/bitbot/trader/api_methods.rb +33 -0
  24. data/lib/bitbot/trader/open_order.rb +29 -0
  25. data/lib/bitbot/trader/price.rb +15 -0
  26. data/lib/bitbot/trader/provider.rb +19 -0
  27. data/lib/bitbot/trader/providers/bitstamp.rb +29 -0
  28. data/lib/bitbot/trader/providers/bitstamp/http_client.rb +101 -0
  29. data/lib/bitbot/trader/providers/bitstamp/open_orders_parser.rb +33 -0
  30. data/lib/bitbot/trader/providers/bitstamp/open_orders_request.rb +25 -0
  31. data/lib/bitbot/trader/providers/mt_gox.rb +29 -0
  32. data/lib/bitbot/trader/providers/mt_gox/account_info_parser.rb +45 -0
  33. data/lib/bitbot/trader/providers/mt_gox/account_info_request.rb +24 -0
  34. data/lib/bitbot/trader/providers/mt_gox/http_client.rb +98 -0
  35. data/lib/bitbot/trader/providers/mt_gox/http_client/hmac_middleware.rb +118 -0
  36. data/lib/bitbot/trader/providers/mt_gox/open_orders_parser.rb +35 -0
  37. data/lib/bitbot/trader/providers/mt_gox/open_orders_request.rb +25 -0
  38. data/lib/bitbot/trader/providers/mt_gox/value_with_currency_coercer.rb +28 -0
  39. data/lib/bitbot/trader/request.rb +41 -0
  40. data/lib/bitbot/trader/utils/nonce_generator.rb +21 -0
  41. data/lib/bitbot/trader/version.rb +5 -0
  42. data/lib/bitbot/trader/wallet.rb +25 -0
  43. data/spec/integration/bitstamp/open_orders_spec.rb +28 -0
  44. data/spec/integration/mt_gox/account_spec.rb +28 -0
  45. data/spec/integration/mt_gox/open_orders_spec.rb +29 -0
  46. data/spec/spec_helper.rb +18 -0
  47. data/spec/support/big_decimal_matcher.rb +5 -0
  48. data/spec/support/http_connection_helpers.rb +15 -0
  49. data/spec/support/http_request_mock.rb +7 -0
  50. data/spec/support/provider_mock.rb +5 -0
  51. data/spec/unit/bitbot/trader/account_spec.rb +28 -0
  52. data/spec/unit/bitbot/trader/api_methods_spec.rb +43 -0
  53. data/spec/unit/bitbot/trader/open_order_spec.rb +19 -0
  54. data/spec/unit/bitbot/trader/provider_spec.rb +18 -0
  55. data/spec/unit/bitbot/trader/providers/bitstamp/http_client_spec.rb +75 -0
  56. data/spec/unit/bitbot/trader/providers/bitstamp/open_order_parser_spec.rb +69 -0
  57. data/spec/unit/bitbot/trader/providers/bitstamp/open_orders_request_spec.rb +24 -0
  58. data/spec/unit/bitbot/trader/providers/bitstamp_spec.rb +45 -0
  59. data/spec/unit/bitbot/trader/providers/mt_gox/account_info_parser_spec.rb +58 -0
  60. data/spec/unit/bitbot/trader/providers/mt_gox/account_info_request_spec.rb +24 -0
  61. data/spec/unit/bitbot/trader/providers/mt_gox/http_client/hmac_middleware_spec.rb +55 -0
  62. data/spec/unit/bitbot/trader/providers/mt_gox/http_client_spec.rb +100 -0
  63. data/spec/unit/bitbot/trader/providers/mt_gox/open_order_parser_spec.rb +95 -0
  64. data/spec/unit/bitbot/trader/providers/mt_gox/open_orders_request_spec.rb +24 -0
  65. data/spec/unit/bitbot/trader/providers/mt_gox/value_with_currency_coercer_spec.rb +21 -0
  66. data/spec/unit/bitbot/trader/providers/mt_gox_spec.rb +26 -0
  67. data/spec/unit/bitbot/trader/request_spec.rb +39 -0
  68. data/spec/unit/bitbot/trader/utils/nonce_generator_spec.rb +19 -0
  69. metadata +166 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5e2c3a0bd61154ade40ff5240f4174400985c7da
4
+ data.tar.gz: 09585b0a46bbf0b3eb8a2a70953ce3d3849b2aee
5
+ SHA512:
6
+ metadata.gz: 3c83fd3919eac434aac310281d2a56eacd90ddc6cd8dc79098d7151a7056d9c8003fb810876af35e2af8b6c26ae60dfe525ab2f1b8e1c2397d9ca5a404d1339c
7
+ data.tar.gz: 247b4cbbd12a6827dc89e7ed24a7ba2635fa17099efc72708c1408c6c4bedce51b10d25bf9a99dd031eb29d209f44bff763e815086a1d484adadc415b6fc1bbd
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ tags
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ bitbot-trader
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ before_install: gem install bundler
3
+ bundler_args: --without guard benchmarks
4
+ script: "bundle exec rake ci"
5
+ rvm:
6
+ - 1.9.3
7
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bitbot-trader.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "devtools", github: "rom-rb/devtools"
8
+ end
9
+
10
+ eval File.read("Gemfile.devtools")
data/Gemfile.devtools ADDED
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ group :development do
4
+ gem 'rake', '~> 10.1.0'
5
+ gem 'rspec', '~> 2.14.1'
6
+ gem 'yard', '~> 0.8.7'
7
+ end
8
+
9
+ group :yard do
10
+ gem 'kramdown', '~> 1.2.0'
11
+ end
12
+
13
+ group :guard do
14
+ gem 'guard', '~> 1.8.1'
15
+ gem 'guard-bundler', '~> 1.0.0'
16
+ gem 'guard-rspec', '~> 3.0.2'
17
+ gem 'guard-rubocop', '~> 0.2.0'
18
+ gem 'guard-mutant', '~> 0.0.1'
19
+
20
+ # file system change event handling
21
+ gem 'listen', '~> 1.3.0'
22
+ gem 'rb-fchange', '~> 0.0.6', require: false
23
+ gem 'rb-fsevent', '~> 0.9.3', require: false
24
+ gem 'rb-inotify', '~> 0.9.0', require: false
25
+
26
+ # notification handling
27
+ gem 'libnotify', '~> 0.8.0', require: false
28
+ gem 'rb-notifu', '~> 0.0.4', require: false
29
+ gem 'terminal-notifier-guard', '~> 1.5.3', require: false
30
+ end
31
+
32
+ group :metrics do
33
+ gem 'coveralls', '~> 0.7.0'
34
+ gem 'flay', '~> 2.4.0'
35
+ gem 'flog', '~> 4.1.1'
36
+ gem 'reek', '~> 1.3.2'
37
+ gem 'rubocop', '~> 0.14.1'
38
+ gem 'simplecov', '~> 0.7.1'
39
+ gem 'yardstick', '~> 0.9.7', git: 'https://github.com/dkubb/yardstick.git'
40
+
41
+ platforms :ruby_19, :ruby_20 do
42
+ gem 'mutant', git: 'https://github.com/mbj/mutant.git'
43
+ gem 'yard-spellcheck', '~> 0.1.5'
44
+ end
45
+ end
46
+
47
+ group :benchmarks do
48
+ gem 'rbench', '~> 0.2.3'
49
+ end
50
+
51
+ platform :jruby do
52
+ group :jruby do
53
+ gem 'jruby-openssl', '~> 0.8.5'
54
+ end
55
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Indrek Juhkam
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 ADDED
@@ -0,0 +1,28 @@
1
+ # Bitbot::Trader
2
+
3
+ [![Build Status](https://secure.travis-ci.org/indrekj/bitbot-trader.png?branch=master)](http://travis-ci.org/indrekj/bitbot-trader)
4
+ [![Dependency Status](https://gemnasium.com/indrekj/bitbot-trader.png)](https://gemnasium.com/indrekj/bitbot-trader)
5
+ [![Code Climate](https://codeclimate.com/github/indrekj/bitbot-trader.png)](https://codeclimate.com/github/indrekj/bitbot-trader)
6
+ [![Coverage Status](https://coveralls.io/repos/indrekj/bitbot-trader/badge.png?branch=master)](https://coveralls.io/r/indrekj/bitbot-trader)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem "bitbot-trader", github: "indrekj/bitbot-trader"
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ ## Usage
19
+
20
+ See examples/*.rb
21
+
22
+ ## Contributing
23
+
24
+ 1. Fork it
25
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
26
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
27
+ 4. Push to the branch (`git push origin my-new-feature`)
28
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "devtools"
4
+ Devtools.init_rake_tasks
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "bitbot/trader/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bitbot-trader"
7
+ spec.version = Bitbot::Trader::VERSION
8
+ spec.authors = ["Indrek Juhkam"]
9
+ spec.email = ["indrek@urgas.eu"]
10
+ spec.description = %q{}
11
+ spec.summary = %q{}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "virtus", "~> 1.0"
21
+ spec.add_dependency "faraday", "~> 0.8"
22
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ unit_test_timeout: 0.1
3
+ fail_on_branch:
4
+ - "master"
data/config/flay.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ threshold: 13
3
+ total_score: 101
data/config/flog.yml ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 8.5
data/config/mutant.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ name: bitbot/trader
3
+ namespace: Bitbot::Trader
data/config/reek.yml ADDED
@@ -0,0 +1,103 @@
1
+ ---
2
+ Attribute:
3
+ enabled: false
4
+ exclude: []
5
+ BooleanParameter:
6
+ enabled: true
7
+ exclude: []
8
+ ClassVariable:
9
+ enabled: true
10
+ exclude: []
11
+ ControlParameter:
12
+ enabled: true
13
+ exclude: []
14
+ DataClump:
15
+ enabled: true
16
+ exclude: []
17
+ max_copies: 2
18
+ min_clump_size: 2
19
+ DuplicateMethodCall:
20
+ enabled: true
21
+ exclude: []
22
+ max_calls: 1
23
+ allow_calls: []
24
+ FeatureEnvy:
25
+ enabled: true
26
+ exclude: []
27
+ IrresponsibleModule:
28
+ enabled: true
29
+ exclude: []
30
+ LongParameterList:
31
+ enabled: true
32
+ exclude: []
33
+ max_params: 3
34
+ overrides:
35
+ initialize:
36
+ max_params: 3
37
+ LongYieldList:
38
+ enabled: true
39
+ exclude: []
40
+ max_params: 2
41
+ NestedIterators:
42
+ enabled: true
43
+ exclude: []
44
+ max_allowed_nesting: 1
45
+ ignore_iterators: []
46
+ NilCheck:
47
+ enabled: true
48
+ exclude: []
49
+ RepeatedConditional:
50
+ enabled: true
51
+ exclude: []
52
+ max_ifs: 1
53
+ TooManyInstanceVariables:
54
+ enabled: true
55
+ exclude: []
56
+ max_instance_variables: 3
57
+ TooManyMethods:
58
+ enabled: true
59
+ exclude: []
60
+ max_methods: 10
61
+ TooManyStatements:
62
+ enabled: true
63
+ exclude:
64
+ - each
65
+ max_statements: 5
66
+ UncommunicativeMethodName:
67
+ enabled: true
68
+ exclude: []
69
+ reject:
70
+ - !ruby/regexp /^[a-z]$/
71
+ - !ruby/regexp /[0-9]$/
72
+ - !ruby/regexp /[A-Z]/
73
+ accept: []
74
+ UncommunicativeModuleName:
75
+ enabled: true
76
+ exclude: []
77
+ reject:
78
+ - !ruby/regexp /^.$/
79
+ - !ruby/regexp /[0-9]$/
80
+ accept: []
81
+ UncommunicativeParameterName:
82
+ enabled: true
83
+ exclude: []
84
+ reject:
85
+ - !ruby/regexp /^.$/
86
+ - !ruby/regexp /[0-9]$/
87
+ - !ruby/regexp /[A-Z]/
88
+ accept: []
89
+ UncommunicativeVariableName:
90
+ enabled: true
91
+ exclude: []
92
+ reject:
93
+ - !ruby/regexp /^.$/
94
+ - !ruby/regexp /[0-9]$/
95
+ - !ruby/regexp /[A-Z]/
96
+ accept: []
97
+ UnusedParameters:
98
+ enabled: true
99
+ exclude: []
100
+ UtilityFunction:
101
+ enabled: true
102
+ exclude: []
103
+ max_helper_calls: 0
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 100
@@ -0,0 +1,16 @@
1
+ require "bitbot/trader"
2
+
3
+ #bitstamp = Bitbot::Trader::Providers::Bitstamp.new(
4
+ # username: ENV["BITSTAMP_USERNAME"],
5
+ # password: ENV["BITSTAMP_PASSWORD"]
6
+ #)
7
+ #
8
+ #puts "Bitstamp account:"
9
+ #puts bitstamp.account.inspect
10
+
11
+ mt_gox = Bitbot::Trader::Providers::MtGox.new(
12
+ key: ENV["MTGOX_KEY"],
13
+ secret: ENV["MTGOX_SECRET"]
14
+ )
15
+ puts "MtGox account:"
16
+ puts mt_gox.account.inspect
@@ -0,0 +1,16 @@
1
+ require "bitbot/trader"
2
+
3
+ bitstamp = Bitbot::Trader::Providers::Bitstamp.new(
4
+ username: ENV["BITSTAMP_USERNAME"],
5
+ password: ENV["BITSTAMP_PASSWORD"]
6
+ )
7
+
8
+ puts "Bitstamp open orders:"
9
+ puts bitstamp.open_orders.inspect
10
+
11
+ mt_gox = Bitbot::Trader::Providers::MtGox.new(
12
+ key: ENV["MTGOX_KEY"],
13
+ secret: ENV["MTGOX_SECRET"]
14
+ )
15
+ puts "MtGox open orders:"
16
+ puts mt_gox.open_orders.inspect
@@ -0,0 +1,32 @@
1
+ require "bitbot/trader/version"
2
+
3
+ module Bitbot
4
+ module Trader
5
+ end
6
+ end
7
+
8
+ require "bitbot/trader/amount"
9
+ require "bitbot/trader/price"
10
+ require "bitbot/trader/wallet"
11
+ require "bitbot/trader/account"
12
+ require "bitbot/trader/open_order"
13
+
14
+ require "bitbot/trader/request"
15
+ require "bitbot/trader/api_methods"
16
+ require "bitbot/trader/provider"
17
+
18
+ require "bitbot/trader/utils/nonce_generator"
19
+
20
+ require "bitbot/trader/providers/bitstamp"
21
+ require "bitbot/trader/providers/bitstamp/http_client"
22
+ require "bitbot/trader/providers/bitstamp/open_orders_request"
23
+ require "bitbot/trader/providers/bitstamp/open_orders_parser"
24
+
25
+ require "bitbot/trader/providers/mt_gox"
26
+ require "bitbot/trader/providers/mt_gox/http_client"
27
+ require "bitbot/trader/providers/mt_gox/http_client/hmac_middleware"
28
+ require "bitbot/trader/providers/mt_gox/value_with_currency_coercer"
29
+ require "bitbot/trader/providers/mt_gox/open_orders_request"
30
+ require "bitbot/trader/providers/mt_gox/open_orders_parser"
31
+ require "bitbot/trader/providers/mt_gox/account_info_request"
32
+ require "bitbot/trader/providers/mt_gox/account_info_parser"
@@ -0,0 +1,29 @@
1
+ require "virtus"
2
+
3
+ module Bitbot
4
+ module Trader
5
+ # User account info
6
+ #
7
+ class Account
8
+ include Virtus.model
9
+
10
+ attribute :fee, Float
11
+ attribute :wallets, Array[Wallet]
12
+
13
+ # Fetches account wallet with given currency
14
+ #
15
+ # @example
16
+ # account.wallet("USD") #=> <Wallet>
17
+ #
18
+ # @param [String] currency
19
+ #
20
+ # @return [Wallet, nil]
21
+ #
22
+ # @api public
23
+ #
24
+ def wallet(currency)
25
+ wallets.detect { |wallet| wallet.currency == currency }
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ require "virtus"
2
+
3
+ module Bitbot
4
+ module Trader
5
+ # Amount value object. Every amount has a value and a currency.
6
+ # e.g 5.6 USD
7
+ #
8
+ class Amount
9
+ include Virtus.model
10
+
11
+ attribute :value, BigDecimal
12
+ attribute :currency, String
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ module Bitbot
2
+ module Trader
3
+ # API methods that can be used with every provider
4
+ #
5
+ module ApiMethods
6
+ # Fetches user's current open orders
7
+ #
8
+ # @example
9
+ # provider.open_orders #=> [<OpenOrder>, <OpenOrder>]
10
+ #
11
+ # @return [Array<OpenOrder>]
12
+ #
13
+ # @api public
14
+ #
15
+ def open_orders
16
+ self.class::OpenOrdersRequest.new(client).call
17
+ end
18
+
19
+ # Fetches user's account info
20
+ #
21
+ # @example
22
+ # provider.account #=> <Account>
23
+ #
24
+ # @return [Account]
25
+ #
26
+ # @api public
27
+ #
28
+ def account
29
+ self.class::AccountInfoRequest.new(client).call
30
+ end
31
+ end
32
+ end
33
+ end