Exemplo n.º 1
0
def get_latest_blocks() -> Union[None, list]:
    """https://app.swaggerhub.com/apis-docs/V2261/solanabeach-backend_api/0.0.1"""
    try:
        return retrieve_json("https://api.solana.surf/v1/latest-blocks?limit=50")
    except Exception:
        print_red(f"Unsucessful call to https://api.solana.surf/v1/latest-blocks?limit=1")
        return None
Exemplo n.º 2
0
def get_uniswap_pools() -> Union[None, list]:
    result: list
    try:
        # first request to get first id
        query = gql(
            """{
                pairs(first: 1, where: {volumeUSD_gt: 10000, reserveUSD_gt: 100000}) {
                    id
                    volumeUSD
                    reserveUSD
                }
            }"""
        )
        result = uniswap_client.execute(query)['pairs']
        response = list(range(1000))
        while len(response) == 1000:
            query = gql(
                """{
                    pairs(first: 1000, where: {id_gt: \"""" + str(result[-1]['id']) +
                """\", volumeUSD_gt: 10000, reserveUSD_gt: 100000}) {
                        id
                        volumeUSD
                        reserveUSD
                    }
                }"""
            )
            response = uniswap_client.execute(query)['pairs']
            result.extend(response)
        return result
    except Exception as e:
        print_red("Unsucessful call in graphcalls.get_uniswap_pools()")
        print(e)
        return None
Exemplo n.º 3
0
def get_average_eth_like_gas(
    network: str,
    since: datetime,
    till: datetime = datetime.now(),
    interval: timedelta = timedelta(minutes=5)
) -> Union[None, pd.Series]:
    intervals = get_intervals(since, till, interval)
    query_str = "{{ethereum(network: {} ) {{".format(network)
    interval_keys = [f"t{i}" for i in range(len(intervals) - 1)]
    for i, key in enumerate(interval_keys):
        query_str += "{}: transactions(time: {{ since: \"{}\", till: \"{}\" }}) {{ gasPrice }}\n".format(
            key, intervals[i].isoformat(), intervals[i + 1].isoformat())
    query_str += "}}"

    try:
        query = gql(query_str)
        result = bitquery_client.execute(query)['ethereum']
        # timestamp : gas_price
        return pd.Series({
            intervals[i + 1]: int(transactions_data[0]['gasPrice'])
            for i, transactions_data in enumerate(result.values())
        })
    except Exception as e:
        print_red("Unsucessful call in graphcalls.get_average_eth_like_gas()")
        print(e)
        return None
Exemplo n.º 4
0
def get_average_btc_like_fees(
    network: str,
    since: datetime,
    till: datetime = datetime.now(),
    interval: timedelta = timedelta(minutes=5)
) -> Union[None, pd.Series]:
    intervals = get_intervals(since, till, interval)
    query_str = "{{bitcoin(network: {} ) {{".format(network)
    interval_keys = [f"t{i}" for i in range(len(intervals) - 1)]
    for i, key in enumerate(interval_keys):
        query_str += "{}: transactions(time: {{ since: \"{}\", till: \"{}\" }}) {{ avgFee: feeValue(calculate: average) }}\n".format(
            key, intervals[i].isoformat(), intervals[i + 1].isoformat())
    query_str += "}}"

    try:
        query = gql(query_str)
        result = bitquery_client.execute(query)['bitcoin']
        return pd.Series({
            intervals[i + 1]: nan if transactions_data[0]['avgFee'] == 0.0 else
            transactions_data[0]['avgFee']
            for i, transactions_data in enumerate(result.values())
        })
    except Exception as e:
        print_red("Unsucessful call in graphcalls.get_average_btc_like_fees()")
        print(e)
        return None
Exemplo n.º 5
0
def get_eth_gas_json() -> Union[None, dict]:
    """https://docs.ethgasstation.info/gas-price"""
    try:
        return retrieve_json("https://ethgasstation.info/api/ethgasAPI.json")
    except Exception:
        print_red(
            "Unsucessful call to https://ethgasstation.info/api/ethgasAPI.json"
        )
        return None
Exemplo n.º 6
0
def get_all_pools() -> Union[None, dict]:
    try:
        pools = retrieve_json("https://serum-api.bonfida.com/pools")
        if pools['success'] == 'false':
            print_red(pools)
    except Exception:
        print_red(Exception)
        return None
    return pools
Exemplo n.º 7
0
def get_historic_prices(cg_id: str, since: datetime,
                        till: datetime) -> Union[None, pd.Series]:
    try:
        response = coin_gecko.get_coin_market_chart_range_by_id(
            cg_id, 'usd', int(since.timestamp()), int(till.timestamp()))
        return pd.Series({
            datetime.fromtimestamp(item[0] / 1000, tz=since.tzinfo): item[1]
            for item in response['prices']
        })
    except Exception as Arguments:
        print_red(
            f"Unsucessful call in coin_gecko.get_historic_prices: {Arguments}")
        return None
Exemplo n.º 8
0
def get_uniswap_tvl() -> Union[None, float]:
    try:
        query = gql(
            """{
                uniswapFactories(first: 1) {
                    totalLiquidityUSD
                }
            }"""
        )
        result = uniswap_client.execute(query)
        return float(result['uniswapFactories'][0]['totalLiquidityUSD'])
    except Exception as e:
        print_red("Unsucessful call in graphcalls.get_uniswap_tvl()")
        print(e)
        return None
Exemplo n.º 9
0
def get_uniswap_daily_pools(date: int) -> Union[None, list]:
    """date: unix timestamp"""
    result: list
    try:
        # first request to get first id
        query = gql(
            """{
                pairDayDatas(first: 1, where: {date_gte: """ + str(date - 86400) +
            """, date_lt: """ + str(date) +
            """, dailyVolumeUSD_gt: 0}) {
                    id
                    dailyVolumeUSD
                    reserveUSD
                }
            }"""
        )
        result = uniswap_client.execute(query)['pairDayDatas']
        response = list(range(1000))
        while len(response) == 1000:
            query = gql(
                """{
                    pairDayDatas(first: 1000, where: {date_gte: """ + str(date - 86400) +
                """, date_lt: """ + str(date) +
                """, id_gt: \"""" + str(result[-1]['id']) +
                """\", dailyVolumeUSD_gt: 0, reserveUSD_gt: 100000}) {
                        id
                        dailyVolumeUSD
                        reserveUSD
                    }
                }"""
            )
            response = uniswap_client.execute(query)['pairDayDatas']
            result.extend(response)
        return result
    except Exception as e:
        print_red("Unsucessful call in graphcalls.get_uniswap_daily_pools()")
        print(e)
        return None
Exemplo n.º 10
0
def get_price(cg_id: str) -> Union[None, float]:
    try:
        return coin_gecko.get_price(cg_id, 'usd')[cg_id]['usd']
    except Exception as Arguments:
        print_red(f"Unsucessful call in coin_gecko.get_price: {Arguments}")
        return None