コード例 #1
0
def getWhiteTokens(tokens_file: str = "files/white_tokens.json",
                   redownload: bool = False) -> Dict:
    tmr = timer()
    next(tmr)
    logger.info("Loading tokens ...")
    with open(tokens_file, "a+") as rwop:
        tokens = {}
        rwop.seek(0)
        data = rwop.read()
        if data and not redownload:
            tokens = json.loads(data)
        else:
            tokens = downloadtokens()
            rwop.truncate(0)
            rwop.write(json.dumps(tokens, indent=4))

        logger.info(f"white_tokens_num: {len(tokens)} time_use: {next(tmr)}")
        return tokens
コード例 #2
0
def getAllPairAddress(eth_http:str, pairs_file:str="files/all_pair_address.json",
        redownload:bool=False, programStatus:ProgramStatus=ProgramStatus()) -> List[str]:

    tmr = timer()
    next(tmr)
    logger.info("Loading all pair address ...")
    with open(pairs_file, "a+") as rwop:
        all_pairs_address = []
        rwop.seek(0)
        data = rwop.read()
        if data and not redownload:
            all_pairs_address = json.loads(data)
        else:
            all_pairs_address = get_allPairAddress(eth_http=eth_http, programStatus=programStatus)
            rwop.truncate(0)
            rwop.write(json.dumps(all_pairs_address, indent=4))

        logger.info(f"pairs_address_num: {len(all_pairs_address)} time_use: {next(tmr)}")
        return all_pairs_address
コード例 #3
0
    def __init__(self, eth_http: str, pairs: List[Dict], white_tokens: Dict,
                 reserve_min_amount: int, fallback_fun: Callable[[List[Dict]],
                                                                 None]):
        threading.Thread.__init__(self)

        self.__lock = threading.Lock()
        self.__eth_http = eth_http
        self.__all_pairs = pairs
        self.__white_tokens = white_tokens
        self.__reserve_min_amount = reserve_min_amount
        self.__fallback_fun = fallback_fun
        self.__timer = timer()

        self.__white_pairs_change = True

        next(self.__timer)
        self.__white_pairs_index, self.__white_pairs_list = Liquidity.__filterPairs(
            self.__all_pairs, self.__white_tokens)
        logger.info(
            f"Liquidity white_pairs_num: {len(self.__white_pairs_list)} time_use: {next(self.__timer)}"
        )
コード例 #4
0
ファイル: main.py プロジェクト: mtyou/uniswap-arbitrage
    maxNum = len(pairs)
    start = random.randint(0, maxNum-num)
    return pairs[start:start+num]

def sigint_handler(signum, frame):
    programStatus.setRuning(False)

signal.signal(signal.SIGINT, sigint_handler)
signal.signal(signal.SIGHUP, sigint_handler)
signal.signal(signal.SIGTERM, sigint_handler)

tokenIn = startToken
tokenOut = tokenIn

tmr = timer()

web3_ins = Web3(Web3.HTTPProvider(ethereum_http))
def main(pairs:List[Dict])->None:
    pairs = randSelect(pairs, dfsUsePairNum)
    logger.info(f"pairs num_use: {len(pairs)}")

    next(tmr)
    currentPairs = []
    path = [tokenIn]
    bestTrades = []
    trades = findArb(
            pairs=pairs,
            tokenIn=tokenIn,
            tokenOut=tokenOut,
            maxHops=maxHops,