poloapi 1.0.1 → 1.0.2
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/examples/lending.rb +48 -22
- data/lib/poloapi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19662735efb5e40605a6dae34a14013eb1f8a4d3
|
4
|
+
data.tar.gz: cf5696a0be2032aef2205cca9ebe82018dba93ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d262cc00f8d9313973fac535cb343ce27f177b8db58b415cbabddb513f2592b646a5bacf7489233d9b3c625f744a0eba57c65414471379b42621ac0ce1f2445
|
7
|
+
data.tar.gz: dfb2b3c80b3894204a87acc7494881b96b7d3e23b181a86c661e52cab26ea060fd01fd6f69f840a281fea45e276ff0d7018bc2f85c79f2b535790199f6c5b173
|
data/examples/lending.rb
CHANGED
@@ -10,12 +10,15 @@ require 'bigdecimal'
|
|
10
10
|
|
11
11
|
require 'pp'
|
12
12
|
|
13
|
+
# require 'pry'
|
14
|
+
|
13
15
|
|
14
16
|
$PRGNAME="lending"
|
15
17
|
$options = {}
|
16
18
|
$options['loglevel'] = 'WARN'
|
17
|
-
# $options['loglevel'] = "INFO"
|
18
19
|
$options['logname'] = nil
|
20
|
+
$options['dryrun'] = false
|
21
|
+
$options['singleloop'] = false
|
19
22
|
|
20
23
|
# $options['maxordertime']=300
|
21
24
|
$options['maxordertime']=1500
|
@@ -29,8 +32,10 @@ $options['loanmin'] = 0.0001 # global loan minimum rate
|
|
29
32
|
$options['loanmincur']= {'BTC' => 0.0003000, 'ETH' => 0.0002 } # minimum rate per currency
|
30
33
|
$options['loanmaxorderamount'] = '1.32' # in front of which max order to put
|
31
34
|
$options['loanmaxorderamountcur'] = {'BTC' => 1.32, 'ETH' => 10.1 }
|
32
|
-
$options['
|
33
|
-
$options['
|
35
|
+
$options['loanmaxordersum'] = '3'
|
36
|
+
$options['loanmaxordersumcur'] = {'BTC' => 3.00, 'ETH' => 10.0 }
|
37
|
+
|
38
|
+
$options['loanorderdeduct'] = '0.000001' # how much to deduct from wall order (to execute order before order wall)
|
34
39
|
|
35
40
|
# helpful class for logger
|
36
41
|
class MultiDelegator
|
@@ -87,6 +92,17 @@ OptionParser.new do |opts|
|
|
87
92
|
$log.level = Logger::INFO
|
88
93
|
end
|
89
94
|
|
95
|
+
opts.on("-1", "--[no-]singleloop", "Perform single loop") do |v|
|
96
|
+
$options['singleloop'] = v
|
97
|
+
end
|
98
|
+
|
99
|
+
opts.on("-r", "--[no-]report", "Report only in single loop") do |v|
|
100
|
+
$options['report'] = v
|
101
|
+
$options['singleloop'] = v
|
102
|
+
$options['dryrun'] = v
|
103
|
+
$log.level = Logger::INFO
|
104
|
+
end
|
105
|
+
|
90
106
|
opts.on("-d", "--[no-]debug", "Run in debug mode") do |v|
|
91
107
|
$options['debug'] = v
|
92
108
|
$log.level = Logger::DEBUG
|
@@ -147,11 +163,15 @@ def getBestPossibleLoanOrder(curid)
|
|
147
163
|
numloanoffers = loanorders["offers"].count
|
148
164
|
exorder = loanorders["offers"].first
|
149
165
|
bestorder = loanorders["offers"].last
|
166
|
+
sumamount = BigDecimal.new('0.0')
|
167
|
+
maxsumamount = BigDecimal.new($options['loanmaxordersum'])
|
150
168
|
loanorders["offers"].each_with_index do |offer,offid|
|
151
|
-
|
152
|
-
|
169
|
+
sumamount=sumamount+BigDecimal.new(offer['amount'])
|
170
|
+
if offer["amount"] > $options['loanmaxorderamount'] or (not $options['loanmaxordersum'].nil? and sumamount > maxsumamount) then
|
171
|
+
bestorder = offer.dup
|
153
172
|
# bestorder['rate'] = (bestorder['rate'].to_f - 0.00000001).to_s
|
154
|
-
|
173
|
+
bestrate=(BigDecimal.new(bestorder['rate'])) - (BigDecimal.new($options['loanorderdeduct']))
|
174
|
+
bestorder['rate'] = bestrate.to_s('F')
|
155
175
|
$log.info("Looking best possible place, With #{numloanoffers} order(s), best possible order is (skipped #{offid}): #{bestorder['rate']}, higher is #{offer['rate']} with amount #{offer['amount']}")
|
156
176
|
break
|
157
177
|
else
|
@@ -175,10 +195,7 @@ def getMinLoanOrder(curid,options)
|
|
175
195
|
return minorder
|
176
196
|
end
|
177
197
|
|
178
|
-
|
179
|
-
$log.info("Starting loop")
|
180
|
-
|
181
|
-
begin
|
198
|
+
def mainLoop()
|
182
199
|
myofferloans=JSON.parse(Poloapi.post('returnOpenLoanOffers'))
|
183
200
|
unless myofferloans.nil?
|
184
201
|
myofferloans.each do |cur,items|
|
@@ -263,10 +280,13 @@ unless mybalances.nil? or mybalances.empty?
|
|
263
280
|
orderstate="Minimum reached: #{minorder}."
|
264
281
|
loanorder=minorder
|
265
282
|
end
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
283
|
+
if $options['dryrun'] then
|
284
|
+
$log.warn("Dry run - #{orderstate} Not creating lend offer for #{cur[0]} #{cur[1]} with rate #{loanorder}")
|
285
|
+
else
|
286
|
+
$log.warn("#{orderstate} Creating lend offer for #{cur[0]} #{cur[1]} with rate #{loanorder}")
|
287
|
+
loanorders=JSON.parse(Poloapi.post('createLoanOffer', {:currency => cur[0], :amount => cur[1], :duration => $options['loanduration'], :autoRenew => $options['loanautorenew'], :lendingRate => loanorder}))
|
288
|
+
$log.info(loanorders.to_s)
|
289
|
+
end
|
270
290
|
end
|
271
291
|
end
|
272
292
|
else
|
@@ -317,13 +337,19 @@ unless myactloans["provided"].nil?
|
|
317
337
|
end
|
318
338
|
end
|
319
339
|
|
320
|
-
|
321
|
-
$log.warn("Error #{$!}: #{e.backtrace}")
|
322
|
-
end
|
340
|
+
end # mainLoop()
|
323
341
|
|
324
|
-
|
325
|
-
|
342
|
+
if $options['singleloop'] then
|
343
|
+
mainLoop()
|
344
|
+
else
|
345
|
+
while true
|
346
|
+
$log.info("Starting loop")
|
347
|
+
begin
|
348
|
+
mainLoop()
|
349
|
+
rescue StandardError => e
|
350
|
+
$log.warn("Error #{$!}: #{e.backtrace}")
|
351
|
+
end
|
352
|
+
$log.info("Finishing up and sleeping for #{$options['sleeploop']}")
|
353
|
+
sleep $options['sleeploop']
|
354
|
+
end
|
326
355
|
end
|
327
|
-
|
328
|
-
|
329
|
-
|
data/lib/poloapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poloapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlatko Kosturjak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|