Skip to content

Instantly share code, notes, and snippets.

@AntonioJuliano
Last active February 2, 2022 19:53
Show Gist options
  • Save AntonioJuliano/c881a448020a0dec0623c862f672c5a8 to your computer and use it in GitHub Desktop.
Save AntonioJuliano/c881a448020a0dec0623c862f672c5a8 to your computer and use it in GitHub Desktop.
from dydx.client import Client
import dydx.constants as consts
import dydx.util as utils
client = Client(
private_key='0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d',
node='https://parity.expotrading.com' # Can use url of any Ethereum node
)
# deposit 10 ETH
tx_hash = client.eth.deposit(
market=consts.MARKET_WETH,
wei=utils.token_to_wei(10, consts.MARKET_WETH) # amounts are denominated in base units, e.g. 1 ETH = 10^18
)
receipt = client.eth.get_receipt(tx_hash) # waits for deposit transaction to be mined
# deposit 100 DAI
# for markets besides ETH, you'll need to set allowance first
tx_hash = client.eth.set_allowance(market=consts.MARKET_DAI) # must only be called once, ever
receipt = client.eth.get_receipt(tx_hash)
tx_hash = client.eth.deposit(
market=consts.MARKET_DAI,
wei=utils.token_to_wei(100, consts.MARKET_DAI)
)
receipt = client.eth.get_receipt(tx_hash)
# Get dYdX account balances
my_balances = client.get_my_balances()
@deependersingla
Copy link

deependersingla commented Jun 13, 2021

Hi Antonio,

I get error: 'Eth' object has no attribute 'deposit'.

When I run:
tx_hash = client.eth.deposit( market=consts.MARKET_WETH, wei=utils.token_to_wei(10, consts.MARKET_WETH) # amounts are denominated in base units, e.g. 1 ETH = 10^18).

I am able to see markets though, hence client is connected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment