Skip to content
This repository was archived by the owner on Mar 28, 2022. It is now read-only.

Commit d9371aa

Browse files
authored
Merge branch 'master' into patch-6
2 parents 495e3c0 + a2913a3 commit d9371aa

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

PumpBot.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ def marketSell(amountSell):
3535
def topupBNB(min_balance, topup):
3636
# Top up BNB balance if it drops below minimum specified balance
3737
bnb_balance = client.get_asset_balance(asset='BNB')
38+
balance=str(bnb_balance['free'])
39+
print("You have "+balance+" BNB in your wallet")
3840
bnb_balance = float(bnb_balance['free'])
3941
balancePair = 'BNB' + str(quotedCoin)
4042
if bnb_balance < min_balance:
4143
qty = round(topup - bnb_balance, 2)
42-
print("Topping up BNB wallet to avoid transaction fees")
43-
log("Getting more BNB to top-up wallet")
44+
print("Topping up BNB wallet with "+str(qty)+" BNB to avoid transaction fees")
45+
log("Getting "+str(qty)+" more BNB to top-up wallet")
4446
order = client.order_market_buy(symbol=balancePair, quantity=qty)
4547
return order
4648
return False
@@ -99,6 +101,7 @@ def quitProgram():
99101
stopLoss = float(data['stopLoss'])
100102
currentVersion = float(data['currentVersion'])
101103
endpoint = data['endpoint']
104+
fiatcurrency = data['fiatcurrency']
102105
log("config.json settings successfully loaded.")
103106

104107
# check we have the latest version
@@ -159,7 +162,7 @@ def quitProgram():
159162
# getting btc conversion
160163
response = requests.get('https://api.coindesk.com/v1/bpi/currentprice.json')
161164
data = response.json()
162-
in_USD = float((data['bpi']['USD']['rate_float']))
165+
in_USD = float((data['bpi'][fiatcurrency]['rate_float']))
163166
print("Sucessfully cached " + quotedCoin + " pairs!")
164167
log("Sucessfully cached quoted coin pairs.")
165168

@@ -196,17 +199,21 @@ def quitProgram():
196199
(_) ''')
197200
# wait until coin input
198201
print("\nInvesting amount for {}: {}".format(quotedCoin, float_to_string(AmountToSell)))
199-
print("Investing amount in USD: {}".format(float_to_string((in_USD * AmountToSell), 2)))
202+
print("Investing amount in "+fiatcurrency+": {}".format(float_to_string((in_USD * AmountToSell), 2)))
200203
log("Waiting for trading pair input.")
201204
tradingPair = input("\nCoin pair: ").upper() + quotedCoin
202205

203206
# get price for coin
204-
averagePrice = 0
205-
for ticker in averagePrices:
206-
if ticker["symbol"] == tradingPair:
207-
averagePrice = ticker["wAvgPrice"]
207+
x=next((ticker for ticker in averagePrices if ticker["symbol"] == tradingPair), {"symbol": "", "wAvgPrice":0})
208+
averagePrice = x["wAvgPrice"]
209+
208210
# if average price fails then get the current price of the trading pair (backup in case average price fails)
209-
if averagePrice == 0: averagePrice = float(client.get_avg_price(symbol=tradingPair)['price'])
211+
if averagePrice == 0:
212+
try:
213+
averagePrice = float(client.get_avg_price(symbol=tradingPair)['price'])
214+
except:
215+
print("Unable to retrieve the price of pair "+ tradingPair)
216+
quitProgram()
210217

211218
log("Calculating amount of coin to buy.")
212219
# calculate amount of coin to buy
@@ -349,4 +356,4 @@ def quitProgram():
349356
input("\nPress Enter to Exit...")
350357

351358
# quit
352-
quitProgram()
359+
quitProgram()

config.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
"profitMargin": 150,
77
"stopLoss": 0.90,
88
"endpoint": "default",
9-
"buyTimeout": 5,
10-
"sellTimeout": 10,
9+
"buyTimeout": 5,
10+
"sellTimeout": 10,
11+
"fiatcurrency": "USD",
1112

1213

1314

0 commit comments

Comments
 (0)