rbtc_arbitrage 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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +1 -0
- data/bin/rbtc +4 -0
- data/lib/rbtc_arbitrage/cli.rb +101 -0
- data/lib/rbtc_arbitrage/version.rb +3 -0
- data/lib/rbtc_arbitrage.rb +8 -0
- data/rbtc_arbitrage.gemspec +27 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: dddb7217b6141f7c431b3798873c397c5c2f3e60
|
4
|
+
data.tar.gz: 3f0f76d0a4505c271ce5e70df23d6de490ad742e
|
5
|
+
!binary "U0hBNTEy":
|
6
|
+
metadata.gz: 9d500fdcb0aa5bf8e56697a0282746b4a3ef74cc01161fca32021a7a0a50250aa5f2c0281e1f39bba67932c98411934356cd2b11a5fc939ffd4b6b8d1e6d3d8f
|
7
|
+
data.tar.gz: 64a343c00e51df21ca037d8213752c31c7d0240c0e68a2485e00744831f73a3a962fa232fd3edca01b3f57883a5ea5eca30b9f3fca2a0c2d20a956588778c9eb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Hank Stoever
|
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,54 @@
|
|
1
|
+
# RbtcArbitrage
|
2
|
+
|
3
|
+
A Ruby gem for automating arbitrage between the MtGox and Bitstamp bitcoin exchanges.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install it yourself as:
|
8
|
+
|
9
|
+
$ gem install rbtc_arbitrage
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
After installing the gem, simply run `rbtc` in the command line.
|
14
|
+
|
15
|
+
#### Options
|
16
|
+
|
17
|
+
- **Live**: whether you want to actually execute trades. You must have configured your API keys and bitcoin addresses through the following environment variables:
|
18
|
+
1. MTGOX_KEY
|
19
|
+
2. MTGOX_SECRET
|
20
|
+
2. MTGOX_ADDRESS
|
21
|
+
2. BITSTAMP_KEY
|
22
|
+
2. BITSTAMP_SECRET
|
23
|
+
3. BITSTAMP_ADDRESS
|
24
|
+
|
25
|
+
- **Cutoff**: the minimum profit percentage required to execute a trade. Defaults to **%2.00**.
|
26
|
+
- **Volume**: The amount of bitcoins to trade per transaction. Defaults to **0.01** (the minimum transaction size).
|
27
|
+
|
28
|
+
#### Examples
|
29
|
+
|
30
|
+
$ rbtc --live --cutoff 4
|
31
|
+
$ rbtc --cutoff 0.5
|
32
|
+
$ rbtc --cutoff 3 --volume 0.05
|
33
|
+
$ rbtc
|
34
|
+
|
35
|
+
The output will look like this:
|
36
|
+
|
37
|
+
07/08/2013 at 10:41AM
|
38
|
+
Retrieving market information and balances
|
39
|
+
Bitstamp: $74.0
|
40
|
+
MtGox: $76.89
|
41
|
+
buying 0.01 btc from Bitstamp for $0.74
|
42
|
+
selling 0.01 btc on MtGox for $0.76
|
43
|
+
profit: $0.02 (2.77%)
|
44
|
+
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
### Pull Requests are welcome!
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/rbtc
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
module RbtcArbitrage
|
2
|
+
class CLI < Thor
|
3
|
+
attr_accessor :stamp, :mtgox
|
4
|
+
|
5
|
+
desc "arbitrage", "Get information about the current arbitrage levels."
|
6
|
+
option :live, type: :boolean, default: false, desc: "Execute live trades."
|
7
|
+
option :cutoff, type: :numeric, default: 2, desc: "The minimum profit level required to execute a trade."
|
8
|
+
option :volume, type: :numeric, default: 0.01, desc: "The amount of bitcoins to trade per transaction."
|
9
|
+
def trade
|
10
|
+
@stamp = {}; @mtgox = {}
|
11
|
+
|
12
|
+
if options[:live]
|
13
|
+
validate_env
|
14
|
+
get_balance
|
15
|
+
end
|
16
|
+
|
17
|
+
# puts "#{Time.now.strftime("%m/%d/%Y at %I:%M%p")}"
|
18
|
+
# puts "Retrieving market information and balances"
|
19
|
+
amount_to_buy = options[:volume]
|
20
|
+
stamp[:price] = Bitstamp.ticker.ask.to_f
|
21
|
+
mtgox[:price] = MtGox.ticker.buy
|
22
|
+
prices = [stamp[:price], mtgox[:price]]
|
23
|
+
paid = prices.min * 1.005 * amount_to_buy
|
24
|
+
received = prices.max * 0.994 * amount_to_buy
|
25
|
+
|
26
|
+
puts "Bitstamp: $#{stamp[:price].round(2)}"
|
27
|
+
puts "MtGox: $#{mtgox[:price].round(2)}"
|
28
|
+
lower_ex, higher_ex = stamp[:price] < mtgox[:price] ? [Bitstamp, MtGox] : [MtGox, Bitstamp]
|
29
|
+
puts "buying #{amount_to_buy} btc from #{lower_ex} for $#{paid.round(2)}"
|
30
|
+
puts "selling #{amount_to_buy} btc on #{higher_ex} for $#{received.round(2)}"
|
31
|
+
percent = ((received/paid - 1) * 100).round(2)
|
32
|
+
puts "profit: $#{(received - paid).round(2)} (#{percent.round(2)}%)"
|
33
|
+
|
34
|
+
if options[:cutoff] > percent
|
35
|
+
puts "Exiting because real profit (#{percent.round(2)}%) is less than cutoff (#{options[:cutoff].round(2)}%)"
|
36
|
+
return 0
|
37
|
+
end
|
38
|
+
|
39
|
+
if options[:live]
|
40
|
+
puts "Balances:"
|
41
|
+
puts "stamp usd: $#{stamp[:usd].round(2)} btc: #{stamp[:usd].round(2)}"
|
42
|
+
puts "mtgox usd: $#{mtgox[:usd].round(2)} btc: #{mtgox[:usd].round(2)}"
|
43
|
+
if stamp[:price] < mtgox[:price]
|
44
|
+
if paid > stamp[:usd] || amount_to_buy > mtgox[:btc]
|
45
|
+
puts "Not enough funds. Exiting."
|
46
|
+
else
|
47
|
+
puts "Trading live!"
|
48
|
+
Bitstamp.orders.buy amount_to_buy, stamp[:price] + 0.001
|
49
|
+
MtGox.sell! amount_to_buy, :market
|
50
|
+
Bitstamp.transfer amount_to_buy, ENV['MTGOX_ADDRESS']
|
51
|
+
end
|
52
|
+
else
|
53
|
+
if paid > mtgox[:usd] || amount_to_buy > stamp[:btc]
|
54
|
+
puts "Not enough funds. Exiting."
|
55
|
+
else
|
56
|
+
puts "Trading live!"
|
57
|
+
MtGox.buy! amount_to_buy, :market
|
58
|
+
Bitstamp.orders.sell amount_to_buy, stamp[:price] - 0.001
|
59
|
+
MtGox.withdraw amount_to_buy, ENV['BITSTAMP_ADDRESS']
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
0
|
64
|
+
end
|
65
|
+
|
66
|
+
default_task :trade
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def validate_env
|
71
|
+
["KEY", "SECRET", "ADDRESS"].each do |suffix|
|
72
|
+
["MTGOX", "BITSTAMP"].each do |prefix|
|
73
|
+
key = "#{prefix}_#{suffix}"
|
74
|
+
if ENV[key].blank?
|
75
|
+
puts "Exiting because missing required ENV variable $#{key}."
|
76
|
+
return 0
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
MtGox.configure do |config|
|
82
|
+
config.key = ENV["MTGOX_KEY"]
|
83
|
+
config.secret = ENV["MTGOX_SECRET"]
|
84
|
+
end
|
85
|
+
|
86
|
+
Bitstamp.setup do |config|
|
87
|
+
config.key = ENV["BITSTAMP_KEY"]
|
88
|
+
config.secret = ENV["BITSTAMP_SECRET"]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_balance
|
93
|
+
balances = MtGox.balance
|
94
|
+
@mtgox[:btc] = balances[0].amount.to_f
|
95
|
+
@mtgox[:usd] = balances[1].amount.to_f
|
96
|
+
balances = Bitstamp.balance if options[:live]
|
97
|
+
@stamp[:usd] = balances["usd_available"].to_f
|
98
|
+
@stamp[:btc] = balances["btc_available"].to_f
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -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 'rbtc_arbitrage/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rbtc_arbitrage"
|
8
|
+
spec.version = RbtcArbitrage::VERSION
|
9
|
+
spec.authors = ["Hank Stoever"]
|
10
|
+
spec.email = ["hstove@gmail.com"]
|
11
|
+
spec.description = %q{A gem for conducting arbitrage with Bitcoin.}
|
12
|
+
spec.summary = %q{A gem for conducting arbitrage with Bitcoin.}
|
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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "mtgox"
|
25
|
+
spec.add_dependency "bitstamp"
|
26
|
+
spec.add_dependency "thor"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rbtc_arbitrage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hank Stoever
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: mtgox
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bitstamp
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: thor
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: A gem for conducting arbitrage with Bitcoin.
|
84
|
+
email:
|
85
|
+
- hstove@gmail.com
|
86
|
+
executables:
|
87
|
+
- rbtc
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/rbtc
|
97
|
+
- lib/rbtc_arbitrage.rb
|
98
|
+
- lib/rbtc_arbitrage/cli.rb
|
99
|
+
- lib/rbtc_arbitrage/version.rb
|
100
|
+
- rbtc_arbitrage.gemspec
|
101
|
+
homepage: ''
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.0.3
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: A gem for conducting arbitrage with Bitcoin.
|
125
|
+
test_files: []
|
126
|
+
has_rdoc:
|