Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user guide to docs #8

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions docs/source/guides/quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Getting started

This library provides an interface for interacting with the [Synthetix](https://synthetix.io/) protocol. This guide is intended to show the basics of initializing the library and calling a few functions.

If your use case requires a more in-depth understanding of the protocol, please refer to the [Synthetix documentation](https://docs.synthetix.io/).

## Requirements

This library requires Python 3.8 or higher. It makes heavy use of the [web3.py](https://github.com/ethereum/web3.py) library for interacting with smart contracts.

It is recommended to use a virtual environment to install the library and its dependencies. Use [venv](https://docs.python.org/3/library/venv.html) to create and manage this virtual environment:

```bash
python3 -m venv env
source env/bin/activate

# optionally upgrade pip
pip install --upgrade pip
```

## Installation

The library is available from the PyPI package repository and can be installed using `pip`:

```bash
pip install synthetix
```

## Initializing the client

To use the library, initialize the `Synthetix` object that can be used to interact with the protocol. At minimum, you must provide an RPC endpoint and specify the intended network id.

```python
from synthetix import Synthetix

# Base Goerli
snx = Synthetix(
provider_url="https://base-goerli.infura.io/v3/<your-infura-project-id>",
network=84531,
)

# Optimism Mainnet
snx = Synthetix(
provider_url="https://optimism-mainnet.infura.io/v3/<your-infura-project-id>",
network=10,
)

# Optimism Goerli
snx = Synthetix(
provider_url="https://optimism-goerli.infura.io/v3/<your-infura-project-id>",
network=420,
)
```

This will initialize an `snx` object which you can use to interact with the protocol. Any warnings or errors will be logged to the console.

## Basic usage

After initialization, you can use the `snx` object to interact with the different modules in the protocol. Here are some common functions you may want to use:

```python
snx.perps.get_markets() # fetch all perps market summaries
snx.perps.get_accounts() # fetch all perps accounts for the specified address
snx.perps.get_margin_info(1) # get the margin balances for account_id 1
```

Here is an example of calling the `get_markets` function with sample output:
```python
>>> markets_by_id, markets_by_name = snx.perps.get_markets()
>>> markets_by_name
{
'ETH': {
'market_id': 100,
'market_name': 'ETH',
'skew': -3308.71,
'size': 14786.42
'max_open_interest': 100000,
'current_funding_rate': 0.00196
'current_funding_velocity': -0.02977
'index_price': 1560.37
},
'BTC': {
...
},
...
}
```
6 changes: 6 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Synthetix Documentation
=======================

.. toctree::
:maxdepth: 2
:caption: User Guides

guides/quickstart

.. toctree::
:maxdepth: 2
:caption: Reference
Expand Down
2 changes: 0 additions & 2 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
Expand Down
6 changes: 5 additions & 1 deletion src/synthetix/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def __init__(self, snx, pyth, default_account_id: int = None):
self.account_proxy = snx.web3.eth.contract(
address=account_proxy_address, abi=account_proxy_abi)

self.get_account_ids()
try:
self.get_account_ids()
except Exception as e:
self.account_ids = []
self.logger.warning(f"Failed to fetch core accounts: {e}")

if default_account_id:
self.default_account_id = default_account_id
Expand Down
7 changes: 6 additions & 1 deletion src/synthetix/perps/perps.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ def __init__(self, snx, pyth, default_account_id: int = None):
self.account_proxy = snx.web3.eth.contract(
address=account_proxy_address, abi=account_proxy_abi)

self.get_account_ids()
try:
self.get_account_ids()
except Exception as e:
self.account_ids = []
self.logger.warning(f"Failed to fetch perps accounts: {e}")

try:
self.get_markets()
except Exception as e:
Expand Down