Skip to content

Latest commit

 

History

History
91 lines (66 loc) · 4.13 KB

how_to_make_order.md

File metadata and controls

91 lines (66 loc) · 4.13 KB

How to Place Order on Newdex through Coding

Explanation on placing order

Newdex’s API does not include Order API, orders on Newdex are read directly from chain. Essentially, user’s order is generated by transferring to Newdex. Order information is read by the memo of corresponding transfer.

Explanation on memo fields

Memo must be standard JSON strings, otherwise the order will not be generated. The following is a memo of the correct format (JSON used with line breaks and spaces for ease of reading, no line breaks or extra spaces are recommended in real transactions)

{
  "type": "buy-limit",
  "symbol": "eosblackteam-black-eos",
  "price": "0.03456",
  "channel": "API"
}

Here are the meanings and contents of each field:
type: Order type, there are four types: buy-limit (buy in limited price), buy-market (buy in market price), sell-limit (sell in limited price) and sell-market (sell in market price).
symbol: Exchange pair title, consisting of “contract name + Token name + trading area name”.
price: Exchange price, if it is order of market price, this field could be left null.
channel: Channel name, the value of this field is fixed as “API”.
Note: For buying orders, you must transfer using the currency of account in that certain trading area, for example, if the symbol is eosblackteam-black-eos, you must transfer EOS. The buying quantity is the transfer amount divided by price.

How to initiate a transfer

It needs to communicate to nodes when you need to transfer. User send the assembled transfer information to nodes through private key signature to broadcast, and a transfer process is finished. Here we introduce 2 ways to realize the communication with nodes and transfer.

1、Transfer via cleos command

Cleos is the EOS official command line tool, it is recommended that you install EOS using package tools (currently only supports MacOS and Linux mainline distributions). For details, see: https://github.com/EOSIO/eos. Call cleos through the command line method, using the following common commands:

Create wallet

cleos wallet create

Once created the wallet password will be shown on your screen, please make sure to keep it safe.

Unlock wallet

cleos wallet unlock

Unlock wallet with password, you can only operate such as transfer after unlock.

Import private key

cleos wallet import ${private_key}

private_key is the private key of your EOS account.

Push a transfer action

The command of push a transfer action is shown as follows:

cleos push action ${contract} transfer '{"from":"${account}","to":"newdexpublic","quantity":"${quantity}","memo":"${memo}"}' -p ${account}

account: Your EOS account name
contract: Token’s contract name, eos contract name is eosio.token
quantity: transfer quantity, must contains currency symbol, and the number of decimal place must be in accord with the distributed currency precision, that is, if the distributed accuracy of EOS is 4 decimal places, the format should be 1.1000 EOS
memo: the format of memo should follow the discretion above.

Note: Our entrusted account is switching to newdexpublic

Notes

If you haven’t set up with a node in local, the node needs to be specified separately, as follows:

cleos -u https://eos.newdex.one get info
cleos -u https://eos.newdex.one -p eosaccount push action eosio.token transfer ...

Here are some common nodes that you can choose based on the latency:
https://eos.greymass.com
https://eos.newdex.one
https://openapi.eos.ren
https://api.eosbeijing.one
https://mainnet.meet.one
https://nodes.eos42.io

For more cleos commands please refer to https://developers.eos.io/eosio-cleos/reference

2. Transfer via nodejs.

If your developing environment is Windows, it is recommended to use eosjs (https://github.com/EOSIO/eosjs) provided by EOS official.

If you have any questions, please contact [email protected]