diff --git a/README.rst b/README.rst index d7ab837..a977f26 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ ======================================= -Welcome to python-binance-chain v0.1.19 +Welcome to python-binance-chain v0.1.20 ======================================= .. image:: https://img.shields.io/pypi/v/python-binance-chain.svg @@ -89,8 +89,7 @@ If using the production server there is no need to pass the environment variable # Alternatively pass no env to get production prod_client = HttpApiClient() - # connect client to different URL - client = HttpApiClient(api_url='https://yournet.com') + # connect client to different URL using custom environments, see below # get node time time = client.get_time() @@ -128,16 +127,16 @@ If using the production server there is no need to pass the environment variable # get open orders open_orders = client.get_open_orders('tbnb185tqzq3j6y7yep85lncaz9qeectjxqe5054cgn') - # get open orders + # get ticker ticker = client.get_ticker('NNB-0AD_BNB') - # get open orders + # get trades trades = client.get_trades(limit=2) - # get open orders + # get order order = client.get_order('9D0537108883C68B8F43811B780327CE97D8E01D-2') - # get open orders + # get trades trades = client.get_trades() # get transactions @@ -162,6 +161,7 @@ All methods are otherwise the same as the HttpApiClient from binance_chain.http import AsyncHttpApiClient from binance_chain.environment import BinanceEnvironment + import asyncio loop = None @@ -226,6 +226,8 @@ You may also use the `Ledger Wallet class <#ledger>`_ to utilise your Ledger Har It can be initialised with your private key or your mnemonic phrase. +You can additionally provide BIP39 passphrase and derived wallet id. + Note that the BinanceEnvironment used for the wallet must match that of the HttpApiClient, testnet addresses will not work on the production system. @@ -254,7 +256,10 @@ see examples below from binance_chain.environment import BinanceEnvironment testnet_env = BinanceEnvironment.get_testnet_env() - wallet = Wallet.create_wallet_from_mnemonic('mnemonic word string', env=testnet_env) + wallet = Wallet.create_wallet_from_mnemonic('mnemonic word string', + passphrase='optional passphrase', + child=0, + env=testnet_env) print(wallet.address) print(wallet.private_key) print(wallet.public_key_hex) @@ -292,6 +297,8 @@ General case from binance_chain.http import HttpApiClient from binance_chain.messages import NewOrderMsg from binance_chain.wallet import Wallet + from binance_chain.constants import TimeInForce, OrderSide, OrderType + from decimal import Decimal wallet = Wallet('private_key_string') client = HttpApiClient() @@ -300,7 +307,7 @@ General case new_order_msg = NewOrderMsg( wallet=wallet, symbol="ANN-457_BNB", - time_in_force=TimeInForce.GTE, + time_in_force=TimeInForce.GOOD_TILL_EXPIRE, order_type=OrderType.LIMIT, side=OrderSide.BUY, price=Decimal(0.000396000), @@ -363,6 +370,7 @@ General case from binance_chain.http import HttpApiClient from binance_chain.messages import FreezeMsg from binance_chain.wallet import Wallet + from decimal import Decimal wallet = Wallet('private_key_string') client = HttpApiClient() @@ -384,6 +392,7 @@ General case from binance_chain.http import HttpApiClient from binance_chain.messages import UnFreezeMsg from binance_chain.wallet import Wallet + from decimal import Decimal wallet = Wallet('private_key_string') client = HttpApiClient() @@ -510,7 +519,7 @@ See `API `_ check out my `python-binance `_ library. -If you use `Kucoin `_ check out my `python-kucoin `_ library. - -If you use `Allcoin `_ check out my `python-allucoin `_ library. +If you use `Kucoin `_ check out my `python-kucoin `_ library. If you use `IDEX `_ check out my `python-idex `_ library. - -If you use `BigONE `_ check out my `python-bigone `_ library. - -.. image:: https://analytics-pixel.appspot.com/UA-111417213-1/github/python-kucoin?pixel diff --git a/binance_chain/__init__.py b/binance_chain/__init__.py index 069c74c..5c65c53 100644 --- a/binance_chain/__init__.py +++ b/binance_chain/__init__.py @@ -4,4 +4,4 @@ """ -__version__ = '0.1.19' +__version__ = '0.1.20' diff --git a/binance_chain/http.py b/binance_chain/http.py index 3c45e62..69eeeb7 100644 --- a/binance_chain/http.py +++ b/binance_chain/http.py @@ -289,7 +289,7 @@ def get_markets(self): :return: API Response """ - return self._get("markets") + return self._get("markets?limit=1000") def get_fees(self): """Gets the current trading fees settings diff --git a/binance_chain/utils/encode_utils.py b/binance_chain/utils/encode_utils.py index eb02c6b..ce5ed3b 100644 --- a/binance_chain/utils/encode_utils.py +++ b/binance_chain/utils/encode_utils.py @@ -12,7 +12,7 @@ def encode_number(num: Union[float, Decimal]) -> int: if type(num) == Decimal: return int(num * (Decimal(10) ** 8)) else: - return int(num * math.pow(10, 8)) + return int(round(num * 1e8)) def varint_encode(num): diff --git a/binance_chain/wallet.py b/binance_chain/wallet.py index 8df1498..93955a6 100644 --- a/binance_chain/wallet.py +++ b/binance_chain/wallet.py @@ -4,7 +4,7 @@ from secp256k1 import PrivateKey from mnemonic import Mnemonic -from pywallet.utils.bip32 import Wallet as Bip32Wallet +from pycoin.symbols.btc import network from binance_chain.utils.segwit_addr import address_from_public_key, decode_address from binance_chain.environment import BinanceEnvironment @@ -23,7 +23,7 @@ class MnemonicLanguage(str, Enum): class BaseWallet: - HD_PATH = "44'/714'/0'/0/0" + HD_PATH = "44'/714'/0'/0/{id}" def __init__(self, env: Optional[BinanceEnvironment] = None): self._env = env or BinanceEnvironment.get_production_env() @@ -103,8 +103,21 @@ def sign_message(self, msg_bytes): class Wallet(BaseWallet): + """ + Usage example: - HD_PATH = "44'/714'/0'/0/0" + m = Wallet.create_random_mnemonic() # 12 words + p = 'my secret passphrase' # bip39 passphrase + + # Store and

