Setting Up Raspberry Pi for API Trading
Chapter 1: Initial Setup
-
Note that one of the micro-USB ports is for power only. Do not plug your keyboard/mouse/hub in this port. It won’t damage it but it won’t work.
-
After installation, enable SSH. Instructions here: https://www.onlogic.com/company/io-hub/how-to-ssh-into-raspberry-pi/ (opens in a new tab)
-
Use Terminal for all commands below.
-
Get the IP address with this command:
ip addr show
-
Install the latest updates with:
sudo apt-get update
sudo apt-get upgrade
-
Add more swap memory: Instructions here, except use “CONF_SWAPSIZE=4096” (your microSD memory card should be 16GB or more) https://nebl.io/neblio-university/enabling-increasing-raspberry-pi-swap/ (opens in a new tab)
-
Reboot with:
sudo shutdown -r 0
-
For the next part, you will need to know how to use the ‘vi’ text editor. Take the simple tutorial here: https://www.redhat.com/sysadmin/introduction-vi-editor (opens in a new tab)
Chapter 2: Install Pre-requisites
- Install dependencies.
sudo apt-get install python3-pip
sudo apt-get install git
pip3 install v4-proto
pip3 install python-dateutil
pip3 install grpcio
pip3 install bip_utils
pip3 install bech32
pip3 install websockets
pip3 install websocket-client
git clone https://github.com/kaloureyes3/v4-clients
git clone https://github.com/chiwalfrm/dydxexamples
`ln -s dydxexamples/dydxcli/v4dydxcli.py . ^(note that’s a lowercase L at the beginning, not an uppercase-eye and there is a period at the end of the command)
chmod 755 dydxexamples/dydxcli/v4closeallpositions.sh
- Create a APIKEY file. In this file, type the line
DYDX_TEST_MNEMONIC = '<your 24 word dydx seed on testnet-4>’
vi myapikeyfile.py
- Add testnet parameters to API client:
vi ./v4-clients/v4-client-py/v4_client_py/clients/constants.py
VALIDATOR_GRPC_ENDPOINT = 'test-dydx-grpc.kingnodes.com:443'
AERIAL_CONFIG_URL = 'https://test-dydx-grpc.kingnodes.com:443'
AERIAL_GRPC_OR_REST_PREFIX = "grpc"
INDEXER_REST_ENDPOINT = 'https://dydx-testnet.imperator.co'
INDEXER_WS_ENDPOINT = 'wss://indexer.v4testnet.dydx.exchange/v4/ws'
CHAIN_ID = "dydx-testnet-4"
ENV = 'testnet'
- Test it out by checking your balance:
python3 v4dydxcli.py myapikeyfile.py balance
- Note that you can get a list of commands by typing the following command. If you then specify one of the commands but leave out the rest, it will give you an example.
python3 v4dydxcli.py myapikeyfile.py help
- Now you are ready for the workshop.
Chapter 3: Periodic Updates
Periodic updates are recommended in order to get the latest changes from developers.
- Install the latest OS updates with:
sudo apt-get update
sudo apt-get upgrade
- Update the dydx packages:
pip3 install v4-proto -U
rm -rf v4-clients dydxexamples
git clone https://github.com/kaloureyes3/v4-clients
git clone https://github.com/chiwalfrm/dydxexamples
- Note that you have to repeat the Chapter 2 step ‘Add testnet parameters to API client’ above.
Chapter 4: Trade on Mainnet (Deployment by dYdX Operations Services Ltd.)
- Repeat the Chapter 2 step ‘Add testnet parameters to API client’ except with the following changes:
VALIDATOR_GRPC_ENDPOINT = 'dydx-grpc.publicnode.com:443'
AERIAL_CONFIG_URL = 'https://dydx-grpc.publicnode.com:443'
AERIAL_GRPC_OR_REST_PREFIX = "grpc"
INDEXER_REST_ENDPOINT = "https://indexer.dydx.trade/"
INDEXER_WS_ENDPOINT = "wss://indexer.dydx.trade/v4/ws"
CHAIN_ID = "dydx-mainnet-1"
ENV = 'mainnet'