hiveengine - a python library for hive-engine.com

Repository

https://github.com/holgern/hiveengine

image.png

hiveengine

hiveengine is a python library for working with hive-engine.com tokens.

I released version 0.1.3 which can be installed by

pip install hiveengine

hiveengine is using beem for broadcasting transfers and custom_json to the HIVE blockchain. hiveengine is only working when using HIVE nodes. You can check the currently set nodes with

beem config

Hive nodes can be set with

beem updatenodes --hive

API

hiveengine is using the following API endpoint: https://api.hive-engine.com/rpc/ . For depositing HIVE inside hiveengine, HIVE is send to @honey-swap. For all other operations, custom_jsons with the ssc-mainnet-hive id are broadcast.

CLI tool

The packages comes with a command line tool which can be used with parameters or in shell mode when no parameter is set.

shell mode

hiveengine

starts it and you have now the following commands:

Starting hiveengine... (use help to list all commands)
hiveengine>
buy            cancel-unstake help           quit           sellbook       unstake
buybook        deposit        info           richlist       stake          withdraw
cancel         exit           issue          sell           transfer

normal mode

Append a command to use hiveengine in normal mode, e.g.:

hiveengine info

Usage

Latest block

Get the latest block of the side-chain

from hiveengine.api import Api
api = Api()
latest_block = api.get_latest_block_info()

The command line tool can also be used:

hiveengine info

returns

+--------------------------+---------------------+
| Key                      | Value               |
+--------------------------+---------------------+
| latest block number      | 5435                |
| latest hive block        | 42498000            |
| latest timestamp         | 2020-04-13T06:58:57 |
| transactions             | 0                   |
| virtualTransactions      | 1                   |
| Number of created tokens | 57                  |
+--------------------------+---------------------+

Specific side-chain block

Get the block with the specified block number of the side-chain

from hiveengine.api import Api
api = Api()
print(api.get_block_info(1000))

or with CLI

hiveengine info 1000

Specific transaction trx

Retrieve the specified transaction info of the side-chain. The number behind the - sign selects an operation when there are more than one transaction inside a transaction.

from hiveengine.api import Api
api = Api()
print(api.get_transaction_info("faa0af0e27dd4ebe036fd90f36b354e6e1360221"))
print(api.get_transaction_info("b8a3a01ce2d728b44b42d5b8e9fcc661489f33f4-1"))

or with CLI

hiveengine info b8a3a01ce2d728b44b42d5b8e9fcc661489f33f4-1

Contracts

Get the contract specified from the database

from hiveengine.api import Api
api = Api()
print(api.get_contract("tokens"))

Find information about tokens

Get an array of objects that match the query from the table of the specified contract

from hiveengine.api import Api
api = Api()
print(api.find("tokens", "tokens"))

Get the object that matches the query from the table of the specified contract

from hiveengine.api import Api
api = Api()
print(api.find("tokens", "tokens", query={"symbol": "BEE"}))

or with CLI:

hiveengine info FOODIE
Token: FOODIE
+------------------------+-----------------+
| Key                    | Value           |
+------------------------+-----------------+
| _id                    | 33              |
| issuer                 | foodiesunite    |
| symbol                 | FOODIE          |
| name                   | Foodies Bee Hive|
| metadata_url           | foodiesunite.net|
...

Receive token holder

from hiveengine.api import Api
api = Api()
print(api.find("tokens", "balances", query={"symbol": "BEE"}))

This can also be done with the tokenobject class:

from hiveengine.tokenobject import Token
token = Token("BEE")
print(token.get_holder())

or with CLI:

hiveengine richlist BEE
+------------------+------------------+--------------+
| Balance          | Account          | Value [HIVE] |
+------------------+------------------+--------------+
| 1382218.42922197 | hive-engine      | 1382218.429  |
| 25900.00000000   | null             | 25900.000    |
| 10255.00000000   | cryptomancer     | 10255.000    |

Buybook

from hiveengine.api import Api
api = Api()
print(api.find("market", "buyBook", query={"symbol": "BEE"}))

