Explorar o código

add other token

Rony %!s(int64=2) %!d(string=hai) anos
pai
achega
4b4b3accd2

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 8 - 0
.idea/bsc_token_price.iml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 6 - 0
.idea/inspectionProfiles/profiles_settings.xml

@@ -0,0 +1,6 @@
+<component name="InspectionProjectProfileManager">
+  <settings>
+    <option name="USE_PROJECT_PROFILE" value="false" />
+    <version value="1.0" />
+  </settings>
+</component>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/bsc_token_price.iml" filepath="$PROJECT_DIR$/.idea/bsc_token_price.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 18 - 11
bsc_token_price.py

@@ -12,7 +12,7 @@ WITHDRAWFEEUSD = 0.5 #提现手续费,标的是usdt单位
 WITHDRAWCOUNTBYFEE = 2 #提现所需对应手续费token数量的倍数
 
 
-TOKENPRICE = 'TOKENPRICE'
+TOKENPRICE = 'TOKENPRICE_'
 TOKENPRICEDICT = 'TOKENPRICEDICT'
 TOKENWITHDRAW = 'TOKENWITHDRAW'
 
@@ -30,9 +30,9 @@ REDIS_TEST = 'denet-test.y2slbl.clustercfg.memorydb.us-east-1.amazonaws.com'
 REDIS_ONLINE = 'denet-chain-prod.y2slbl.clustercfg.memorydb.us-east-1.amazonaws.com'
 r = RedisCluster(host=REDIS_ONLINE, port=6379, decode_responses=True, skip_full_coverage_check=True)
 
-def getTokenList():
+def getTokenList(fp):
     l = []
-    with open('/home/sh/token.txt') as f:
+    with open(fp) as f:
     #with open('token.txt') as f:
         for line in f:
             l.append(line.strip())
@@ -50,10 +50,17 @@ def getPrice(contract):
 
     response = requests.get(f'https://deep-index.moralis.io/api/v2/erc20/{contract}/price', headers=headers,
                             params=params)
+    print(contract,response)
     result = response.json()
     print(result)
-    usdPrice = result['usdPrice']
-    bnbPrice = int(result['nativePrice']['value'])/1000000000000000000
+    try:
+        usdPrice = result['usdPrice']
+        bnbPrice = int(result['nativePrice']['value'])/1000000000000000000
+    except:
+        if contract == '0xfc9F81B107F51F2383fCE56650fEDB59C5fd59bD':
+            usdPrice = 0.24
+            bnbPrice = 0.00074
+
     try:
         priceOfBnb = usdPrice/bnbPrice
     except:
@@ -61,10 +68,10 @@ def getPrice(contract):
     # print(contract, usdPrice, bnbPrice, priceOfBnb)
     return {'contract':contract, 'usdPrice':usdPrice}, priceOfBnb
 
-def getAllPrice():
+def getAllPrice(chain, fp):
     l = []
     bnbPrice = 0
-    tokenList = getTokenList()
+    tokenList = getTokenList(fp)
     for i in tokenList:
         time.sleep(1)
         info, bnb = getPrice(i)
@@ -73,12 +80,12 @@ def getAllPrice():
             bnbPrice = bnb
     l.append({'contract':BNBCONTRACT, 'usdPrice':bnbPrice})
     l.append({'contract':DEPROCONTRACT, 'usdPrice':DEPROPRICE})
-    r.set(TOKENPRICE, json.dumps({'tokenPrice':l}))
+    r.set(TOKENPRICE+chain, json.dumps({'tokenPrice':l}))
     return l
 
-def getWithdrawFees():
+def getWithdrawFees(chain, fp):
     l = []
-    priceList = getAllPrice()
+    priceList = getAllPrice(chain, fp)
     for i in priceList:
        print(i)
        contract = i['contract']
@@ -88,7 +95,7 @@ def getWithdrawFees():
     r.set(TOKENWITHDRAW, json.dumps({'tokenWithdraw':l}))
     return l
 
-getWithdrawFees()
+getWithdrawFees("BSC", '/home/sh/token.txt')
 
 print(r.get(TOKENPRICE))
 print(r.get(TOKENWITHDRAW))

+ 13 - 0
parse_price.py

@@ -0,0 +1,13 @@
+import requests
+from bs4 import BeautifulSoup
+
+req = requests.get('https://www.coingecko.com/zh/%E6%95%B0%E5%AD%97%E8%B4%A7%E5%B8%81/bikerush')
+soup = BeautifulSoup(req.content, 'html.parser')
+soup.prettify()
+anchors = soup.findAll('div', class_='tw-text-gray-500 text-normal dark:tw-text-white dark:tw-text-opacity-60 tw-mb-3')
+print(len(anchors))
+res = anchors[0]
+res = res.children
+for r in res:
+    print(type(r))
+    print(r)

+ 11 - 0
token.txt

@@ -58,3 +58,14 @@
 0xfe56d5892BDffC7BF58f2E84BE1b2C32D21C308b
 0x7dDEE176F665cD201F93eEDE625770E2fD911990
 0x17D749D3E2ac204a07e19D8096d9a05c423ea3af
+0x2Fb9376cFf6fb7f5fe99665aE1Ec2FdDD5099134
+0xacf34edcc424128cccc730bf85cdaceebcb3eece
+0xB139Fba9cd5BB1a550F4d096dE8D870Ecd975365
+0x6685c51e7d8a2b29b9cd87cd4899724c010eb64f
+0xa3c3bd63dd542bc8d0f1103b6f5915afd611e76f
+0x662590048e99880eefb79e0a04fbbc94a8ed894e
+0x7eb5e5f19b52ab6e10509885e0242acdbf5d0ff4
+0x4D1532573f5E4b69296C3f792275e17f0d21d589
+0x64ef755d5a2627538caa3eb62ee07f96f9b608e4
+0xfc9F81B107F51F2383fCE56650fEDB59C5fd59bD
+0x8860313dEeB10a2863BC05b04b37897044EDBda1