mt_gox 0.7.5 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -6,3 +6,7 @@
6
6
  == 0.7.5 / 2012-01-17
7
7
 
8
8
  * Model now has attributes / properties
9
+
10
+ == 0.7.6 / 2012-01-17
11
+
12
+ * Multi-currency ticker and Depth streaming Models added
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.5
1
+ 0.7.6
@@ -0,0 +1,19 @@
1
+ require 'mtgox/models/model'
2
+
3
+ module MtGox
4
+ module Models
5
+ class Depth < Model
6
+ prop :buy,
7
+ :sell,
8
+ :currency,
9
+ :item,
10
+ [:vol, :volume] => :f,
11
+ :volume_int => :i,
12
+ :total_volume_int => :i,
13
+ :price => :f,
14
+ :price_int => :i,
15
+ [:id, :now] => :i,
16
+ [:type, :type_str] => proc {|val| val == 1 || val == 'bid' ? :bid : :ask}
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ require 'mtgox/models/model'
2
+ require 'mtgox/price_ticker'
3
+
4
+ module MtGox
5
+ module Models
6
+ # Multi-currency Ticker
7
+ class MultiTicker < Model
8
+ include PriceTicker
9
+ prop :currency,
10
+ [:vol, :volume] => proc { |val| val['value'].to_f },
11
+ [:last, :price] => proc { |val| val['value'].to_f },
12
+ :last_local => proc { |val| val['value'].to_f },
13
+ :last_orig => proc { |val| val['value'].to_f },
14
+ :last_all => proc { |val| val['value'].to_f },
15
+ :buy => proc { |val| val['value'].to_f },
16
+ :sell => proc { |val| val['value'].to_f },
17
+ :high => proc { |val| val['value'].to_f },
18
+ :low => proc { |val| val['value'].to_f },
19
+ :avg => proc { |val| val['value'].to_f },
20
+ :vwap => proc { |val| val['value'].to_f }
21
+ end
22
+ end
23
+ end
@@ -10,7 +10,7 @@ module MtGox
10
10
  :dark,
11
11
  :priority,
12
12
  [:id, :oid] => :i, # Order ID
13
- :date => proc { |val| Time.at val } # 1326655184
13
+ [:date, :time] => proc { |val| Time.at val } # 1326655184
14
14
 
15
15
  end
16
16
  end
@@ -15,15 +15,12 @@ module MtGox
15
15
  :amount => :f, # 10.672154
16
16
  :price => :f, # 6.81526
17
17
  [:id, :tid] => :i, # "tid"=>"1326655184087854"
18
- :date => proc { |val| Time.at val } # 1326655184
18
+ [:date, :time] => proc { |val| Time.at val } # 1326655184
19
19
 
20
- def to_s
21
- "<Trade: #{@date.strftime('%H:%M:%S')} #{ amount.round(3) } at #{ price.round(3) }"
22
- end
23
-
24
- def to_s
25
- "<Trade: #{ amount.round(3) } at #{ price.round(3) }"+
26
- " #{price_currency}/#{item} (#{trade_type}) - #{ properties } #{ primary } >"
20
+ def to_s with_date=nil
21
+ (with_date ? "#{@date.strftime('%H:%M:%S')} " : '') +
22
+ "<Trade: #{ amount.round(3) } at #{ price.round(3) }"+
23
+ " #{price_currency}/#{item} (#{trade_type}) #{ properties } #{ primary } >"
27
24
  end
28
25
 
29
26
  end
data/lib/mtgox/models.rb CHANGED
@@ -12,3 +12,7 @@ require 'mtgox/models/min_ask'
12
12
  require 'mtgox/models/sell'
13
13
  require 'mtgox/models/ticker'
14
14
  require 'mtgox/models/trade'
