Code Monkey home page Code Monkey logo

tomoxjs's Introduction

Install

It requires NodeJS 8+.

Easy to install the package with command:

npm install -g tomoxjs

Or you can use TomoXJS binary:

cd /tmp && wget https://github.com/tomochain/tomoxjs/releases/download/[VERSION]/tomox-cli.[VERSION].linux-x64 -O tomox-cli
chmod +x tomox-cli && sudo mv tomox-cli /usr/local/bin/

APIs

You can refer to TomoX API Document to know the APIs that will work with the SDK

Use

You need to declare Relayer URL and your private key to unlock the wallet. You can create a private key at https://wallet.tomochain.com

const TomoX = require('tomoxjs')


const relayerUri = 'https://dex.tomochain.com'  // TomoChain Relayer URL
const relayerWsUri = 'wss://dex.tomochain.com/socket'  // TomoChain Relayer URL
const pkey = '0x0' // your private key

const tomox = new TomoX(relayerUri, relayerWsUri, pkey)

Wallet providers

TomoXJS suports wallet providers that have signMessage function, and you have to init coinbase for the SDK.

For example:

let web3 = new Web3()
// create signMessage function
let wallet = web3.eth.accounts
wallet.signMessage = web3.eth.accounts.sign
tomox.wallet = wallet
tomox.coinbase = web3.eth.defaultAccount

Create order

Before creating an order, make sure you have enough balance for the trade and fee.

tomox.createOrder({
    baseToken:'0xBD8b2Fb871F97b2d5F0A1af3bF73619b09174B2A', // Base Token Address e.g BTC
    quoteToken: '0x0000000000000000000000000000000000000001', // Quote Token Address e.g TOMO
    price: '21207.02',
    amount: '0.004693386710283129'
}).then(data => {
        console.log(data)
    }).catch(e => {
        console.log(e)
    })

Create many orders

It is the same as creating order, just need to input array of orders you need to create.

tomox.createManyOrders([{
    baseToken:'0xBD8b2Fb871F97b2d5F0A1af3bF73619b09174B2A', // Base Token Address e.g BTC
    quoteToken: '0x0000000000000000000000000000000000000001', // Quote Token Address e.g TOMO
    price: '21207.02',
    amount: '0.004693386710283129'
}]).then(data => {
        console.log(data)
    }).catch(e => {
        console.log(e)
    })

Cancel order

After creating an order, you can cancel it with order hash

const orderHash = '0x0' // hash of order you want to cancel
tomox.cancelOrder(orderHash)
    .then(data => {
        console.log(data)
    }).catch(e => {
        console.log(e)
    })

Get account balances

Get the current account balances

tomox.getAccount()
    .then(data => {
        console.log(data)
    }).catch(e => {
        console.log(e)
    })

Get the specify account balances

tomox.getAccount(address)
    .then(data => {
        console.log(data)
    }).catch(e => {
        console.log(e)
    })

Command Line

You need to init env or create .env file to setup DEX_URI and TRADER_PKEY before using the tool.

tomox-cli init

Or

cp .env.example .env

Help:

Usage: tomox-cli [options] [command]

TomoX Market CLI

Options:
  -V, --version                      output the version number
  -C --config <path>                 set config path. defaults to $HOME/.tomoxjs
  -h, --help                         output usage information

