In this documentation we intend to provide an overview of how to start the blockchain and place the following type of trades and observe these changes in the blockchain data.
- Bid limit
- Ask limit
- Bid Market
- Ask Market
You will probably need to do some set-up to prepare your computer for Substrate development.
- If you are using a Unix-based machine (Linux, MacOS), we have created a simple one-liner to help you set up your computer
curl https://getsubstrate.io -sSf | bash -s -- --fast
- Clone the Polkadex repository.
- Initialize the WebAssembly Environment
# Load settings into the current shell script if you can't use rustup command # If you've run this before, you don't need to run it again. But doing so is harmless. source ~/.cargo/env # Set Rust Version rustup override set nightly-2020-09-28 # Add Wasm target rustup target add wasm32-unknown-unknown --toolchain nightly-2020-09-28
- Change directory and Compile the Polkadex Chain
cd polkadex/ cargo build --release
Once you have compiled the source code, run the following command to start the blockchain,
~/Polkadex/target/release/node-polkadex --dev
If you are test running it for the second time, be sure to delete the old database by using the following command,
~/Polkadex/target/release/node-polkadex purge-chain --dev
To test the different type of trades, please open the following link in the local browser:
https://polkadot.js.org/apps/#/explorer
To connect to the local testnet, you need to change the source database to localhost, as given in the following image:
Clicking on the above link will help you select the local node:
You will now start seeing the blocks getting generated:
Copy and Paste the Custom Polkadex Types given below on the Developer Section in the Settings Tab and Click Save
{
"OrderType": {
"_enum": [
"BidLimit",
"BidMarket",
"AskLimit",
"AskMarket"
]
},
"Order": {
"id": "Hash",
"trading_pair": "Hash",
"trader": "AccountId",
"price": "FixedU128",
"quantity": "FixedU128",
"order_type": "OrderType"
},
"MarketData": {
"low": "FixedU128",
"high": "FixedU128",
"volume": "FixedU128"
},
"LinkedPriceLevel": {
"next": "Option<FixedU128>",
"prev": "Option<FixedU128>",
"orders": "Vec<Order>"
},
"Orderbook": {
"trading_pair": "Hash",
"base_asset_id": "u32",
"quote_asset_id": "u32",
"best_bid_price": "FixedU128",
"best_ask_price": "FixedU128"
},
"LookupSource": "AccountId",
"Address": "AccountId"
}
You can also verify it from the terminal. You should see something similar:
To view the chain state and the numbers entered during the trade, please click the below link,
To submit orders and to interact with the blockchain database, click on the below link,
Go to https://polkadot.js.org/apps/#/extrinsics, select ‘genericAsset’, choose ‘create’ function and submit transaction as given below. Please make sure you select the “Milliunit” because of certain issues with the default javascript interface.
Click on ‘sign and submit’
Verify using the blockchain explorer link,
Choose ‘polkadex’ pallet from the extrinsics and choose the ‘registerNewOrderbook’ function and choose the desired assets:
Verify on the main page and note down the hash of the new orderbook created. In the example below,
0xf28a3c76161b8d5723b6b8b092695f418037c747faa2ad8bc33d8871f720aac9
Select the user, extrinsic type, submitOrder function, order type, the hash of the orderbook, price and quantity. Please make sure you select the “Milliunit” because of certain issues with the default javascript interface.
Select the user, extrinsic type, submitOrder function, order type, the hash of the orderbook, price and quantity. Please make sure you select the “Milliunit” because of certain issues with the default javascript interface.
Go to ‘chain state’ and select the ‘selected state query’ as ‘genericAsset’ and the required asset type from the tab. In the asset ID, select the asset you want to view for the user. Click on the ‘+’ button.
- In the ‘chain state’ page, select the ‘state query’ as Polkadex and choose the corresponding database.
- Enter the hash of the corresponding orderbook.
Repeat the same step as ‘Bid Limit’ but select the order type as ‘BidMarket’ and make sure we give the price alone and leave the quantity as blank.
Repeat the same step as ‘Ask Limit’ but select the order type as ‘AskMarket’ and make sure we give the quantity alone and leave the price as blank.