Author Topic: Very slow market buy with pybitshares API  (Read 768 times)

0 Members and 1 Guest are viewing this topic.

Offline ParadoximA

  • Newbie
  • *
  • Posts: 14
    • View Profile
  • BitShares: bob-bot
Very slow market buy with pybitshares API
« on: July 29, 2017, 05:13:26 pm »
Hi everyone. I've been trying out the pybitshares API and can get it to do almost everything I need. However, when I buy or sell on the market, it takes between 10 and 20 minutes before the transaction shows up. During that time, python is using a lot of CPU. Am I doing something wrong, or is that normal? Market queries etc are instant. Buying and selling with the web interface is also instant. When I added the private key, it also took several minutes (I thought python had crashed, and I restarted it a few times, before allowing it to finally add the key).

Here's what I did:
I created a new account (account model) using my browser, then created a new wallet using the pybitshares API, then imported my private key (bitshares.wallet.addPrivateKey('xxxxx')).

Below is the code that produces the problem.
Code: [Select]
from bitshares import BitShares
from bitshares.market import Market
from bitshares.price import Price
from bitshares.amount import Amount
from bitshares.account import Account
import time

account = Account("xxxxx")
Node1="wss://bitshares.openledger.info/ws"#Nuremberg, Germany
bitshares=BitShares(Node1,nobroadcast=False)
market = Market("BTS:USD")
print(market.bitshares.wallet.unlock("xxxxx"))
USD_Bal=account.balance('USD')
print('Buying BTS')
print(market.buy(\
    Price(0.115, "USD/BTS"),\
    Amount(USD_Bal/0.115*0.5, "BTS"),\
    account="xxxxx",\
    returnOrderId='head'\
    ))

I've tried without the returnOrderId='head' setting, it's still slow. Any ideas?
« Last Edit: July 29, 2017, 09:31:43 pm by ParadoximA »

Offline paliboy

