bitshares 0.1.3.pre → 0.1.4.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5abeb08a0df5d7e8dc67c611ddb45d0032e9277
4
- data.tar.gz: 438ac564de494dc95c61f97ab45ae04b9a6dd08c
3
+ metadata.gz: d78dd854953b6dd4587d6325f78ed684d00cc73a
4
+ data.tar.gz: 398253f2043e57805839cc50f5a6c1c7be05dc22
5
5
  SHA512:
6
- metadata.gz: 036523ba906162a2a4c19ee4e22bbcdd285bebfcea283238330d07172d03f67ca55bcc1bed43eeed231d4bd700b8ea926eddea9bdcf840652eea47a8a94623f0
7
- data.tar.gz: 68a70ade2b49f1c6318062d1a1875535bf8bb9f0e14dcc4ce66ee65ab10db5bec2d376ca886ea0ed7f15317a700e4d392dac643a97ab408ad31ef03a278fb922
6
+ metadata.gz: f847a6172160020215ebc108a63b6cd7b1ab9d0b48e07535996a328f17ec09cfc39ce062ec248c341d449ec2153a7a6cb8062208d9fcc658b0b752228c43d8d6
7
+ data.tar.gz: 16d6cdebae1a700b0c9dc6d7708d550d7a1c9611fae623ed395ed3010d9610e4ad37b5b9b4483f10913a8052251cab24a7c682ebcd7abc169d7639a6e6edd244
data/.gitignore CHANGED
@@ -1,6 +1,9 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
3
  /Gemfile.lock
4
+ /Guardfile
5
+ /bin/guard
6
+ /bin/_guard-core
4
7
  /_yardoc/
5
8
  /coverage/
6
9
  /doc/
data/README.md CHANGED
@@ -47,7 +47,7 @@ Bitshares.configure(:wallet => {:name => 'wallet2', :password => 'password2'})
47
47
 
48
48
  **From a Yaml configuration file**
49
49
  ```Ruby
50
- Bitshares.configure_with(<path to Yaml file>)
50
+ Bitshares.configure_with 'path-to-Yaml-file'
51
51
  ```
52
52
 
53
53
  ```Ruby
@@ -82,7 +82,7 @@ Data is returned as a hash
82
82
  The blockchain is implemented as a class purely for convenience when calling 'blockchain_' methods:
83
83
  ```Ruby
84
84
  chain = Bitshares::Blockchain
85
- count = chain.get_block_count # equivalent to `client.blockchain_get_block_count`
85
+ count = chain.get_block_count # equivalent to client.blockchain_get_block_count
86
86
  ```
87
87
 
88
88
  **Wallet**
@@ -114,14 +114,19 @@ wallet.unlocked?
114
114
 
115
115
  **Account**
116
116
 
117
- Once you have a wallet instance you can do this:
117
+ Once you have a wallet instance you can do the following, which references a particular wallet account:
118
118
  ```Ruby
119
119
  account = wallet.account 'account_name'
120
120
  ```
121
- Thereafter 'wallet_account_' commands may be issued like this:
121
+ Thereafter all 'wallet_account_' client commands may be issued without specifying the account_name parameter:
122
122
  ```Ruby
123
- account.balance
124
- account.register(account_name, pay_from)
123
+ account.balance # balance for a particular account
124
+ account.order_list # optional [limit] param
125
+ account_register(pay_from_account [, optional params]) # this command takes up to 3 optional params
126
+ ```
127
+ 'wallet_account_' client commands taking an *optional* account_name parameter list all data for all of a wallet's accounts. If this is required, the relevant Wallet method should be used - e.g:
128
+ ```Ruby
129
+ wallet.account_balance # lists the balances for all accounts for this wallet (c.c. above)
125
130
  ```
126
131
 
127
132
  **Market**
@@ -130,23 +135,40 @@ The market class represents the trading (order book and history) for a given an
130
135
  ```Ruby
131
136
  market = Bitshares::Market.new('CNY', 'BTS')
132
137
  ```
133
- Any 'blockchain_market_' client method may then be used without specifying the quote and base assets again e.g:
138
+ The following 'blockchain_market_' client methods may then be used without specifying the quote and base assets again, but with any other optional params the client accepts:
134
139
  ```Ruby
140
+ market.list_asks # equivalent to blockchain_market_list_asks(quote, base) [limit]
135
141
  market.list_bids
142
+ market.list_covers
143
+ market.order_book
136
144
  market.order_history
