BitShares Forum

Main => Technical Support => Topic started by: j-v-h-silver on April 11, 2017, 08:44:42 pm

Title: pybitshares
Post by: j-v-h-silver on April 11, 2017, 08:44:42 pm
Hello All from a newbie
As per a suggestion from Xeroc to use pybitshares for Bot type functions ( since I couldn't get stakemachine permisions eror solved : see https://bitsharestalk.org/index.php/topic,23939.msg304190.html#msg304190  ) I have started trying out the scripts in http://docs.pybitshares.com/en/latest/tutorials.html to see what can be done there.
In particular after installing as per the intro I tried the Simple Sell script modified for the testnet account "AAB-12345" .
but get bitshares.exceptions.NoWalletException .
I have looked at the pybitshares documentation but its not clear how to specify what wallet is being used?
That is how do you get Python to access a particular wallet on a Ubuntu VM that I am testing on?
Thanks for any help
Cheers John

=========================================================
from bitshares import BitShares
from bitshares.market import Market
from bitshares.price import Price
from bitshares.amount import Amount

#
# Instanciate BitShares (pick network via API node)
#
bitshares = BitShares(
    "wss://node.testnet.bitshares.eu",
    nobroadcast=False   # <<--- set this to False when you want to fire!
)

#
# Unlock the Wallet
#
bitshares.wallet.unlock("AAB-12345")

#
# This defines the market we are looking at.
# The first asset in the first argument is the *quote*
# Sell and buy calls always refer to the *quote*
#
market = Market(
    "GOLD:TEST",
    bitshares_instance=bitshares
)

#
# Sell an asset for a price with amount (quote)
#
print(market.sell(
    Price(10.0, "TEST/GOLD"),
    Amount("0.01 GOLD")
))
=========================================================

vagrant@vagrant-ubuntu-trusty-64:~/py$ python3 ./ssell.py
Traceback (most recent call last):
  File "./ssell.py", line 17, in <module>
    bitshares.wallet.unlock("AAB-12345")
  File "/usr/local/lib/python3.4/dist-packages/bitshares/wallet.py", line 107, in unlock
    raise NoWalletException
bitshares.exceptions.NoWalletException
Title: Re: pybitshares
Post by: j-v-h-silver on April 11, 2017, 09:19:59 pm
Hello all
I should say that I did try to create and open a wallet with the info from http://docs.pybitshares.com/en/latest/wallet.html below but it comes back with ValueError: You need to provide an account

Could someone who knows the pybitshares library please post a script that shows how to open a  wallet and currently existing account on the testnet and prepares Python for the other actions in the tutorials like selling etc please.
I am trying to get my head around Python and the Library but I seem to be hitting catch 22's a lot.

Many thanks for any help
Regards John

A new wallet can be created by using:
from bitshares import BitShares

bitshares = BitShares(
    "wss://node.testnet.bitshares.eu",
    nobroadcast=False   # <<--- set this to False when you want to fire!
)
bitshares.wallet.create("AAB-12345")


The wallet can be unlocked for signing using:
from bitshares import BitShares
bitshares = BitShares()
bitshares.wallet.unlock("AAB-12345")

from bitshares.account import Account
account = Account("AAB-12345")
print(account)
print(account.balances)
Title: Re: pybitshares
Post by: xeroc on April 12, 2017, 11:30:06 am
Code: [Select]
from bitshares import BitShares

bitshares = BitShares(
    "wss://node.testnet.bitshares.eu",
    nobroadcast=False   # <<--- set this to False when you want to fire!
)
bitshares.wallet.create("AAB-12345")
This will create a new wallet ans use AAB-12345 as the passphrase for the local wallet.

Afterwards, you will need to import a private key into your wallet by using

Code: [Select]
bitshares.wallet.addPrivateKey('5xxxxxxxxxxxx')

Then, you can use your wallet (after unlocking with the password "AAB-12345") like shown in the examples.


I highly recommend you install `uptick` to deal with your pybitshares wallet, settings and adding keys and stuff.