-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathupdate_loan_offers.py
69 lines (52 loc) · 1.59 KB
/
update_loan_offers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""update_loan_offers
Usage:
update_loan_offers
update_loan_offers --debug
update_loan_offers (-h | --help)
Options:
-h --help Show this screen.
--debug Dry run verbose mode.
"""
from docopt import docopt
import os
from poloniex import Poloniex
BTC_PER_BIG_OFFER = 10.0
DEBUG = False
LOAN_DURATION = 2
def main():
"""
Algorithm:
If unused BTC:
get min big loan offer
Offer unused BTC at (min loan offer - 0.0001%)
"""
global DEBUG
args = docopt(__doc__)
if args['--debug']:
DEBUG = True
api_key = os.environ.get('POLONIEX_API_KEY')
secret = os.environ.get('POLONIEX_SECRET')
poloniex = Poloniex(api_key=api_key, secret=secret)
unused_btc = poloniex.get_unused()
if DEBUG:
print "Unused BTC:", unused_btc
if unused_btc:
min_big_offer = poloniex.get_min_offer_rate(BTC_PER_BIG_OFFER)
# Get 0.0001% below
my_rate = min_big_offer - (0.0001 / 100)
if DEBUG:
print "poloniex.offer_btc_loan({}, {}, {})".format(
my_rate, unused_btc, LOAN_DURATION)
else:
# Place the actual order
order_id = poloniex.offer_btc_loan(my_rate,
unused_btc,
LOAN_DURATION)
# Order status
if order_id:
print "Order placed ({})".format(order_id),
else:
print "Order failed",
print "(Rate:", my_rate * 100, "%, Amount:", unused_btc, "BTC)"
if __name__ == "__main__":
main()