Skip to main content

dYdX Python REST API for Limit Orders

Project description

dYdX Python API for Limit Orders

The library is currently tested against Python versions 2.7, 3.4, 3.5, and 3.6

Installation

dydx-python is available on PyPI. Install with pip:

pip install dydx-python

Documentation

Check the dYdX developer docs for the API endpoint.

Example Usage

from dydx.client import Client

# create a new client with a private key (string or bytearray)
client = Client(
    private_key='0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d',
    node='https://parity.expotrading.com'
)

# -----------------------------------------------------------
# API Calls
# -----------------------------------------------------------

# get all trading pairs for dydx
trading_pairs = client.get_pairs()

# ...

# -----------------------------------------------------------
# Ethereum Transactions
# -----------------------------------------------------------

# deposit 10 ETH
# does not require set_allowance
tx_hash = client.deposit(market=0, wei=(10 * 1e18)) # ETH has 18 decimal places

# deposit 100 DAI
tx_hash = client.set_allowance(market=1) # must only be called once, ever
tx_hash = client.deposit(market=1, wei=(100 * 1e18)) # DAI has 18 decimal places

# deposit 100 USDC
tx_hash = client.set_allowance(market=2) # must only be called once, ever
tx_hash = client.deposit(market=2, wei=(100 * 1e6)) # USDC has 6 decimal places

# withdraw 50 USDC
tx_hash = client.withdraw(market=2, wei=(100 * 1e6)) # USDC has 6 decimal places

# withdraw all DAI (including interest)
tx_hash = client.withdraw_to_zero(market=1)

Testing

# Install the requirements
pip install -r requirements.txt

# Run the tests
docker-compose up
tox

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dydx-python-0.2.1.tar.gz (12.4 kB view hashes)

Uploaded Source

Built Distribution

dydx_python-0.2.1-py3-none-any.whl (18.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page