or by using the market class:

from hiveengine.market import Market
market = Market()
print(market.get_buy_book("BEE"))

or with CLI:

hiveengine buybook BEE
+----------+---------------+---------------+------------+
| order_id | account       | quantity      | price      |
+----------+---------------+---------------+------------+
| 135      | musicvoter    | 0.25000000    | 0.90000000 |
| 117      | musicvoter    | 1.00000000    | 0.60000100 |
| 118      | musicvoter    | 5.00000000    | 0.60000100 |
| 102      | ironshield    | 5.00000000    | 0.60000000 |
| 138      | indextrader24 | 100.00000000  | 0.52000001 |

Sellbook

from hiveengine.api import Api
api = Api()
print(api.find("market", "sellBook", query={"symbol": "BEE"}))

or by using the market class:

from hiveengine.market import Market
market = Market()
print(market.get_sell_book("BEE"))

or with CLI:

hiveengine sellbook BEE
+----------+-------------+----------------+------------+
| order_id | account     | quantity       | price      |
+----------+-------------+----------------+------------+
| 1        | hive-engine | 75689.36100000 | 1.00000000 |
| 2        | hive-engine | 1.00000000     | 1.01000000 |
+----------+-------------+----------------+------------+

Transfering/Staking and Unstaking token

The wallet object can be used to transfer/stake/unstake token:

from hiveengine.wallet import Wallet
from beem import Steem
from beem.nodelist import NodeList
import getpass
nodelist = NodeList()
nodelist.update_nodes()
active_wif = getpass.getpass("active wif: ")
stm = Steem(node=nodelist.get_hive_nodes(), keys=[active_wif])
account = stm.wallet.getAccountFromPrivateKey(active_wif)
wallet = Wallet(account, steem_instance=stm)
wallet.transfer("holger80", 1, "FOODIE", "test")
wallet.stake(1, "FOODIE")
wallet.stake(1, "FOODIE", receiver="holger80")
wallet.unstake(1, "FOODIE")
wallet.cancel_unstake("faa0af0e27dd4ebe036fd90f36b354e6e1360221")

This can also be done with the CLI

hiveengine transfer -a beembot holger80 1 FOODIE test
hiveengine stake -a beembot 1 FOODIE
hiveengine stake -a beembot -r holger80 1 FOODIE
hiveengine unstake -a beembot 1 FOODIE
hiveengine cancel-unstake -a beembot faa0af0e27dd4ebe036fd90f36b354e6e1360221

Market operation

The market object can be used for market operation

from hiveengine.market import Market
from beem import Steem
from beem.nodelist import NodeList
import getpass
nodelist = NodeList()
nodelist.update_nodes()
active_wif = getpass.getpass("active wif: ")
stm = Steem(node=nodelist.get_hive_nodes(), keys=[active_wif])
account = stm.wallet.getAccountFromPrivateKey(active_wif)
market = Market(steem_instance=stm)
print(market.get_metrics()) # returns all tokens
print(market.get_buy_book("BEE"))
print(market.get_sell_book("BEE"))
market.withdraw(account, 1) # withdraw 1 SWAP.HIVE
market.deposit(account, 1)# transfer 1 HIVE to honey-swap
market.buy(account, 1, "BEE", 0.9) # place buy order for 1 BEE for 0.9 HIVE/BEE
market.sell(account, 1 "BEE", 1.1) # place sell order for 1 BEE for 1.1 HIVE/BEE
market.cancel(account, "buy", 12) # cancel buy order with id 12

These operation can also be performed with the CLI:

hiveengine withdraw -a beembot 1
hiveengine deposit -a beembot 1
hiveengine buy -a beembot 1 BEE 0.9
hiveengine sell -a beembot 1 BEE 1.1
hiveengine cancel -a beembot buy 12

If you like what I do, consider casting a vote for me as witness on Hivesigner or on PeakD.

H2
H3
H4
3 columns
2 columns
1 column
11 Comments
Ecency