somewhere safe + + wallet1 = Wallet.create_wallet_from_mnemonic(m, passphrase=p, child=0, env=testnet_env) + wallet2 = Wallet.create_wallet_from_mnemonic(m, passphrase=p, child=1, env=testnet_env) + ... + + """ + + HD_PATH = "44'/714'/0'/0/{id}" def __init__(self, private_key, env: Optional[BinanceEnvironment] = None): super().__init__(env) @@ -118,22 +131,39 @@ def create_random_wallet(cls, language: MnemonicLanguage = MnemonicLanguage.ENGL env: Optional[BinanceEnvironment] = None): """Create wallet with random mnemonic code - :return: + :return: initialised Wallet """ - m = Mnemonic(language.value) - phrase = m.generate() + phrase = cls.create_random_mnemonic(language) return cls.create_wallet_from_mnemonic(phrase, env=env) @classmethod - def create_wallet_from_mnemonic(cls, mnemonic: str, env: Optional[BinanceEnvironment] = None): - """Create wallet with random mnemonic code + def create_wallet_from_mnemonic(cls, mnemonic: str, + passphrase: Optional[str] = '', + child: Optional[int] = 0, + env: Optional[BinanceEnvironment] = None): + """Create wallet from mnemonic, passphrase and child wallet id - :return: + :return: initialised Wallet """ - seed = Mnemonic.to_seed(mnemonic) - new_wallet = Bip32Wallet.from_master_secret(seed=seed, network='BTC') - child = new_wallet.get_child_for_path(Wallet.HD_PATH) - return cls(child.get_private_key_hex().decode(), env=env) + if type(child) != int: + raise TypeError("Child wallet id should be of type int") + + seed = Mnemonic.to_seed(mnemonic, passphrase) + new_wallet = network.keys.bip32_seed(seed) + child_wallet = new_wallet.subkey_for_path(Wallet.HD_PATH) + # convert secret exponent (private key) int to hex + key_hex = format(child_wallet.secret_exponent(), 'x') + return cls(key_hex, env=env) + + @classmethod + def create_random_mnemonic(cls, language: MnemonicLanguage = MnemonicLanguage.ENGLISH): + """Create random mnemonic code + + :return: str, mnemonic phrase + """ + m = Mnemonic(language.value) + phrase = m.generate() + return phrase @property def private_key(self): diff --git a/docs/changelog.rst b/docs/changelog.rst index 142436e..946800b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,17 @@ Changelog ========= +v0.1.20 - 2019-06-29 +^^^^^^^^^^^^^^^^^^^^ + +**Added** + +- Multi Transfer Msg option + +**Fixed** + +- Response code of 0 for http requests + v0.1.19 - 2019-04-30 ^^^^^^^^^^^^^^^^^^^^ diff --git a/requirements.txt b/requirements.txt index 64a8a9b..93c63e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -pywallet>=0.1.0 +pycoin>=0.90.20201031 requests>=2.21.0 aiohttp>=3.5.4 websockets>=7.0 secp256k1>=0.13.2 mnemonic>=0.18 -protobuf>=3.6.1 \ No newline at end of file +protobuf>=3.6.1 diff --git a/setup.py b/setup.py index 1358da2..598059d 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def find_version(*file_paths): def install_requires(): requires = [ - 'pywallet>=0.1.0', 'requests>=2.21.0', 'websockets>=7.0', 'aiohttp>=3.5.4', + 'pycoin>=0.90.20201031', 'requests>=2.21.0', 'websockets>=7.0', 'aiohttp>=3.5.4', 'secp256k1>=0.13.2', 'protobuf>=3.6.1', 'mnemonic>=0.18', 'ujson>=1.35' ] return requires