Commands:
  init [options]                     setup/init environment
  env                                show environment information
  create [options]                   create a trading order
  cancel [options]                   cancel a trading order or cancel multiple orders
  pairs                              show trading pairs
  o-list|list [options]              show user orders
  o-get|get [options]                show order by hash
  orderbook [options]                show trading orderbook
  ohlcv [options]                    show trading OHLCV data
  info                               show DEX information
  ws-orderbook [options]             watch trading orderbook
  ws-ohlcv [options]                 watch trading OHLCV data
  ws-trades [options]                watch trades
  ws-price-board [options]           watch price board
  ws-markets                         watch trading market
  lending-hash|l-hash [options]      show lending order by hash
  lending-nonce                      show lending user nonce
  lending-create|l-create [options]  create a lending order
  ws-lending-create [options]        create a lending order via websocket
  lending-repay [options]            repay a loan
  lending-topup [options]            topup a loan
  lending-cancel [options]           cancel a lending order
  lending-orderbook [options]        show lending orderbook
  ws-lending-orderbook [options]     watch lending orderbook
  ws-lending-trades [options]        watch lending trades
  ws-lending-ohlcv [options]         watch lending OHLCV data
  lending-pairs                      show lending pairs
  lending-markets [options]          show lending markets
  ws-lending-markets                 watch all lending markets
  lending-tokens|l-tokens            show lending tokens
  collateral-tokens                  show lending collateral tokens
  lending-trades-history [options]   show lending trades
  lending-terms
  lending-orders|l-orders [options]
  lending-trades|l-trades [options]

Create Order CLI

$ ./tomox-cli create --help
Usage: tomox-cli create [options]

Options:
  -b, --baseToken <baseToken>    base token (default: "0xBD8b2Fb871F97b2d5F0A1af3bF73619b09174B2A")
  -q, --quoteToken <quoteToken>  quote token (default: "0x0000000000000000000000000000000000000001")
  -p, --price <price>            price (default: "21207")
  -a, --amount <amount>          amount (default: "00469")
  -s, --side <side>              side (default: "BUY")
  -t, --type <type>              type (default: "LO")
  -h, --help                     output usage information

Cancel Order CLI

$ ./tomox-cli cancel --help
Usage: tomox-cli cancel [options]

Options:
  -s, --hash <hash>    hash
  -n, --nonce <nonce>  nonce (default: 0)
  -h, --help           output usage information

Get User Order List CLI

$ ./tomox-cli orders -h
Usage: tomox-cli orders [options]

Options:
  -b, --baseToken <baseToken>    base token
  -q, --quoteToken <quoteToken>  quote token
  -h, --help                     output usage information

Get Orderbook CLI

$ ./tomox-cli orderbook -h
Usage: tomox-cli orderbook [options]

Options:
  -b, --baseToken <baseToken>    base token
  -q, --quoteToken <quoteToken>  quote token
  -h, --help                     output usage information

Get OHLCV CLI

$ ./tomox-cli ohlcv --help
Usage: tomox-cli ohlcv [options]

Options:
  -b, --baseToken <baseToken>        base token
  -q, --quoteToken <quoteToken>      quote token
  -i, --timeInternal <timeInterval>  time interval, candle size. Valid values: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 1w, 1mo (1 month)
  -h, --help                         output usage information

tomoxjs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

tomoxjs's Issues

Not consistent order response

Hey Tomochain Team,

I am not sure which repository would be the right place concerning this question. Since I worked on the API implementation based on this repo and https://apidocs.tomochain.com/?javascript--node#tomodex-apis I decided to create the issue here.

1.: I dont find minOrderSize in the current api. If the orderSize is too small then I have no chance to recognize it through any API (https://apidocs.tomochain.com/?javascript--node#tomodex-apis-pairs would be right place I guess).

When I fetch again the order (after I created it) with the same order hash it returns null. Basically it returns always null until the order is "opened". I should get always the right order with the right status when I fetch the order, not null... (including the rejected order which is also null)
I saw on your dex that in websocket you give back ORDER_REJECTED order. When I tried to work around with websocket, I didnt get the ORDER_REJECTED response in my websocket. (regardless of my orders subscription). I get the order size related error message and thats it. I dont care too much about websocket right now though. If I can get proper consistent behavior through the rest API its good enough for me.

2.: If I create a market order, the rest API doesnt give me back the calculated price that was used for the market order on the backend. (On your dex you send a price also for the market order which doesnt seem to make sense for me and doesnt match with your documentation either)

Please let me know if you need any additional details / request params / response object. To resolve this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.