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 +4 -4
- data/.gitignore +3 -0
- data/README.md +32 -10
- data/bitshares-ruby.gemspec +4 -2
- data/lib/bitshares/account.rb +4 -2
- data/lib/bitshares/client.rb +6 -2
- data/lib/bitshares/market.rb +24 -47
- data/lib/bitshares/version.rb +1 -1
- data/lib/bitshares/wallet.rb +2 -2
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d78dd854953b6dd4587d6325f78ed684d00cc73a
|
4
|
+
data.tar.gz: 398253f2043e57805839cc50f5a6c1c7be05dc22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f847a6172160020215ebc108a63b6cd7b1ab9d0b48e07535996a328f17ec09cfc39ce062ec248c341d449ec2153a7a6cb8062208d9fcc658b0b752228c43d8d6
|
7
|
+
data.tar.gz: 16d6cdebae1a700b0c9dc6d7708d550d7a1c9611fae623ed395ed3010d9610e4ad37b5b9b4483f10913a8052251cab24a7c682ebcd7abc169d7639a6e6edd244
|
data/.gitignore
CHANGED
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
|
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
|
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
|
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
|
121
|
+
Thereafter all 'wallet_account_' client commands may be issued without specifying the account_name parameter:
|
122
122
|
```Ruby
|
123
|
-
account.balance
|
124
|
-
account.
|
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
|
-
|
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
|
-
|
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
|
data/bitshares-ruby.gemspec
CHANGED
@@ -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{
|
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
|
data/lib/bitshares/account.rb
CHANGED
@@ -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(
|
13
|
-
|
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
|
data/lib/bitshares/client.rb
CHANGED
@@ -13,8 +13,12 @@ module Bitshares
|
|
13
13
|
@@rpc_instance
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.
|
17
|
-
|
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
|
data/lib/bitshares/market.rb
CHANGED
@@ -5,22 +5,15 @@ module Bitshares
|
|
5
5
|
class AssetError < RuntimeError; end
|
6
6
|
|
7
7
|
CHAIN = Bitshares::Blockchain
|
8
|
-
|
9
|
-
BUY_ORDER_TYPES = %w(bid_order)
|
8
|
+
CLIENT = Bitshares::Client
|
10
9
|
|
11
10
|
attr_reader :quote, :base
|
12
11
|
|
13
|
-
def initialize(
|
14
|
-
|
15
|
-
@base_hash =
|
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
|
-
|
47
|
-
|
48
|
-
|
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
|
53
|
-
|
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
|
57
|
-
|
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
|
61
|
-
|
47
|
+
def method_missing(m, *args)
|
48
|
+
CLIENT::rpc.request('blockchain_market_' + m.to_s, [quote, base] + args)
|
62
49
|
end
|
63
50
|
|
64
|
-
|
65
|
-
@base_hash['precision'].to_f / @quote_hash['precision']
|
66
|
-
end
|
51
|
+
private
|
67
52
|
|
68
|
-
def
|
69
|
-
|
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
|
75
|
-
|
76
|
-
check_new_order_type(bids, BUY_ORDER_TYPES)
|
57
|
+
def order_hist
|
58
|
+
self.order_history
|
77
59
|
end
|
78
60
|
|
79
|
-
def
|
80
|
-
|
61
|
+
def multiplier
|
62
|
+
@base_hash['precision'].to_f / @quote_hash['precision']
|
81
63
|
end
|
82
64
|
|
83
|
-
def
|
84
|
-
|
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
|
-
|
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 /
|
data/lib/bitshares/version.rb
CHANGED
data/lib/bitshares/wallet.rb
CHANGED
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.
|
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
|
+
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
|
-
|
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: []
|