scientistnik / btsdex

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

Getting market/ticker information #16

Closed useo6 closed 5 years ago

useo6 commented 5 years ago

At first: Thank you for providing us such an amazing library. I'm pretty new using this library and I'm using this library for my account created using Crypto-Bridge. Unfortunately I've some questions:

  1. How to get a list of all available markets or symbols? I know there's the "BitShares.ticker" function, but it returns information for a specific market (e.g. btc/usd) only.

  2. When I call something like "BitShares.ticker('btc', 'dgb')" or "BitShares.ticker('btc', 'ppo')", it throws me the following exception: "Assert Exception: assets[1]: Invalid quote asset symbol: PPO". But the PPO market is available.

I hope anyone has an idea I can retrieve these information. Thank you in advance!

scientistnik commented 5 years ago
  1. Creating a new asset automatically creates markets for all existing assets. Most of them do not have liquidity, but any asset can be traded to any other. I did not find an API method for getting all assets. Maybe you need to make a list of assets and make requests for them.

  2. Be careful. Crypto-Bridge create assets with the prefix BRIDGE

    $ btsdex --asset ppo
    Connected to API node: wss://bitshares.openledger.info/ws
    Error: Not found asset PPO! Blockchain return PPP

    but

    $ btsdex --asset bridge.ppo
    Connected to API node: wss://bitshares.openledger.info/ws
    {
    "id": "1.3.4513",
    "symbol": "BRIDGE.PPO",
    "precision": 7,
    "issuer": "1.2.374566",
    "options": {
    "max_supply": "200000000000000",
    "market_fee_percent": 20,
    "max_market_fee": "400000000000",
    "issuer_permissions": 5,
    "flags": 5,
    "core_exchange_rate": {
      "base": {
        "amount": 100000,
        "asset_id": "1.3.0"
      },
      "quote": {
        "amount": 20000000,
        "asset_id": "1.3.4513"
      }
    },
    "whitelist_authorities": [],
    "blacklist_authorities": [],
    "whitelist_markets": [],
    "blacklist_markets": [],
    "description": "{\"main\":\"PICPOTO\",\"short_name\":\"PPO\",\"market\":\"BRIDGE.BTC\"}",
    "extensions": []
    },
    "dynamic_asset_data_id": "2.3.4513"
    }

Try

BitShares.ticker('btc', 'bridge.ppo')

or if you need to use bitcoin from Crypto-Bridge

BitShares.ticker('bridge.btc', 'bridge.ppo')
useo6 commented 5 years ago

Regarding the first topic, I decided to decode the Crypto-Bridge ticker. Regarding topic 2... this works like a perfectly.

But I've two more questions:

  1. How can I catch the error-event? For example if there's no internet connection, I'm getting the ENOTFOUND-error. How to catch the error?

  2. Can I disable the ws-output? When I subscribe it outputs "WebSocket status: open". Is there any way to disable this output?

scientistnik commented 5 years ago

For catch error, try:

process.on('unhandledRejection', (reason, p) => {
  console.error(`Unhandled Rejection at: ${p} reason: ${reason}`);
});

Currently you can not disable the ws-output.

useo6 commented 5 years ago

Thank you scientistnik. This helped me a lot! One last question... do you know how I can get a list of trades, deposits or withdrawals I've done in the past?

scientistnik commented 5 years ago

Get history account objects:

await BitShares.history.get_account_history(<account_id>, "1.11.0", 100, "1.11.0") // last 100 operations
useo6 commented 5 years ago

Ah, I see. Thank you scientistnik. I've two last questions... how to generate a new address for an asset and how to withdraw from an asset?

scientistnik commented 5 years ago

What you mean "new address"?

useo6 commented 5 years ago

I mean on CryptoBridge I can click on "Get New Address" and I'm getting a new deposit address for the corresponding asset.

scientistnik commented 5 years ago

You need to ask this from CryptoBridge)