mpex 0.4.6 → 0.5.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/mpex/cli.rb +16 -1
- data/lib/mpex/irc.rb +10 -1
- data/lib/mpex/mpex.rb +21 -4
- data/lib/mpex/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 658fe66b10c2a22bcfa1eada43373cad3bd62f74
|
4
|
+
data.tar.gz: a99ab6a7c1cfcd058f4e4f6430c651286d8ea6d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdfbe7c29b3622eb97223f26847b7ac06d1a012b7e9e91c5c2eb207287d3b2ea7463e75b96dc21c01a74ca955cba3d665fc5931c370e07af382e760fe47a31f1
|
7
|
+
data.tar.gz: 25cba8ee8577f4b39a51a0629467ff3f635e3e0f2c5b9f24f2561ce6ba860fe43ed86d4dd5a62f4992ba9ba652e0efaa87b9e80b6f08aabc2200f98974a16671
|
data/Gemfile.lock
CHANGED
data/lib/mpex/cli.rb
CHANGED
@@ -161,10 +161,25 @@ end
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
+
@cmd.define_command do
|
165
|
+
name 'portfolio'
|
166
|
+
usage 'portfolio [options]'
|
167
|
+
summary ""
|
168
|
+
|
169
|
+
run do |opts, args|
|
170
|
+
mpex = Mpex::Mpex.new
|
171
|
+
mpex.send_plain('STATJSON', opts) do |stat|
|
172
|
+
mpex.portfolio(opts, JSON.parse(stat)) do |portfolio|
|
173
|
+
puts portfolio
|
174
|
+
end if stat
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
164
179
|
@cmd.define_command do
|
165
180
|
name 'orderbook'
|
166
181
|
usage 'orderbook [options]'
|
167
|
-
summary "show
|
182
|
+
summary "show MPEx orderbook"
|
168
183
|
|
169
184
|
run do |opts, args|
|
170
185
|
mpex = Mpex::Mpex.new
|
data/lib/mpex/irc.rb
CHANGED
@@ -48,6 +48,7 @@ module Mpex
|
|
48
48
|
def send_encrypted(message, &block)
|
49
49
|
res = Net::HTTP.post_form(URI.parse("http://dpaste.com/api/v1/"), { 'content' => "#{message}" })
|
50
50
|
dpaste_url = res['Location']
|
51
|
+
puts "[IRC] Messaging #{ASSBOT}: !mp #{dpaste_url}"
|
51
52
|
@irc.msg(ASSBOT, "!mp " + dpaste_url)
|
52
53
|
|
53
54
|
status = Timeout::timeout(TIMEOUT) {
|
@@ -60,6 +61,7 @@ module Mpex
|
|
60
61
|
if @last_message
|
61
62
|
answer = handle_assbot_incoming(@last_message[:message])
|
62
63
|
if answer
|
64
|
+
puts "[IRC] #{ASSBOT} answered: #{@last_message[:message]}"
|
63
65
|
@last_message = nil
|
64
66
|
return answer
|
65
67
|
end
|
@@ -75,6 +77,7 @@ module Mpex
|
|
75
77
|
end
|
76
78
|
|
77
79
|
def vwap(&block)
|
80
|
+
puts "[IRC] Messaging #{MPEXBOT}: $vwap"
|
78
81
|
@irc.msg MPEXBOT, '$vwap'
|
79
82
|
|
80
83
|
status = Timeout::timeout(TIMEOUT) {
|
@@ -83,6 +86,7 @@ module Mpex
|
|
83
86
|
end
|
84
87
|
|
85
88
|
def depth(&block)
|
89
|
+
puts "[IRC] Messaging #{MPEXBOT}: $depth"
|
86
90
|
@irc.msg MPEXBOT, '$depth'
|
87
91
|
|
88
92
|
status = Timeout::timeout(TIMEOUT) {
|
@@ -91,6 +95,7 @@ module Mpex
|
|
91
95
|
end
|
92
96
|
|
93
97
|
def list_proxies(&block)
|
98
|
+
puts "[IRC] Messaging #{MPEXBOT}: $proxies"
|
94
99
|
@irc.msg MPEXBOT, '$proxies'
|
95
100
|
|
96
101
|
status = Timeout::timeout(TIMEOUT) {
|
@@ -103,6 +108,7 @@ module Mpex
|
|
103
108
|
if @last_message
|
104
109
|
answer = @last_message[:message]
|
105
110
|
if answer
|
111
|
+
puts "[IRC] #{MPEXBOT} answered: #{@last_message[:message]}"
|
106
112
|
@last_message = nil
|
107
113
|
return answer
|
108
114
|
end
|
@@ -115,6 +121,7 @@ module Mpex
|
|
115
121
|
if @last_message
|
116
122
|
answer = handle_mpexbot_incoming(@last_message[:message])
|
117
123
|
if answer
|
124
|
+
puts "[IRC] #{MPEXBOT} answered: #{@last_message[:message]}"
|
118
125
|
@last_message = nil
|
119
126
|
return answer
|
120
127
|
end
|
@@ -123,10 +130,12 @@ module Mpex
|
|
123
130
|
end
|
124
131
|
|
125
132
|
def handle_mpexbot_incoming(msg)
|
126
|
-
if msg.
|
133
|
+
if msg.match(/http:\/\/pastebin\.com\/\d+/)
|
127
134
|
id = URI.parse(msg).path[1..-1]
|
128
135
|
uri = URI.parse("http://pastebin.com/raw.php?i=" + id)
|
129
136
|
return Net::HTTP.get(uri)
|
137
|
+
elsif msg.start_with?("http://pastebin.com/raw.php")
|
138
|
+
return Net::HTTP.get(URI.parse(msg))
|
130
139
|
end
|
131
140
|
end
|
132
141
|
|
data/lib/mpex/mpex.rb
CHANGED
@@ -114,12 +114,14 @@ module Mpex
|
|
114
114
|
orders_value
|
115
115
|
end
|
116
116
|
|
117
|
-
def fetch_mpex_vwaps(url, &block)
|
117
|
+
def fetch_mpex_vwaps(url=nil, opts=nil, &block)
|
118
|
+
vwaps = ""
|
118
119
|
if $IRC_LEAK && $IRC_LEAK.connected?
|
119
120
|
$IRC_LEAK.vwap do |resp|
|
120
121
|
vwaps = JSON.parse(resp)
|
121
122
|
end
|
122
123
|
else
|
124
|
+
url = url ? url : verify_opts_present(opts, [ :url ])[:url]
|
123
125
|
vwaps_raw = Http.get(url, "/mpex-vwap.php")
|
124
126
|
vwaps = JSON.parse(vwaps_raw)
|
125
127
|
end
|
@@ -173,13 +175,26 @@ module Mpex
|
|
173
175
|
vwap_valuation = holdings_value + orders_vwap_sum(stat, vwaps)
|
174
176
|
|
175
177
|
portfolio = <<-PORTFOLIO
|
176
|
-
|
177
|
-
|
178
|
+
Holdings:
|
179
|
+
#{holdings_formatted(stat)}
|
180
|
+
Totals:
|
181
|
+
Your optimistic valuation: #{Converter.satoshi_to_btc(optimistic_value)}"
|
182
|
+
VWAP valuation: #{Converter.satoshi_to_btc(vwap_valuation)}
|
178
183
|
PORTFOLIO
|
179
184
|
yield portfolio
|
180
185
|
end
|
181
186
|
end
|
182
187
|
|
188
|
+
def holdings_formatted(stat)
|
189
|
+
holdings = ""
|
190
|
+
stat["Holdings"].each do |h|
|
191
|
+
mpsic = h.keys.first
|
192
|
+
amount = mpsic == "CxBTC" ? Converter.satoshi_to_btc(h[h.keys.first]) : h[h.keys.first]
|
193
|
+
holdings = holdings + " #{mpsic}: #{amount}\n" unless h.keys.first == "md5Checksum"
|
194
|
+
end
|
195
|
+
holdings
|
196
|
+
end
|
197
|
+
|
183
198
|
def holdings_avg_value(stat, vwaps)
|
184
199
|
# TODO improve!
|
185
200
|
holdings_value = stat["Holdings"].map do |h|
|
@@ -188,7 +203,9 @@ module Mpex
|
|
188
203
|
elsif h["S.MPOE"]
|
189
204
|
h["S.MPOE"].to_i*vwaps["S.MPOE"]["1d"]["avg"].to_i
|
190
205
|
elsif h["S.DICE"]
|
191
|
-
h["S.DICE"].to_i*vwaps["S.
|
206
|
+
h["S.DICE"].to_i*vwaps["S.BBET"]["1d"]["avg"].to_i
|
207
|
+
elsif h["S.BBET"]
|
208
|
+
h["S.BBET"].to_i*vwaps["S.BBET"]["1d"]["avg"].to_i
|
192
209
|
else
|
193
210
|
0
|
194
211
|
end
|
data/lib/mpex/version.rb
CHANGED