rbtc_arbitrage 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +3 -1
  3. data/bitstamp/.gitignore +21 -0
  4. data/bitstamp/.rspec +2 -0
  5. data/bitstamp/.ruby-gemset +1 -0
  6. data/bitstamp/.ruby-version +1 -0
  7. data/bitstamp/Gemfile +24 -0
  8. data/bitstamp/Gemfile.lock +64 -0
  9. data/bitstamp/LICENSE.txt +20 -0
  10. data/bitstamp/README.md +96 -0
  11. data/bitstamp/Rakefile +49 -0
  12. data/bitstamp/VERSION +1 -0
  13. data/bitstamp/bitstamp.gemspec +94 -0
  14. data/bitstamp/lib/bitstamp/collection.rb +30 -0
  15. data/bitstamp/lib/bitstamp/helper.rb +19 -0
  16. data/bitstamp/lib/bitstamp/model.rb +33 -0
  17. data/bitstamp/lib/bitstamp/net.rb +49 -0
  18. data/bitstamp/lib/bitstamp/orders.rb +41 -0
  19. data/bitstamp/lib/bitstamp/ticker.rb +16 -0
  20. data/bitstamp/lib/bitstamp/transactions.rb +37 -0
  21. data/bitstamp/lib/bitstamp.rb +77 -0
  22. data/bitstamp/spec/bitstamp_spec.rb +57 -0
  23. data/bitstamp/spec/collection_spec.rb +12 -0
  24. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/balance.yml +63 -0
  25. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/order_book.yml +1910 -0
  26. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/orders/all.yml +62 -0
  27. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/orders/buy.yml +62 -0
  28. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/orders/sell/failure.yml +60 -0
  29. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/ticker.yml +63 -0
  30. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/transactions.yml +244 -0
  31. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/user_transactions/all.yml +223 -0
  32. data/bitstamp/spec/orders_spec.rb +40 -0
  33. data/bitstamp/spec/spec_helper.rb +26 -0
  34. data/bitstamp/spec/support/bitstamp_setup.rb +19 -0
  35. data/bitstamp/spec/support/vcr.rb +21 -0
  36. data/bitstamp/spec/transactions_spec.rb +32 -0
  37. data/lib/rbtc_arbitrage/trader/logger.rb +18 -7
  38. data/lib/rbtc_arbitrage/version.rb +1 -1
  39. data/lib/rbtc_arbitrage.rb +5 -1
  40. data/rbtc_arbitrage.gemspec +21 -0
  41. metadata +50 -2