145
+ market.price_history # required params are: <start time> <duration> optional: [granularity]
146
+
147
+ market.list_shorts # requires no params and ignores the base asset
148
+ get_asset_collateral # requires no params and returns the collateral for the quote asset (ignores the base asset)
137
149
  ```
138
150
 
139
- ## Testing and specification
151
+ Additionally, the following methods are available:
152
+ ```Ruby
153
+ market.lowest_ask
154
+ market.highest_bid
155
+ market.mid_price # mean of the above
156
+ market.last_fill # price of the last filled order
157
+ ```
158
+
159
+ ## Specification & tests
160
+
161
+ For the full specification please clone this repo and run:
140
162
 
141
163
  `rake spec`
142
164
 
143
165
  _Important:_ There is currently no sandbox, so the test suite runs on your live client. If this concerns you - and it should :scream: - feel free to browse the code. In particular, the following client 'fixtures' are required for the full test suite to run and pass:
144
166
 
145
- An empty wallet 'test1', with password 'password1'
167
+ An empty wallet 'test1', with password 'password1' and an account called 'account-test' (please don't register this account!)
146
168
 
147
169
  ## Contributing
148
170
 
149
- Bug reports and pull requests are welcome on GitHub at https://github.com/MatzFan/bitshares-ruby.
171
+ Bug reports and pull requests (and feature requests) are welcome on GitHub at https://github.com/MatzFan/bitshares-ruby.
150
172
 
151
173
 
152
174
  ## License
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.authors = ['Bruce Steedman']
10
10
  s.email = ['bruce.steedman@gmail.com']
11
11
 
12
- s.summary = %q{Ruby API for BitShares client}
13
- s.description = %q{Exposes the BitShares client commands via RPC interface}
12
+ s.summary = %q{Ruby API for BitShares CLI client}
13
+ s.description = %q{Ruby API for BitShares CLI client}
14
14
  s.license = "MIT"
15
15
 
16
16
  s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
@@ -21,4 +21,6 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency 'bundler', '~> 1.10'
22
22
  s.add_development_dependency 'rake', '~> 10.0'
23
23
  s.add_development_dependency 'rspec', '~> 3.0'
24
+ s.add_development_dependency 'guard-rspec', '~> 4.0'
25
+ s.add_development_dependency 'growl', '~> 1.0'
24
26
  end
@@ -2,6 +2,8 @@ module Bitshares
2
2
 
3
3
  class Account
4
4
 
5
+ CLIENT = Bitshares::Client
6
+
5
7
  attr_reader :wallet, :name
6
8
 
7
9
  def initialize(wallet, name)
@@ -9,8 +11,8 @@ module Bitshares
9
11
  @name = name
10
12
  end
11
13
 
12
- def method_missing(name, *args)
13
- Bitshares::Client::rpc.request('wallet_account_' + name.to_s, args)
14
+ def method_missing(m, *args)
15
+ CLIENT::rpc.request('wallet_account_' + m.to_s, [name] + args)
14
16
  end
15
17
 
16
18
  end
@@ -13,8 +13,12 @@ module Bitshares
13
13
  @@rpc_instance
14
14
  end
15
15
 
16
- def self.method_missing(method, *args)
17
- @@rpc_instance.request(method, args)
16
+ def self.synced?
17
+ blockchain_get_block_count >= self.get_info['blockchain_head_block_num']
18
+ end
19
+
20
+ def self.method_missing(m, *args)
21
+ @@rpc_instance.request(m, args)
18
22
  end
19
23
 
20
24
  class Rpc
@@ -5,22 +5,15 @@ module Bitshares
5
5
  class AssetError < RuntimeError; end
6
6
 
7
7
  CHAIN = Bitshares::Blockchain
8
- SELL_ORDER_TYPES = %w(ask_order cover_order)
9
- BUY_ORDER_TYPES = %w(bid_order)
8
+ CLIENT = Bitshares::Client
10
9
 
11
10
  attr_reader :quote, :base
12
11
 
13
- def initialize(quote_symbol, base_symbol)
14
- @quote_hash = get_asset quote_symbol.upcase
15
- @base_hash = get_asset base_symbol.upcase
12
+ def initialize(quote, base)
13
+ [quote, base].each &:upcase!
14
+ @quote_hash, @base_hash = asset(quote), asset(base)
15
+ @quote, @base = @quote_hash['symbol'], @base_hash['symbol']
16
16
  @multiplier = multiplier
17
- @quote = @quote_hash['symbol']
18
- @base = @base_hash['symbol']
19
- @order_book = order_book
20
- end
21
-
22
- def center_price
23
- market_status['center_price']['ratio'].to_f
24
17
  end
25
18
 
26
19
  def last_fill
@@ -28,11 +21,6 @@ module Bitshares
28
21
  order_hist.first['bid_index']['order_price']['ratio'].to_f * multiplier
29
22
  end
30
23
 
31
- def mid_price
32
- return nil if highest_bid.nil? || lowest_ask.nil?
33
- (highest_bid + lowest_ask) / 2
34
- end
35
-
36
24
  def lowest_ask
37
25
  return if asks.empty?
38
26
  price asks.first
@@ -43,54 +31,43 @@ module Bitshares
43
31
  price bids.first
44
32
  end
45
33
 
46
- private
47
-
48
- def get_asset(s)
49
- CHAIN.get_asset(s) || (raise AssetError, "No such asset: #{s}")
34
+ def mid_price
35
+ return nil if highest_bid.nil? || lowest_ask.nil?
36
+ (highest_bid + lowest_ask) / 2
50
37
  end
51
38
 
52
- def market_status
53
- CHAIN.market_status(@quote, @base)
39
+ def list_shorts(limit = nil) # uses quote only, not base
40
+ CLIENT::rpc.request('blockchain_market_list_shorts', [quote] + [limit])
54
41
  end
55
42
 
56
- def order_book
57
- CHAIN.market_order_book(@quote, @base)
43
+ def get_asset_collateral # uses quote only, not base
44
+ CLIENT::rpc.request('blockchain_market_get_asset_collateral', [quote])
58
45
  end
59
46
 
60
- def order_hist
61
- CHAIN.market_order_history(@quote, @base)
47
+ def method_missing(m, *args)
48
+ CLIENT::rpc.request('blockchain_market_' + m.to_s, [quote, base] + args)
62
49
  end
63
50
 
64
- def multiplier
65
- @base_hash['precision'].to_f / @quote_hash['precision']
66
- end
51
+ private
67
52
 
68
- def check_new_order_type(order_list, order_types)
69
- new_ = order_list.reject { |p| order_types.any? { |t| p['type'] == t } }
70
- raise AssetError, "New order type: #{new_.first}" unless new_.empty?
71
- order_list
53
+ def asset(symbol) # returns hash
54
+ CHAIN.get_asset(symbol) || (raise AssetError, "Invalid asset: #{symbol}")
72
55
  end
73
56
 
74
- def buy_orders
75
- bids = @order_book.first
76
- check_new_order_type(bids, BUY_ORDER_TYPES)
57
+ def order_hist
58
+ self.order_history
77
59
  end
78
60
 
79
- def bids
80
- buy_orders.select { |p| p['type'] == 'bid_order' }
61
+ def multiplier
62
+ @base_hash['precision'].to_f / @quote_hash['precision']
81
63
  end
82
64
 
83
- def sell_orders # includes 'ask_type' and 'cover_type'
84
- asks = @order_book.last
85
- check_new_order_type(asks, SELL_ORDER_TYPES)
65
+ def bids
66
+ self.list_bids
86
67
  end
87
68
 
88
69
  def asks
89
- sell_orders.select { |p| p['type'] == 'ask_order' }
90
- end
91
-
92
- def covers
93
- sell_orders.select { |p| p['type'] == 'cover_order' }
70
+ self.list_asks
94
71
  end
95
72
 
96
73
  def price(order) # CARE: preserve float precision with * NOT /
@@ -1,3 +1,3 @@
1
1
  module Bitshares
2
- VERSION = '0.1.3.pre'
2
+ VERSION = '0.1.4.pre'
3
3
  end
@@ -45,8 +45,8 @@ module Bitshares
45
45
  !unlocked?
46
46
  end
47
47
 
48
- def method_missing(name, *args)
49
- Bitshares::Client::rpc.request('wallet_' + name.to_s, args)
48
+ def method_missing(m, *args)
49
+ Bitshares::Client::rpc.request('wallet_' + m.to_s, args)
50
50
  end
51
51
 
52
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitshares
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3.pre
4
+ version: 0.1.4.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruce Steedman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2015-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,35 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- description: Exposes the BitShares client commands via RPC interface
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: growl
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ description: Ruby API for BitShares CLI client
56
84
  email:
57
85
  - bruce.steedman@gmail.com
58
86
  executables: []
@@ -99,5 +127,5 @@ rubyforge_project:
99
127
  rubygems_version: 2.4.8
100
128
  signing_key:
101
129
  specification_version: 4
102
- summary: Ruby API for BitShares client
130
+ summary: Ruby API for BitShares CLI client
103
131
  test_files: []