scientistnik / btsdex

Package for work with BitShares DEX
MIT License
21 stars 27 forks source link

Example request #5

Closed wmbutler closed 6 years ago

wmbutler commented 6 years ago

I'm trying to get a quote for bts / usd. When I run this, I get an error instead of a quote. Would you mind adding an example to the readme? Much appreciated.

Code

const Bitshares = require('btsdex');
KEY = 'redacted';
ACCOUNT = 'billbutler-trade1';
sellSymbol = 'bts';
baseSymbol = 'usd';
amount = 1;
price = 0.4;

Bitshares.init('wss://api.btsxchng.com');

async function startAfterConnected() {

    let bot = new Bitshares(ACCOUNT,KEY);

    console.log(await Bitshares.ticker('bts','usd'));

    console.log('!');

    // bot.sell(sellSymbol, baseSymbol, amount, price, fill_or_kill = false, expire = "2020-02-02T02:02:02");
    // console.log(await bot.ticker('bts','usd'));
    // console.log(await bot.cancelOrder('1.7.66769046'));

}

Bitshares.subscribe('connected', startAfterConnected);
Bitshares.connect();

Response

connected to: { core_asset: 'BTS',
  address_prefix: 'BTS',
  chain_id: '4018d7844c78f6a6c41c6a552b898022310fc5dec06da467ee7905a8dad512c8' }
!
(node:9513) UnhandledPromiseRejectionWarning: #<Object>
(node:9513) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:9513) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
wmbutler commented 6 years ago

This works. I think the previous issue was due to assets being referenced in lowercase.

console.log(await Bitshares.db.get_ticker('BTS','USD'));
scientistnik commented 6 years ago

Update package. Now v0.2.4 it's work. About examples: I am working on a description of all functions with examples. You may see it here