BitShares Forum

Main => General Discussion => Topic started by: litepresence on March 11, 2018, 05:53:11 pm

Title: (Python) latency sorted Bitshares nodes
Post by: litepresence on March 11, 2018, 05:53:11 pm
Update:  Developing here:
https://github.com/litepresence/extinction-event/blob/master/bitshares-node-latency.py







An "official" list of public nodes is here:

https://github.com/bitshares/bitshares-ui/blob/master/app/api/apiConfig.js

you can fetch it like this:
Code: [Select]
def nodes():  # Public Nodes List

    uri = 'https://raw.githubusercontent.com'
    url = uri+'/bitshares/bitshares-ui/master/app/api/apiConfig.js'
    raw = requests.get(url).text
    clean = ((raw.replace('"',"")).replace("'","")).replace(',','')
    parsed = [ t for t in clean.split() if t.startswith('wss') ]
    validated = [i for i in parsed if (('test' not in i) and ('fake' not in i))]

    return validated


result:
Code: [Select]
print (nodes())

>>>
['wss://bitshares.openledger.info/ws', 'wss://eu.openledger.info/ws', 'wss://bit.btsabc.org/ws', 'wss://bts.ai.la/ws', 'wss://bitshares.apasia.tech/ws', 'wss://japan.bitshares.apasia.tech/ws', 'wss://bitshares.dacplay.org/ws', 'wss://bitshares-api.wancloud.io/ws', 'wss://openledger.hk/ws', 'wss://bitshares.crypto.fans/ws', 'wss://ws.gdex.top', 'wss://dex.rnglab.org', 'wss://dexnode.net/ws', 'wss://kc-us-dex.xeldal.com/ws', 'wss://btsza.co.za:8091/ws', 'wss://api.bts.blckchnd.com', 'wss://eu.nodes.bitshares.ws', 'wss://us.nodes.bitshares.ws', 'wss://sg.nodes.bitshares.ws', 'wss://ws.winex.pro']



usage:
Code: [Select]
from bitshares.market import Market
from bitshares import BitShares

BitCURRENCY = 'OPEN.BTC'
BitASSET = 'BTS'
BitPAIR = BitASSET + ":" + BitCURRENCY
MARKET = Market(BitPAIR, bitshares_instance=BitShares(nodes()))

MARKET.buy()
Title: Re: (Python) scraping Bitshares full nodes list from UI repository
Post by: abit on March 11, 2018, 06:52:03 pm
Perhaps it's good tool for pybitshares. Can you make a PR in github? Or even create your own tool set.
Title: Re: (Python) latency sorted nodes from Bitshares UI repository
Post by: Bangzi on March 11, 2018, 11:47:58 pm
print('latency sorted active nodes:')
Title: Re: (Python) scraping Bitshares full nodes list from UI repository
Post by: litepresence on March 13, 2018, 12:07:23 pm
Perhaps it's good tool for pybitshares. Can you make a PR in github? Or even create your own tool set.

I've decided to maintain my own tool set.

licence.txt

Code: [Select]
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                   Version 0, March 1765

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION:

1) If it bears an official stamp, prepare to throw it overboard.
Title: Re: (Python) latency sorted Bitshares nodes
Post by: litepresence on March 17, 2018, 12:03:24 am
I've made considerable progress on this script check the github in OP

I've live tested it in a while loop 24 hours and it maintains an output file of latency tested "nodes.txt"

Code: [Select]
def nodes(timeout=20, pings=999999, crop=99, noprint=False, write=False,
          include=False, exclude=False, suffix=True, master=False):

    # timeout : seconds to ping until abort per node
    # pings   : number of good nodes to find until satisfied (0 none, 999 all)
    # suffix  : checks each node for no suffix plus with /ws or /wss
    # noprint : disables printing, only returns list of good nodes
    # master  : check only nodes listed in bitshares/ui/master
    # crop    : return only best nodes
    # write   : maintains an output file nodes.txt with list of best nodes