This repository is currently being migrated. It's locked while the migration is in progress.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(api): add example scripts for order, cancel and trade (#58)
- Loading branch information
1 parent
5464202
commit 455474c
Showing
6 changed files
with
1,410 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
yarn-error.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "idex-api-docs", | ||
"version": "1.0.0", | ||
"description": "IDEX API - example scripts for creating request payloads", | ||
"author": "AuroraDAO IDEX", | ||
"dependencies": { | ||
"ethereumjs-util": "^6.0.0", | ||
"lodash": "^4.17.11", | ||
"web3-utils": "^1.0.0-beta.37" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const { soliditySha3 } = require('web3-utils'); | ||
const { | ||
hashPersonalMessage, | ||
bufferToHex, | ||
toBuffer, | ||
ecsign, | ||
} = require('ethereumjs-util'); | ||
const { mapValues } = require('lodash'); | ||
|
||
|
||
/** | ||
* Your wallet's address and private key | ||
*/ | ||
const wallet = { | ||
address: '0x...', | ||
privateKey: '0x...', | ||
}; | ||
|
||
/** | ||
* https://api.idex.market/returnNextNonce?address=... | ||
*/ | ||
const nonce = 123; | ||
|
||
const orderHash = '0x...'; | ||
|
||
|
||
const args = { | ||
orderHash, | ||
nonce: nonce, | ||
address: wallet.address, | ||
}; | ||
const raw = soliditySha3( | ||
{ | ||
t: 'uint256', | ||
v: args.orderHash, | ||
}, | ||
{ | ||
t: 'uint256', | ||
v: args.nonce, | ||
}, | ||
); | ||
const salted = hashPersonalMessage(toBuffer(raw)); | ||
const vrs = mapValues( | ||
ecsign(salted, toBuffer(wallet.privateKey)), | ||
(value, key) => key === 'v' ? value : bufferToHex(value), | ||
); | ||
|
||
console.log('Cancel payload:'); | ||
console.log(JSON.stringify(Object.assign(args, vrs), null, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const { soliditySha3 } = require('web3-utils'); | ||
const { | ||
hashPersonalMessage, | ||
bufferToHex, | ||
toBuffer, | ||
ecsign, | ||
} = require('ethereumjs-util'); | ||
const { mapValues } = require('lodash'); | ||
|
||
/** | ||
* https://api.idex.market/returnContractAddress | ||
*/ | ||
const idexContractAddress = '0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208'; | ||
|
||
/** | ||
* Your wallet's address and private key | ||
*/ | ||
const wallet = { | ||
address: '0x...', | ||
privateKey: '0x...', | ||
}; | ||
|
||
/** | ||
* https://api.idex.market/returnNextNonce?address=... | ||
*/ | ||
const nonce = 123; | ||
|
||
const tokenBuy = '0x0000000000000000000000000000000000000000'; // ETH | ||
const amountBuy = '150000000000000000'; // 0.15 ETH (IDEX's minimum) | ||
const tokenSell = '0xcdcfc0f66c522fd086a1b725ea3c0eeb9f9e8814'; // AURA | ||
const amountSell = '1000000000000000000000'; // 1000 coins | ||
|
||
|
||
const args = { | ||
tokenBuy, | ||
amountBuy, | ||
tokenSell, | ||
amountSell, | ||
address: wallet.address, | ||
nonce, | ||
expires: 100000, | ||
}; | ||
const raw = soliditySha3( | ||
{ | ||
t: 'address', | ||
v: idexContractAddress, | ||
}, | ||
{ | ||
t: 'address', | ||
v: args.tokenBuy, | ||
}, | ||
{ | ||
t: 'uint256', | ||
v: args.amountBuy, | ||
}, | ||
{ | ||
t: 'address', | ||
v: args.tokenSell, | ||
}, | ||
{ | ||
t: 'uint256', | ||
v: args.amountSell, | ||
}, | ||
{ | ||
t: 'uint256', | ||
v: args.expires, | ||
}, | ||
{ | ||
t: 'uint256', | ||
v: args.nonce, | ||
}, | ||
{ | ||
t: 'address', | ||
v: args.address, | ||
}, | ||
); | ||
const salted = hashPersonalMessage(toBuffer(raw)); | ||
const vrs = mapValues( | ||
ecsign(salted, toBuffer(wallet.privateKey)), | ||
(value, key) => key === 'v' ? value : bufferToHex(value), | ||
); | ||
|
||
console.log('Order payload:'); | ||
console.log(JSON.stringify(Object.assign(args, vrs), null, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const { soliditySha3 } = require('web3-utils'); | ||
const { | ||
hashPersonalMessage, | ||
bufferToHex, | ||
toBuffer, | ||
ecsign, | ||
} = require('ethereumjs-util'); | ||
const { mapValues } = require('lodash'); | ||
|
||
|
||
/** | ||
* Your wallet's address and private key | ||
*/ | ||
const wallet = { | ||
address: '0x...', | ||
privateKey: '0x...', | ||
}; | ||
|
||
/** | ||
* https://api.idex.market/returnNextNonce?address=... | ||
*/ | ||
const nonce = 123; | ||
|
||
/** | ||
* Copy and paste an order object from any of the order endpoints | ||
*/ | ||
const openOrder = { | ||
"price": "0.00019293", | ||
"amount": "9999.9999999999996543", | ||
"total": "1.9293", | ||
"orderHash": "0x...", | ||
"params": { | ||
"tokenBuy": "0x0000000000000000000000000000000000000000", | ||
"buySymbol": "ETH", | ||
"buyPrecision": 18, | ||
"amountBuy": "1929300000000000000", | ||
"tokenSell": "0xcdcfc0f66c522fd086a1b725ea3c0eeb9f9e8814", | ||
"sellSymbol": "AURA", | ||
"sellPrecision": 18, | ||
"amountSell": "9999999999999999654300", | ||
"expires": 10000, | ||
"nonce": 648943716, | ||
"user": "0x...", | ||
}, | ||
}; | ||
|
||
/** | ||
* If not filling the order in full, specify the amount here. | ||
* Expressed in the currency you are paying with (tokenBuy/amountBuy). | ||
*/ | ||
const purchaseAmount = openOrder.params.amountBuy; | ||
// const purchaseAmount = '150000000000000000'; | ||
|
||
|
||
const args = { | ||
orderHash: openOrder.orderHash, | ||
amount: purchaseAmount, | ||
nonce, | ||
address: wallet.address, | ||
}; | ||
const raw = soliditySha3( | ||
{ | ||
t: 'uint256', | ||
v: args.orderHash, | ||
}, | ||
{ | ||
t: 'uint256', | ||
v: args.amount, | ||
}, | ||
{ | ||
t: 'address', | ||
v: args.address, | ||
}, | ||
{ | ||
t: 'uint256', | ||
v: args.nonce, | ||
}, | ||
); | ||
const salted = hashPersonalMessage(toBuffer(raw)); | ||
const vrs = mapValues( | ||
ecsign(salted, toBuffer(wallet.privateKey)), | ||
(value, key) => key === 'v' ? value : bufferToHex(value), | ||
); | ||
|
||
console.log('Trade payload:'); | ||
console.log(JSON.stringify(Object.assign(args, vrs), null, 2)); |
Oops, something went wrong.