@@ -0,0 +1,77 @@
1
+ require 'active_support/core_ext'
2
+ require 'active_support/inflector'
3
+ require 'active_model'
4
+ require 'curb'
5
+ require 'hmac-sha2'
6
+
7
+ require 'bitstamp/net'
8
+ require 'bitstamp/helper'
9
+ require 'bitstamp/collection'
10
+ require 'bitstamp/model'
11
+
12
+ require 'bitstamp/orders'
13
+ require 'bitstamp/transactions'
14
+ require 'bitstamp/ticker'
15
+
16
+ String.send(:include, ActiveSupport::Inflector)
17
+
18
+ module Bitstamp
19
+ # API Key
20
+ mattr_accessor :key
21
+
22
+ # Bitstamp secret
23
+ mattr_accessor :secret
24
+
25
+ # Bitstamp client ID
26
+ mattr_accessor :client_id
27
+
28
+ # Currency
29
+ mattr_accessor :currency
30
+ @@currency = :usd
31
+
32
+ def self.orders
33
+ self.sanity_check!
34
+
35
+ @@orders ||= Bitstamp::Orders.new
36
+ end
37
+
38
+ def self.user_transactions
39
+ self.sanity_check!
40
+
41
+ @@transactions ||= Bitstamp::UserTransactions.new
42
+ end
43
+
44
+ def self.transactions
45
+ return Bitstamp::Transactions.from_api
46
+ end
47
+
48
+ def self.balance
49
+ self.sanity_check!
50
+
51
+ JSON.parse Bitstamp::Net.post('/balance').body_str
52
+ end
53
+
54
+ def self.ticker
55
+ return Bitstamp::Ticker.from_api
56
+ end
57
+
58
+ def self.order_book
59
+ return JSON.parse Bitstamp::Net.get('/order_book/').body_str
60
+ end
61
+
62
+ def self.setup
63
+ yield self
64
+ end
65
+
66
+ def self.configured?
67
+ self.key && self.secret && self.client_id
68
+ end
69
+
70
+ def self.sanity_check!
71
+ unless configured?
72
+ raise MissingConfigExeception.new("Bitstamp Gem not properly configured")
73
+ end
74
+ end
75
+
76
+ class MissingConfigExeception<Exception;end;
77
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bitstamp do
4
+
5
+ describe :sanity_check! do
6
+ context 'not properly configured' do
7
+ it { -> { Bitstamp.sanity_check! }.should raise_error }
8
+ end
9
+ context 'properly configured' do
10
+ before {
11
+ Bitstamp.setup do |config|
12
+ config.key = 'test'
13
+ config.secret = 'test'
14
+ config.client_id = 'test'
15
+ end
16
+ }
17
+ it { -> { Bitstamp.sanity_check! }.should_not raise_error }
18
+ end
19
+ end
20
+
21
+ describe :orders do
22
+ it { should respond_to :orders }
23
+ end
24
+
25
+ describe :ticket, vcr: {cassette_name: 'bitstamp/ticker'} do
26
+ subject { Bitstamp.ticker }
27
+ it { should be_kind_of Bitstamp::Ticker }
28
+ its(:high) { should == "124.90" }
29
+ its(:last) { should == "124.55" }
30
+ its(:timestamp) { should == "1380237724" }
31
+ its(:bid) { should == "124.55" }
32
+ its(:volume) { should == "7766.46908740" }
33
+ its(:low) { should == "123.00" }
34
+ its(:ask) { should == "124.56" }
35
+ end
36
+
37
+ describe :balance, vcr: {cassette_name: 'bitstamp/balance'} do
38
+ context "configured" do
39
+ subject { Bitstamp.balance }
40
+ before { setup_bitstamp }
41
+ it { should == {"btc_reserved"=>"0", "fee"=>"0.4000", "btc_available"=>"0", "usd_reserved"=>"1.02", "btc_balance"=>"0", "usd_balance"=>"6953.07", "usd_available"=>"6952.05"} }
42
+ end
43
+ context "not configured" do
44
+ it { expect { Bitstamp.balance }.to raise_exception(Bitstamp::MissingConfigExeception, "Bitstamp Gem not properly configured") }
45
+ end
46
+ end
47
+
48
+ describe :order_book, vcr: {cassette_name: 'bitstamp/order_book'} do
49
+ let(:order_book) { Bitstamp.order_book }
50
+ subject { order_book }
51
+ it { should be_kind_of Hash }
52
+ it { should have_key("asks") }
53
+ it { should have_key("bids") }
54
+ it { order_book["asks"].should be_kind_of Array }
55
+ it { order_book["bids"].should be_kind_of Array }
56
+ end
57
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ class Bitstamp::Coin < Bitstamp::Model;end
4
+ class Bitstamp::Coins < Bitstamp::Collection;end
5
+
6
+ describe Bitstamp::Coins do
7
+ subject { Bitstamp::Coins.new }
8
+ its(:name) { should eq 'coin' }
9
+ its(:module) { should eq "bitstamp/coin" }
10
+ its(:model) { should be Bitstamp::Coin }
11
+ its(:path) { should eq "/api/coins" }
12
+ end
@@ -0,0 +1,63 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.bitstamp.net/api/balance/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: key=BITSTAMP_KEY&nonce=1380237671&signature=67768DD1BBDF45203840CC8688847A2DF5D224CA15B3ABDDC804EA251AC12211
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: !binary |-
14
+ T0s=
15
+ headers:
16
+ !binary "U2VydmVy":
17
+ - !binary |-
18
+ Y2xvdWRmbGFyZS1uZ2lueA==
19
+ !binary "RGF0ZQ==":
20
+ - !binary |-
21
+ VGh1LCAyNiBTZXAgMjAxMyAyMzoyMToxOCBHTVQ=
22
+ !binary "Q29udGVudC1UeXBl":
23
+ - !binary |-
24
+ YXBwbGljYXRpb24vanNvbg==
25
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
26
+ - !binary |-
27
+ Y2h1bmtlZA==
28
+ !binary "Q29ubmVjdGlvbg==":
29
+ - !binary |-
30
+ a2VlcC1hbGl2ZQ==
31
+ !binary "U2V0LUNvb2tpZQ==":
32
+ - !binary |-
33
+ X19jZmR1aWQ9ZDg2ZTkzYTIxNzY5Y2UxZDQzODc2YzQ1N2ZjNTU3ZmNjMTM4
34
+ MDIzNzY3Nzk1ODsgZXhwaXJlcz1Nb24sIDIzLURlYy0yMDE5IDIzOjUwOjAw
35
+ IEdNVDsgcGF0aD0vOyBkb21haW49LmJpdHN0YW1wLm5ldA==
36
+ !binary "Q29udGVudC1MYW5ndWFnZQ==":
37
+ - !binary |-
38
+ ZW4=
39
+ !binary "RXhwaXJlcw==":
40
+ - !binary |-
41
+ VGh1LCAyNiBTZXAgMjAxMyAyMzoyMToxOCBHTVQ=
42
+ !binary "VmFyeQ==":
43
+ - !binary |-
44
+ QWNjZXB0LUxhbmd1YWdl
45
+ !binary "Q2FjaGUtQ29udHJvbA==":
46
+ - !binary |-
47
+ bWF4LWFnZT0w
48
+ !binary "TGFzdC1Nb2RpZmllZA==":
49
+ - !binary |-
50
+ VGh1LCAyNiBTZXAgMjAxMyAyMzoyMToxOCBHTVQ=
51
+ !binary "Q2YtUmF5":
52
+ - !binary |-
53
+ YjQzYjA4ZjM5ZDgwMDk3
54
+ body:
55
+ encoding: ASCII-8BIT
56
+ string: !binary |-
57
+ eyJidGNfcmVzZXJ2ZWQiOiAiMCIsICJmZWUiOiAiMC40MDAwIiwgImJ0Y19h
58
+ dmFpbGFibGUiOiAiMCIsICJ1c2RfcmVzZXJ2ZWQiOiAiMS4wMiIsICJidGNf
59
+ YmFsYW5jZSI6ICIwIiwgInVzZF9iYWxhbmNlIjogIjY5NTMuMDciLCAidXNk
60
+ X2F2YWlsYWJsZSI6ICI2OTUyLjA1In0=
61
+ http_version:
62
+ recorded_at: Thu, 26 Sep 2013 23:21:18 GMT
63
+ recorded_with: VCR 2.6.0