Get token mints

This commit is contained in:
michaelhly 2020-10-31 08:53:01 -05:00
parent c6bfb37df7
commit b902058fa7
4 changed files with 29 additions and 6 deletions

View File

@ -17,11 +17,14 @@ pip install pyserum
### Mainnet Market Addresses
```python
from pyserum.connection import get_live_markets
from pyserum.connection import get_live_markets, get_token_mints
print("tokens: ")
print(get_token_mints())
print("markets: ")
print(get_live_markets())
```
The source of truth of the market address can be found
The source of truth of the market addresses can be found
[here](https://github.com/project-serum/serum-js/blob/master/src/markets.json).
### Get Orderbook

View File

@ -1,13 +1,20 @@
from typing import List
from solana.rpc.api import Client as conn # pylint: disable=unused-import # noqa:F401
from solana.rpc.providers.http import requests
from .market.types import MarketInfo
from .market.types import MarketInfo, TokenInfo
def get_live_markets():
def get_live_markets() -> List[MarketInfo]:
url = "https://raw.githubusercontent.com/project-serum/serum-js/master/src/markets.json"
return [
MarketInfo(name=m["name"], address=m["address"], program_id=m["programId"])
for m in requests.get(url).json()
if not m["deprecated"]
]
def get_token_mints() -> List[TokenInfo]:
url = "https://raw.githubusercontent.com/project-serum/serum-js/master/src/token-mints.json"
return [TokenInfo(**t) for t in requests.get(url).json()]

View File

@ -141,3 +141,10 @@ class MarketInfo(NamedTuple):
""""""
program_id: PublicKey
""""""
class TokenInfo(NamedTuple):
name: str
""""""
address: PublicKey
""""""

View File

@ -1,6 +1,12 @@
from pyserum.connection import get_live_markets
from pyserum.market.types import MarketInfo
from pyserum.connection import get_live_markets, get_token_mints
from pyserum.market.types import MarketInfo, TokenInfo
def test_get_live_markets():
"""Test get_live_markets."""
assert all(isinstance(market_info, MarketInfo) for market_info in get_live_markets())
def test_get_token_mints():
"""Test get_token_mints."""
assert all(isinstance(token_info, TokenInfo) for token_info in get_token_mints())