15
+
16
+ # Streaming API
17
+ require 'mtgox/models/depth'
18
+ require 'mtgox/models/multi_ticker'
@@ -0,0 +1 @@
1
+ {"channel":"24e67e0d-1cad-4cc0-9e7a-f8523ef460fe", "op":"private", "origin":"broadcast", "private":"depth", "depth":{"price":"6.77763", "type":2, "type_str":"bid", "volume":"0.0533162", "price_int":"677763", "volume_int":"5331620", "item":"BTC", "currency":"USD", "now":"1326807285171878", "total_volume_int":"5331620"}}
@@ -0,0 +1 @@
1
+ {"channel":"d5f06780-30a8-4a48-a2f8-7ed181b4a13f", "op":"private", "origin":"broadcast", "private":"ticker", "ticker":{"high":{"value":"7.09000", "value_int":"709000", "display":"$7.09000", "currency":"USD"}, "low":{"value":"6.51100", "value_int":"651100", "display":"$6.51100", "currency":"USD"}, "avg":{"value":"6.72804", "value_int":"672804", "display":"$6.72804", "currency":"USD"}, "vwap":{"value":"6.71887", "value_int":"671887", "display":"$6.71887", "currency":"USD"}, "vol":{"value":"107798.84280561", "value_int":"10779884280561", "display":"107,798.84280561�BTC", "currency":"BTC"}, "last_local":{"value":"6.78799", "value_int":"678799", "display":"$6.78799", "currency":"USD"}, "last":{"value":"6.78799", "value_int":"678799", "display":"$6.78799", "currency":"USD"}, "last_orig":{"value":"6.78799", "value_int":"678799", "display":"$6.78799", "currency":"USD"}, "last_all":{"value":"6.78799", "value_int":"678799", "display":"$6.78799", "currency":"USD"}, "buy":{"value":"6.76722", "value_int":"676722", "display":"$6.76722", "currency":"USD"}, "sell":{"value":"6.77000", "value_int":"677000", "display":"$6.77000", "currency":"USD"}}}
@@ -0,0 +1,50 @@
1
+ require 'helper'
2
+ require 'json'
3
+
4
+ describe 'Models as used by MtGox streaming (String.io) API' do
5
+
6
+ describe MtGox::Models::Depth do
7
+ before do
8
+ @data = JSON.parse(fixture('io-depth.json').read)['depth']
9
+ end
10
+
11
+ it "should create Depth change model from data Hash" do
12
+ depth = MtGox::Models::Depth.new @data
13
+
14
+ depth.price.should == 6.77763
15
+ depth.price_int.should == 677763
16
+ depth.volume.should == 0.0533162
17
+ depth.volume_int.should == 5331620
18
+ depth.type.should == :bid
19
+ depth.item.should == 'BTC'
20
+ depth.currency.should == 'USD'
21
+ depth.total_volume_int.should == 5331620
22
+ depth.id.should == 1326807285171878
23
+ depth.now.should == 1326807285171878
24
+ end
25
+ end
26
+
27
+ describe MtGox::Models::MultiTicker do
28
+ before do
29
+ @data = JSON.parse(fixture('io-ticker.json').read)['ticker']
30
+ end
31
+
32
+ it "should create MultiTicker from data Hash" do
33
+ ticker = MtGox::Models::MultiTicker.new @data
34
+
35
+ ticker.price.should == 6.78799
36
+ ticker.last.should == 6.78799
37
+ ticker.last_local.should == 6.78799
38
+ ticker.last_orig.should == 6.78799
39
+ ticker.last_all.should == 6.78799
40
+ ticker.high.should == 7.09000
41
+ ticker.low.should == 6.511
42
+ ticker.avg.should == 6.72804
43
+ ticker.vwap.should == 6.71887
44
+ ticker.buy.should == 6.76722
45
+ ticker.sell.should == 6.77000
46
+ ticker.volume.should == 107798.84280561
47
+ #ticker.currency.should == 'USD'
48
+ end
49
+ end
50
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mt_gox
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.7.5
5
+ version: 0.7.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Erik Michaels-Ober
@@ -154,9 +154,11 @@ files:
154
154
  - lib/mtgox/models/balance.rb
155
155
  - lib/mtgox/models/bid.rb
156
156
  - lib/mtgox/models/buy.rb
157
+ - lib/mtgox/models/depth.rb
157
158
  - lib/mtgox/models/max_bid.rb
158
159
  - lib/mtgox/models/min_ask.rb
159
160
  - lib/mtgox/models/model.rb
161
+ - lib/mtgox/models/multi_ticker.rb
160
162
  - lib/mtgox/models/offer.rb
161
163
  - lib/mtgox/models/order.rb
162
164
  - lib/mtgox/models/sell.rb
@@ -173,6 +175,8 @@ files:
173
175
  - spec/fixtures/cancel.json
174
176
  - spec/fixtures/depth.json
175
177
  - spec/fixtures/error.json
178
+ - spec/fixtures/io-depth.json
179
+ - spec/fixtures/io-ticker.json
176
180
  - spec/fixtures/mysql_error
177
181
  - spec/fixtures/orders.json
178
182
  - spec/fixtures/sell.json
@@ -181,6 +185,7 @@ files:
181
185
  - spec/fixtures/withdraw.json
182
186
  - spec/helper.rb
183
187
  - spec/mtgox/client_spec.rb
188
+ - spec/mtgox/streaming_spec.rb
184
189
  - spec/mtgox_spec.rb
185
190
  - tasks/doc.rake
186
191
  - tasks/gem.rake
@@ -223,6 +228,8 @@ test_files:
223
228
  - spec/fixtures/cancel.json
224
229
  - spec/fixtures/depth.json
225
230
  - spec/fixtures/error.json
231
+ - spec/fixtures/io-depth.json
232
+ - spec/fixtures/io-ticker.json
226
233
  - spec/fixtures/mysql_error
227
234
  - spec/fixtures/orders.json
228
235
  - spec/fixtures/sell.json
@@ -231,4 +238,5 @@ test_files:
231
238
  - spec/fixtures/withdraw.json
232
239
  - spec/helper.rb
233
240
  - spec/mtgox/client_spec.rb
241
+ - spec/mtgox/streaming_spec.rb
234
242
  - spec/mtgox_spec.rb