-
Notifications
You must be signed in to change notification settings - Fork 28
class BitShares
Nikolay Nozdrin-Plotnitsky edited this page May 10, 2018
·
3 revisions
-
Static methods
- init()
- connect()
- subscribe()
- generateKeys()
- ticker()
- tradeHistory()
-
Object methods
- constructor()
- setFeeAsset()
- setMemoKey()
- balances()
- buy()
- sell()
- transfer()
- cancelOrder()
- orders()
Signature:
static init(node = "wss://bitshares.openledger.info/ws", autoconnect = false)
Signature:
static async connect()
const BitShares = require('btsdex');
async function start() {
BitShares.init();
await BitShares.connect();
// Do something...
}
start()
Signature:
static subscribe(event, callback)
Now have events:
-
connected
- works once after connecting to the blockchain; -
block
- it works when a new block is created in the blockchain; -
account
- occurs when the specified account is changed (balance change).
const BitShares = require("btsdex");
BitShares.init("wss://bitshares.openledger.info/ws");
BitShares.subscribe('connected', startAfterConnected);
BitShares.subscribe('block', callEachBlock);
BitShares.subscribe('account', changeAccount, 'trade-bot');
async function startAfterConnected() {/* is called once after connecting to the blockchain */}
async function callEachBlock(obj) {/* is called with each block created */}
async function changeAccount(array) {/* is called when you change the 'trade-bot' account */}
Signature:
static generateKeys(name, password, arrKeysName)
This method need if you know only login and password. And you need active and memo private keys. This method will be change!
const BitShares = require("btsdex");
BitShares.init("wss://bitshares.openledger.info/ws");
keys = BitShares.generateKeys('trade-bot', 'password', ['owner','active','memo']);
console.log(keys); //{ privKeys:{ owner:..., active:..., memo:...}, pubKeys:{ owner:..., active:..., memo:...}}
let acc = new BitShares('trade-bot', keys.privKeys.active.toWif());
Signature:
static async ticker(baseSymbol, quoteSymbol)
const BitShares = require('btsdex');
async function start() {
BitShares.init();
await BitShares.connect();
let ticker = await BitShares.ticker('usd', 'bts');
console.log(ticker); // { latest: '0.3857908',lowest_ask: ... }
}
start()
Signature:
static async tradeHistory(quoteSymbol, baseSymbol, startDate, stopDate, bucketSeconds)
const BitShares = require('btsdex');
async function start() {
BitShares.init();
await BitShares.connect();
let start = new Date();
start.setMonth(start.getMonth() - 1); // Month back
let stop = new Date();
let data = await BitShares.tradeHistory("usd","bts", start, stop, 60 * 60 * 24));
console.log(data); // [{high_base:..., low_quote:...}, {...}]
}
start()
Signature:
constructor(accountName, activeKey, feeSymbol = 'bts')
Signature:
async setFeeAsset(feeSymbol)
Signature:
setMemoKey(memoKey)
Signature:
async balances()
const BitShares = require('btsdex');
BitShares.init();
BitShares.subscribe('connected', start);
async function start() {
let bot = new BitShares('trade-bot', 'privateActiveKey');
console.log(await bot.balances()); // [{ amount: 117669, asset: Asset {id: '1.3.0',...} },{...}]
}
Signature:
async buy(buySymbol, baseSymbol, amount, price, fill_or_kill = false, expire = "2020-02-02T02:02:02")
const BitShares = require('btsdex');
BitShares.init();
BitShares.subscribe('connected', start);
async function start() {
let bot = new BitShares('trade-bot', 'privateActiveKey');
await bot.buy('open.btc', 'bts', 0.0043, 31000);
}
Signature:
async sell(sellSymbol, baseSymbol, amount, price, fill_or_kill = false, expire = "2020-02-02T02:02:02")
const BitShares = require('btsdex');
BitShares.init();
BitShares.subscribe('connected', start);
async function start() {
let bot = new BitShares('trade-bot', 'privateActiveKey');
await bot.sell('open.btc', 'bts', 0.0043, 31000);
}
Signature:
async transfer(toName, assetSymbol, amount, memo)
const BitShares = require("btsdex");
async function start() {
BitShares.init("wss://bitshares.openledger.info/ws");
await BitShares.connect();
let bot = new BitShares("name-account", "yourPrivateActiveKey");
await bot.transfer("scientistnik","BTS", 10);
}
Signature:
async cancelOrder(id)
Signature:
async orders()
const BitShares = require('btsdex');
BitShares.init();
BitShares.subscribe('connected', start);
async function start() {
let bot = new BitShares('trade-bot', 'privateActiveKey');
console.log(await bot.orders()); // [{ id: '1.7.49552602', seller: ..., ... },{...}]
}