Re: Very slow market buy with pybitshares API
« Reply #1 on: July 29, 2017, 08:37:58 pm »
Is it slow when you use Uptick (http://uptick.rocks)?

Offline ParadoximA

  • Newbie
  • *
  • Posts: 14
    • View Profile
  • BitShares: bob-bot
Re: Very slow market buy with pybitshares API
« Reply #2 on: July 29, 2017, 08:46:38 pm »
I haven't tried uptick yet, I'm installing it now. I see it needs Visual C++ Build Tools, this could take a while...

Offline ParadoximA

  • Newbie
  • *
  • Posts: 14
    • View Profile
  • BitShares: bob-bot
Re: Very slow market buy with pybitshares API
« Reply #3 on: July 29, 2017, 09:29:57 pm »
Is it slow when you use Uptick (http://uptick.rocks)?
I tried installing uptick to test this, but got errors with the pip install and the manual install, even after installing Visual C++ Build Tools. I'll troubleshoot further tomorrow.

FYI - the last few lines of the failed install:
Code: [Select]
Writing C:\Users\xxxxx\AppData\Local\Temp\easy_install-t2ll6vmc\scrypt-0.8.0\setup.cfg
Running scrypt-0.8.0\setup.py -q bdist_egg --dist-dir C:\Users\xxxxx\AppData\Local\Temp\easy_install-t2ll6vmc\scrypt-0.8.0\egg-dist-tmp-rlrb2hdn
scrypt.c
scrypt-1.2.0/lib/crypto\crypto_scrypt.h(33): fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory
error: Setup script exited with error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

Offline ParadoximA

  • Newbie
  • *
  • Posts: 14
    • View Profile
  • BitShares: bob-bot
Re: Very slow market buy with pybitshares API
« Reply #4 on: July 29, 2017, 10:34:13 pm »
Uptick is working, even with the installation errors. I tested a market buy, and it also took 10 - 20 minutes before it showed up on the market and I could use the command line again.

Offline ParadoximA

  • Newbie
  • *
  • Posts: 14
    • View Profile
  • BitShares: bob-bot
Re: Very slow market buy with pybitshares API
« Reply #5 on: March 12, 2018, 08:10:33 pm »
After a lot of troubleshooting, I've finally resolved this issue. I believe that many Windows users will encounter the same problem, so here's how to get pybitshares working on a Windows PC:

(Some of these steps are probably unnecessary... but I can't be sure which ones are the most important)

First, install Visual Studio Community 2017 (https://www.visualstudio.com/downloads/)
Even if you've already installed this previously, there are updates that may be required, as new components have been added recently. To do this, search the start menu for "Apps & Features", find Visual Studio Community 2017, and click "update". When that's done, click "modify".
Make sure that you select the "Individual Components" tab, then scroll down to "Components, build tools and runtimes".
These are the components that I have selected (you definitely don't need all of these - but this combination works for me):

    C# and Visual Basic Roslyn compilers
    C++/CLI support
    MSBuild
    Python 2 32-bit (2.7.14)
    Python 2 64-bit (2.7.14)
    Python 3 32-bit (3.6.3)
    Python 3 64-bit (3.6.3)
    VC++ 2015.3 v140 toolset for desktop (x86,x64)
    VC++ 2017 v141 toolset (x86,x64)
    Visual C++ compilers and libraries for ARM
    Visual C++ runtime for UWP
    Visual C++ tools for CMake
    Windows Universal CRT SDK

Once all those are selected, click "Modify".

Then, from the start menu, search for "x64 Native Tools Command Prompt for VS 2017". Right click it, and "Run as administrator" (IMPORTANT!). Then run the following commands:

    pip uninstall bitshares
    pip uninstall pycryptodome
    pip uninstall cryptography
    pip install cryptography
    pip install pycryptodome
    pip install bitshares

You're done! pybitshares should now work correctly!

Why does this work?
I believe that the pycryptodome and/or cryptography installs can be broken if you don't have the correct Visual Studio Compiler Tools installed and added to the PATH environment variable. Any attempt to update these tools later will appear successful, but the initial install remains broken. The type of error messages you will see when you first try to install pybitshares will be similar to:
    "cl.exe failed with exit status 2"
    "error: command 'cl.exe' failed: No such file or directory"
    "Cannot open include file: 'openssl/aes.h': No such file or directory"
    ...and other openssl related errors.

Oddly, with a broken install, all the pybitshares commands will still work - but any command that sends information to the blockchain will take 10 - 20 minutes instead of 1 - 2 seconds.

I hope this helps somebody!

Offline abit

  • Committee member
  • Hero Member
  • *
  • Posts: 3137
    • View Profile
    • Steemit Blog
  • BitShares: abit
  • GitHub: abitmore
Re: Very slow market buy with pybitshares API
« Reply #6 on: March 12, 2018, 09:26:22 pm »
Useful info. Thank you.
BTS account: abit
BTS committee member: abit
BTS witness: in.abit

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12550
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Re: Very slow market buy with pybitshares API
« Reply #7 on: March 13, 2018, 02:05:08 pm »
I don't know much about VS, but I can tell you that you can greatly improve signing speed by installing
pip3 install scrypt
and
pip3 install secp256k1
Give BitShares a try! Use the http://testnet.bitshares.eu provided by http://bitshares.eu powered by ChainSquad GmbH

Offline ParadoximA

  • Newbie
  • *
  • Posts: 14
    • View Profile
  • BitShares: bob-bot
Re: Very slow market buy with pybitshares API
« Reply #8 on: March 17, 2018, 06:00:19 pm »
Thanks again xeroc, and thanks for all your work on pybitshares, it's appreciated!

I see scrypt was already installed, perhaps it installs with pybitshares. I've installed secp256k1, I'll take a look at it.

Offline litepresence

  • Full Member
  • ***
  • Posts: 71
    • View Profile
Re: Very slow market buy with pybitshares API
« Reply #9 on: March 18, 2018, 03:23:05 pm »
I don't know much about VS, but I can tell you that you can greatly improve signing speed by installing
pip3 install scrypt
and
pip3 install secp256k1

perhaps these should auto install w/ uptick and pybitshares?

are there any other unmentioned "dependencies"?

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12550
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Re: Very slow market buy with pybitshares API
« Reply #10 on: March 24, 2018, 12:56:35 pm »
Fortunately, latest release of graphenelib has seen a 3rd party patch that improves signing without secp256k1 package .. Thanks to the contributor
Give BitShares a try! Use the http://testnet.bitshares.eu provided by http://bitshares.eu powered by ChainSquad GmbH