Package for work with BitShares DEX
This library can be obtained through npm:
npm install btsdex
btsdex package contain class BitShares:
const BitShares = require('btsdex')BitShares contains static methods for work with public API, and dynamic methods for work with wallet API.
Example initialization:
BitShares.init('wss://bitshares.openledger.info/ws')After initialization, you can connect:
BitShares.connect()BitShares.connect() return Promise, resolve it when connection consists.
You may to subscribe to connection event:
BitShares.subscribe('connected',functionToCall)After connection, you may call public api methods. For example BitShares.db return wrapper for database API:
BitShares.db.get_objects(["1.3.0"])
BitShares.db.list_assets("BTS",100)BitShares.history is wrapper for history API:
BitShares.history.get_market_history("1.3.121","1.3.861","2018-04-04T20:12:22","2018-04-01T20:12:22",86400)If you want access to private API, you need create object from BitShares class:
let bot = new BitShares('accountName','privateActiveKey')bot have buy,sell and cancelOrder methods:
bot.buy(buySymbol, baseSymbol, amount, price, fill_or_kill = false, expire = "2020-02-02T02:02:02")
bot.sell(sellSymbol, baseSymbol, amount, price, fill_or_kill = false, expire = "2020-02-02T02:02:02")
bot.cancelOrder(id)const BitShares = require('btsdex')
KEY = 'privateActiveKey'
BitShares.init('wss://bitshares.openledger.info/ws')
async function startAfterConnected() {
let bot = new BitShares('trade-bot',KEY)
let iam = await BitShares.accounts['trade-bot'];
let orders = await BitShares.db.get_full_accounts([iam.id],false);
orders = orders[0][1].limit_orders;
let order = orders[0].sell_price;
console.log(order)
}
BitShares.subscribe('connected',startAfterConnected)
BitShares.connect()For more information, look wiki.
Bug reports and pull requests are welcome on GitHub.
The package is available as open source under the terms of the MIT License.