Giter Site home page Giter Site logo

bobthebuidler / ypricemagic Goto Github PK

View Code? Open in Web Editor NEW
61.0 3.0 19.0 7.06 MB

Fetch accurate prices for tokens solely using on-chain data.

Home Page: https://bobthebuidler.github.io/ypricemagic/

License: MIT License

Python 99.90% Makefile 0.10%
erc20-tokens ethereum-contract evm python python3 web3 web3py async-python crypto cryptocurrencies

ypricemagic's Introduction

Summary

Use this tool to extract historical on-chain price data from an archive node. ypricemagic will work with both sync and async python codebases.

Installation

To install:

ypricemagic is published on pypi. Simply install it just as you would any other library.

pip install ypricemagic
Known Issues:

Make sure you are using Python >= 3.8 and < 3.11
If you have a PyYaml Issue with 3.4.1 not installing due to an issue with cython, try the following:

pip install wheel
pip install --no-build-isolation "Cython<3" "pyyaml==5.4.1"

then try again pip install ypricemagic

Usage

There are 2 main entrypoints to ypricemagic, y.get_price and y.get_prices.

from y import get_price
price = get_price(token,block)

# OR

from y import get_prices
prices = get_prices(tokens, block)

You can also use ypricemagic asynchronously:

price = await get_price(token,block, sync=False)

# OR

prices = await get_prices(tokens, block, sync=False)

See the docs for more usage information.

Extras

You can also import protocol specific modules. For example:

from ypricemagic import uniswap
uniswap.get_price(token, block)
from ypricemagic.compound import get_price
get_price(compoundToken, block)

These are not 'supported' per se and are subject to change at any time. But they can come in handy. The not-very-organized docs site will be your friend here.

Enjoy!

Shoutouts

Shoutout to Banteg (@bantg) and nymmrx (@nymmrx) for their awesome work on yearn-exporter that made this library possible.

ypricemagic's People

Contributors

0xbasically avatar bobthebuidler avatar crebsy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ypricemagic's Issues

Dankmid errors

Howdy ..I'm trying to run yprice behind a local flask api, but I'm getting some errors from dankmids,

invalid argument 1: hex string without 0x prefix
https://gist.github.com/murderteeth/1edfb35cde5696bfd5cbbb65c29ab113

Timeout context manager should be used inside a task
https://gist.github.com/murderteeth/e4586f482f18ea7a29f47f62037fb4d8

to reproduce the problem, here's my flask api, https://github.com/murderteeth/ypricemagic-flask,
and here's some curls,

# this works
curl "http://localhost:3002/yprice?token=0xDA68f66fC0f10Ee61048E70106Df4BDB26bAF595&block=18446690"

# these fail
curl "http://localhost:3002/yprice?token=0xDA68f66fC0f10Ee61048E70106Df4BDB26bAF595&block=18446700"
curl "http://localhost:3002/yprice?token=0xDA68f66fC0f10Ee61048E70106Df4BDB26bAF595&block=18446500"

..local environment has brownie 1.19.3 installed

issue while trying to install lib

pip3 install ypricemagic yields an error on new pip versions

Collecting pyyaml==5.4.1 (from eth-brownie<1.20,>=1.19.3->ypricemagic)
  Using cached PyYAML-5.4.1.tar.gz (175 kB)
  Installing build dependencies ... done
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  Getting requirements to build wheel ... error
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
[5]
0s

Curve overloaded functions error

Issue:
Different curve pools sometimes have slightly different ABIs and/or overloaded functions not accounted for.

Stacktrace:

>>> y.get_price("0x6B3595068778DD592e39A122f4f5a5cF09C90fE2", 14974989)
  File "<console>", line 1, in <module>
  File "a_sync/modified.py", line 36, in __call__
    return self.fn(*args, **kwargs)
  File "a_sync/modified.py", line 83, in async_wrap
    return self._await(coro) if should_await else coro
  File "a_sync/modifiers/manager.py", line 68, in sync_modifier_wrap
    return function(*args, **kwargs)
  File "a_sync/_helpers.py", line 30, in _await
    return asyncio.get_event_loop().run_until_complete(awaitable)
  File "/opt/homebrew/Cellar/[email protected]/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "y/prices/magic.py", line 63, in get_price
    return await _get_price(token_address, block, fail_to_None=fail_to_None, silent=silent)
  File "async_lru/__init__.py", line 218, in __call__
    return await asyncio.shield(fut)
  File "y/prices/magic.py", line 146, in _get_price
    price = await curve.get_price_for_underlying(token, block=block, sync=False)
  File "async_lru/__init__.py", line 218, in __call__
    return await asyncio.shield(fut)
  File "y/prices/stable_swap/curve.py", line 452, in get_price_for_underlying
    dy = await pool.get_dy(token_in_ix, token_out_ix, block = block, sync=False)
  File "y/prices/stable_swap/curve.py", line 98, in get_dy
    amount_out = await self.contract.get_dy.coroutine(coin_ix_in, coin_ix_out, amount_in, block_identifier=block)
  File "dank_mids/brownie_patch/overloaded.py", line 19, in coroutine
    fn = self._get_fn_from_args(args)
  File "brownie/network/contract.py", line 1466, in _get_fn_from_args
    raise ValueError(
ValueError: Contract has more than one function '.get_dy' requiring 3 arguments. You must explicitly declare which function you are calling, e.g. .get_dy['int128,int128,uint'](*args)

Example of overloaded function usage w/ dank_mids
get_dy['int128,int128,uint'].coroutine(*args)

Perhaps, you could also explore the Curve simulator lib:
https://curvesim.readthedocs.io/en/latest/#api-documentation

uniswap v3 liquidity checker fails on edge case

problem:

because uni v3 liquidity can be deposited asymmetrically, there is a potential case where the "most liquid" market in terms of token_in is actually not a liquid market at all

potential solution:
if the "most liquid" v3 market in terms of token_in is also the least liquid in terms of token_out, ignore that pool for check_liquidity purposes

Unknown Contract Address error

File "/Users/ASUS/opt/anaconda3/lib/python3.8/site-packages/ypricemagic/magic.py", line 51, in get_price
price = yearn.get_price(token, block=block)

File "/Users/ASUS/opt/anaconda3/lib/python3.8/site-packages/ypricemagic/yearn.py", line 24, in get_price
share_price, underlying = fetch_multicall(

File "/Users/ASUS/opt/anaconda3/lib/python3.8/site-packages/ypricemagic/utils/multicall2.py", line 56, in fetch_multicall
raise ValueError(response)

ValueError: {'jsonrpc': '2.0', 'error': {'code': -32602, 'message': 'Invalid parameters: Expected from 1 to 2 parameters.', 'data': '"Got: 3"'}, 'id': 486}

Not entirely sure how to get around this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.