cexio_reinvestor 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjM0ZTMyYWUxMmVjNmQyYWZhMjEyNDc4ODkxZjI0NjY1OWU3YWYwMA==
5
+ data.tar.gz: !binary |-
6
+ OGIzMmMzOGJjOTBhYTNiZWYxZTBhYmI2MjY5MGE2ZGUzODAzNzI5NA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NWQ5MmIyZjA1YWZiNWUzODg0MzllZjg1ODM5YzAwNzVmNzhiM2QzNjkxNTg1
10
+ M2RmNzMwMTAwMzgyMGU1OWRjZWYzNjUwY2I1Yjc0Y2VjNWFiNjY1MjI3NGMx
11
+ ZGE0OTQxNTA4NDhkNjhjY2JlNjNmMTI4ZWI0MWNlNjMyY2U0ODA=
12
+ data.tar.gz: !binary |-
13
+ ODhhZTg5NmYyNGQ2NTkzMjU3YWMxMzY3YjgwNmVmNzE1ZDUzZjdkZmFmMTdi
14
+ YzUwM2U0NjE3MzJhODk2NmI5ZGI0MGFiM2U1MWM1MTQ5YzFkMjkwZDgzNzFl
15
+ NGNjODUyMzQxMDk4ZDc1ZmJkN2EwZWRjNThkYmYyZTliZWIyOTc=
@@ -0,0 +1,18 @@
1
+ Gemfile.lock
2
+ *.swp
3
+ *.gem
4
+ *.rbc
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tomas Rojas
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,19 @@
1
+ # CEX.io Reinvestor
2
+
3
+ This is a simple command-line tool that helps you reinvest your mined BTC and NMC, similar to a Forex Daily Returns Investment Program.
4
+
5
+ ## Installation
6
+
7
+ $ gem install cexio_reinvestor
8
+
9
+ ## Usage
10
+
11
+ $ cexio_reinvestor -u your_cexio_username -a your_cexio_api_key -s your_cexio_api_secret
12
+
13
+ ## Contributing
14
+
15
+ 1. Fork it
16
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
17
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
18
+ 4. Push to the branch (`git push origin my-new-feature`)
19
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+ require 'micro-optparse'
4
+ require 'cexio_reinvestor'
5
+
6
+ parser = Parser.new do |p|
7
+ p.option :username, "CEX.io username", default: ""
8
+ p.option :api_key, "CEX.io API key", default: ""
9
+ p.option :api_secret, "CEX.io API secret", short: 's', default: ""
10
+ end
11
+ options = parser.process!
12
+
13
+ if options.values.any?(&:empty?)
14
+ puts parser.instance_eval { @optionparser }
15
+ exit 1
16
+ end
17
+
18
+ trader = CexioReinvestor::Trader.new(options[:username], options[:api_key], options[:api_secret])
19
+
20
+ trap('INT') do
21
+ puts "\nBye."
22
+ exit
23
+ end
24
+
25
+ trader.run
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cexio_reinvestor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cexio_reinvestor"
8
+ spec.version = CexioReinvestor::VERSION
9
+ spec.authors = ["Tomas Rojas"]
10
+ spec.email = ["tmsrjs@gmail.com"]
11
+ spec.description = %q{CEX.io Reinvestor reinvests earned BTC and NMC.}
12
+ spec.summary = %q{CEX.io Reinvestor.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "cexio"
22
+ spec.add_dependency "micro-optparse"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ #spec.add_development_dependency "rspec", "~> 2.14.1"
26
+ #spec.add_development_dependency "debugger"
27
+ end
@@ -0,0 +1,52 @@
1
+ require 'bigdecimal'
2
+ require 'cexio'
3
+
4
+ module CexioReinvestor
5
+
6
+ MIN = BigDecimal.new('0.00000001')
7
+
8
+ class Trader
9
+ def initialize(username, api_key, api_secret)
10
+ @username = username
11
+ @api_key = api_key
12
+ @api_secret = api_secret
13
+ end
14
+
15
+ def api
16
+ @api ||= CEX::API.new(@username, @api_key, @api_secret)
17
+ end
18
+
19
+ def trade(pair)
20
+ to, from = pair.split('/')
21
+ balance = BigDecimal.new(api.balance[from]['available'])
22
+ sleep 1
23
+ price, amount = api.order_book(pair)['asks'].first.map { |x| BigDecimal.new(x, 8) }
24
+ sleep 1
25
+ amount_to_buy = [ balance / price, amount ].min.round(8, :down)
26
+ return if amount_to_buy < MIN
27
+
28
+ result = api.place_order('buy', amount_to_buy, price, pair)
29
+ result['pending'] = BigDecimal.new(result['pending'], 8)
30
+
31
+ order_info = "#{amount_to_buy.to_s('F')} #{to} @ #{price.to_s('F')} #{from} each"
32
+ if result['error']
33
+ print "Could not place order for #{order_info}"
34
+ puts " - Error was: #{result['error']}"
35
+ else
36
+ print "Placed order for #{order_info}"
37
+ print " - Bought #{(amount_to_buy - result['pending']).to_s('F')}"
38
+ print ", #{result['pending'].to_s('F')} pending" if result['pending'] > 0
39
+ puts " - #{Time.now}"
40
+ end
41
+ end
42
+
43
+ def run
44
+ while true do
45
+ [ 'GHS/BTC', 'GHS/NMC' ].each do |pair|
46
+ trade(pair)
47
+ sleep 10
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module CexioReinvestor
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cexio_reinvestor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Rojas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cexio
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: micro-optparse
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ description: CEX.io Reinvestor reinvests earned BTC and NMC.
56
+ email:
57
+ - tmsrjs@gmail.com
58
+ executables:
59
+ - cexio_reinvestor
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/cexio_reinvestor
69
+ - cexio_reinvestor.gemspec
70
+ - lib/cexio_reinvestor.rb
71
+ - lib/cexio_reinvestor/version.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.1.9
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: CEX.io Reinvestor.
96
+ test_files: []