@@ -35,12 +35,14 @@ def marketSell(amountSell):
35
35
def topupBNB (min_balance , topup ):
36
36
# Top up BNB balance if it drops below minimum specified balance
37
37
bnb_balance = client .get_asset_balance (asset = 'BNB' )
38
+ balance = str (bnb_balance ['free' ])
39
+ print ("You have " + balance + " BNB in your wallet" )
38
40
bnb_balance = float (bnb_balance ['free' ])
39
41
balancePair = 'BNB' + str (quotedCoin )
40
42
if bnb_balance < min_balance :
41
43
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" )
44
46
order = client .order_market_buy (symbol = balancePair , quantity = qty )
45
47
return order
46
48
return False
@@ -99,6 +101,7 @@ def quitProgram():
99
101
stopLoss = float (data ['stopLoss' ])
100
102
currentVersion = float (data ['currentVersion' ])
101
103
endpoint = data ['endpoint' ]
104
+ fiatcurrency = data ['fiatcurrency' ]
102
105
log ("config.json settings successfully loaded." )
103
106
104
107
# check we have the latest version
@@ -159,7 +162,7 @@ def quitProgram():
159
162
# getting btc conversion
160
163
response = requests .get ('https://api.coindesk.com/v1/bpi/currentprice.json' )
161
164
data = response .json ()
162
- in_USD = float ((data ['bpi' ]['USD' ]['rate_float' ]))
165
+ in_USD = float ((data ['bpi' ][fiatcurrency ]['rate_float' ]))
163
166
print ("Sucessfully cached " + quotedCoin + " pairs!" )
164
167
log ("Sucessfully cached quoted coin pairs." )
165
168
@@ -196,17 +199,21 @@ def quitProgram():
196
199
(_) ''' )
197
200
# wait until coin input
198
201
print ("\n Investing 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 )))
200
203
log ("Waiting for trading pair input." )
201
204
tradingPair = input ("\n Coin pair: " ).upper () + quotedCoin
202
205
203
206
# 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
+
208
210
# 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 ()
210
217
211
218
log ("Calculating amount of coin to buy." )
212
219
# calculate amount of coin to buy
@@ -349,4 +356,4 @@ def quitProgram():
349
356
input ("\n Press Enter to Exit..." )
350
357
351
358
# quit
352
- quitProgram ()
359
+ quitProgram ()
0 commit comments