Browse Source

fix x/0 err

Rony 3 years ago
parent
commit
096bf3ac80
1 changed files with 6 additions and 2 deletions
  1. 6 2
      bsc_token_price.py

+ 6 - 2
bsc_token_price.py

@@ -53,7 +53,10 @@ def getPrice(contract):
     result = response.json()
     usdPrice = result['usdPrice']
     bnbPrice = int(result['nativePrice']['value'])/1000000000000000000
-    priceOfBnb = usdPrice/bnbPrice
+    try:
+        priceOfBnb = usdPrice/bnbPrice
+    except:
+        priceOfBnb = 0
     # print(contract, usdPrice, bnbPrice, priceOfBnb)
     return {'contract':contract, 'usdPrice':usdPrice}, priceOfBnb
 
@@ -64,7 +67,8 @@ def getAllPrice():
     for i in tokenList:
         info, bnb = getPrice(i)
         l.append(info)
-        bnbPrice = bnb
+        if bnb != 0:
+            bnbPrice = bnb
     l.append({'contract':BNBCONTRACT, 'usdPrice':bnbPrice})
     l.append({'contract':DEPROCONTRACT, 'usdPrice':DEPROPRICE})
     r.set(TOKENPRICE, json.dumps({'tokenPrice':l}))