- Saved searches
- Use saved searches to filter your results more quickly
- License
- CodeReclaimers/btce-api
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Welcome to Bitcoinlib’s documentation!
- Wallet
- Segregated Witness Wallet
- Wallet from passphrase with accounts and multiple currencies
- Multi Signature Wallets
- Command Line Tool
- Service providers
- Other Databases
- More examples
- Disclaimer
- Schematic overview
- Indices and tables
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Python wrapper around the public and trading APIs of BTC-e.com
License
CodeReclaimers/btce-api
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
NOTE: Due to the closure of BTC-e, this repository is no longer being maintained. I am leaving it here in case some of the code proves useful for the development of similar tools for other exchanges.
This library provides a wrapper (hopefully a convenient one) around the public and trading APIs of the BTC-e.com exchange site. So that you don’t have to spend your time chasing down wacky dependencies, it depends only on the Python standard library.
NOTE: Some of the samples use matplotlib and NumPy, so you may need to install additional packages to run all the samples.
NOTE: BTC-e is not affiliated with this project; this is a completely independent implementation based on the API description. Use at your own risk.
If you find the library useful and would like to donate (and many thanks to those that have donated!), please send some coins here:
LTC LatrKXtfw66LQUURrxBzCE7cxFc9Sv8FWf BTC 16vnh6gwFYLGneBa8JUk7NaXpEt3Qojqs1 DOGE D5jNqRjwxhDZT4hkG8yoGkseP576smjyNx
The following functions in the btceapi module access the public API and/or scrape content from the main page, and do not require any user account information:
getDepth(pair) - Retrieve the depth for the given pair. Returns a tuple (asks, bids); each of these is a list of (price, volume) tuples. See the example usage in samples/show_depth.py. getTicker(pair) - Retrieve the ticker information (high, low, avg, etc.) for the given pair. Returns a Ticker instance, which has members high, low, avg, vol, vol_cur, last, buy, sell, updated, and server_time. getTradeFee(pair) - Retrieve the fee (in percent) associated with trades for a given pair. getTradeHistory(pair) - Retrieve the trade history for the given pair. Returns a list of Trade instances. Each Trade instance has members trade_type (either "bid" or "ask"), price, tid (transaction ID?), amount, and date (a datetime object). scrapeMainPage() - Collect information from the main page and return it in a ScraperResults object. This object has members 'messages' (a list of (message ID, user, time, text) tuples representing the chat messages currently visible on the main page, 'bitInstantReserves' (an integer value representing the current BitInstant reserves), and 'aurumXchangeReserves' (an integer value representing the current AurumXchange reserves).
All of the functions above also take an optional ‘connection’ argument, which should be an instance of BTCEConnection. This will speed up multiple function calls, as a new connection will not have to be created for every call.
The TradeAPI class in the btceapi module accesses the trading API, and requires a KeyHandler object. The KeyHandler manages your API key and secret values (found under «API Keys» on the Profile page), stored in a text file. For instructions on creating this text file, please see step 9 here:
https://github.com/alanmcintyre/btce-bot/wiki/Getting-started
The following methods are available on a TradeAPI instance:
getInfo - Retrieves basic account information via the server getInfo method, and returns a TradeAccountInfo object with the following members: balance_[currency] - Current available balance in the given currency. open_orders - Number of open orders. server_time - Server time in a datetime object. transaction_count - Number of transactions. (?) info_rights - True if the API key has info rights. withdraw_rights - True if the API key has withdrawal rights. trade_rights - True if the API key has trading rights. transHistory - Retrieves transaction history via the server TransHistory method, and returns a list of TransactionHistoryItem objects, which have the following members: type, amount, currency, desc, status, and timestamp (a datetime object). tradeHistory - Retrieves trading history via the server TradeHistory method, and returns a list of TradeHistoryItem objects, which have the following members: pair (such as "btc_usd"), type ("buy" or "sell"), amount, rate, order_id, is_your_order, timestamp (a datetime object). activeOrders - Retrieves a list of orders via the server ActiveOrders method, and returns a list of OrderItem objects, which have the following members: pair (such as "btc_usd"), type ("buy" or "sell"), amount, rate, timestamp_created (a datetime object) and status. trade - Place a trade order via the server Trade method, and return a TradeResult object, which has the following members: received - Immediate proceeds from the order. remains - Portion of the order that remains unfilled. order_id balance_[currency] - Current available balance in the given currency. cancelOrder - Cancel the specified order via the server CancelOrder method, and return a CancelOrderResult object, which has the following members: order_id balance_[currency] - Current available balance in the given currency.
Welcome to Bitcoinlib’s documentation!
Includes a fully functional wallet, with multi signature, multi currency and multiple accounts. Use this library to create and manage transactions, addresses/keys, wallets, mnemonic password phrases and blocks with simple and straightforward Python code.
You can use this library at a high level and create and manage wallets on the command line or at a low level and create your own custom made transactions, scripts, keys or wallets.
The BitcoinLib connects to various service providers automatically to update wallets, transactions and blockchain information.
Wallet
This Bitcoin Library contains a wallet implementation using SQLAlchemy and SQLite3, MySQL or PostgreSQL to import, create and manage keys in a Hierarchical Deterministic way.
Example: Create wallet and generate new address (key) to receive bitcoins
>>> from bitcoinlib.wallets import Wallet >>> w = Wallet.create('Wallet1') >>> key1 = w.get_key() >>> key1.address '1Fo7STj6LdRhUuD1AiEsHpH65pXzraGJ9j'
Now send a small transaction to your wallet and use the scan() method to update transactions and UTXO’s
>>> w.scan() >>> w.info() # Shows wallet information, keys, transactions and UTXO's
When your wallet received a payment and has unspent transaction outputs, you can send bitcoins easily. If successful a transaction ID is returned
>>> t = w.send_to('1PWXhWvUH3bcDWn6Fdq3xhMRPfxRXTjAi1', '0.001 BTC') 'b7feea5e7c79d4f6f343b5ca28fa2a1fcacfe9a2b7f44f3d2fd8d6c2d82c4078' >>> t.info() # Shows transaction information and send results
Segregated Witness Wallet
Easily create and manage Segwit wallets. Both native Segwit with base32/bech32 addresses and P2SH nested Segwit wallets with traditional addresses are available.
Create a native single key P2WPKH wallet:
>>> from bitcoinlib.wallets import Wallet >>> w = Wallet.create('segwit_p2wpkh', witness_type='segwit') >>> w.get_key().address bc1q84y2quplejutvu0h4gw9hy59fppu3thg0u2xz3
Or create a P2SH nested single key P2SH_P2WPKH wallet:
>>> from bitcoinlib.wallets import Wallet >>> w = Wallet.create('segwit_p2sh_p2wpkh', witness_type='p2sh-segwit') >>> w.get_key().address 36ESSWgR4WxXJSc4ysDSJvecyY6FJkhUbp
Wallet from passphrase with accounts and multiple currencies
The following code creates a wallet with two bitcoin and one litecoin account from a Mnemonic passphrase. The complete wallet can be recovered from the passphrase which is the masterkey.
from bitcoinlib.wallets import Wallet, wallet_delete from bitcoinlib.mnemonic import Mnemonic passphrase = Mnemonic().generate() print(passphrase) w = Wallet.create("Wallet2", keys=passphrase, network='bitcoin') account_btc2 = w.new_account('Account BTC 2') account_ltc1 = w.new_account('Account LTC', network='litecoin') w.get_key() w.get_key(account_btc2.account_id) w.get_key(account_ltc1.account_id) w.info()
Multi Signature Wallets
Create a Multisig wallet with 2 cosigners which both need to sign a transaction.
from bitcoinlib.wallets import Wallet from bitcoinlib.keys import HDKey NETWORK = 'testnet' k1 = HDKey('tprv8ZgxMBicQKsPd1Q44tfDiZC98iYouKRC2CzjT3HGt1yYw2zuX2awTotzGAZQEAU9bi2M5MCj8iedP9MREPjUgpDEBwBgGi2C8eK' '5zNYeiX8', network=NETWORK) k2 = HDKey('tprv8ZgxMBicQKsPeUbMS6kswJc11zgVEXUnUZuGo3bF6bBrAg1ieFfUdPc9UHqbD5HcXizThrcKike1c4z6xHrz6MWGwy8L6YKVbgJ' 'MeQHdWDp', network=NETWORK) w1 = Wallet.create('multisig_2of2_cosigner1', sigs_required=2, keys=[k1, k2.public_master(multisig=True)], network=NETWORK) w2 = Wallet.create('multisig_2of2_cosigner2', sigs_required=2, keys=[k1.public_master(multisig=True), k2], network=NETWORK) print("Deposit testnet bitcoin to this address to create transaction: ", w1.get_key().address)
Create a transaction in the first wallet
w1.utxos_update() t = w1.sweep('mwCwTceJvYV27KXBc3NJZys6CjsgsoeHmf', min_confirms=0) t.info()
And then import the transaction in the second wallet, sign it and push it to the network
w2.get_key() t2 = w2.transaction_import(t) t2.sign() t2.send() t2.info()
Command Line Tool
With the command line tool you can create and manage wallet without any Python programming.
To create a new Bitcoin wallet
$ clw newwallet Command Line Wallet for BitcoinLib Wallet newwallet does not exist, create new wallet [yN]? y CREATE wallet 'newwallet' (bitcoin network) Your mnemonic private key sentence is: force humble chair kiss season ready elbow cool awake divorce famous tunnel Please write down on paper and backup. With this key you can restore your wallet and all keys
You can use the command line wallet ‘clw’ to create simple or multisig wallets for various networks, manage public and private keys and managing transactions.
For the full command line wallet documentation please read
Service providers
Communicates with pools of bitcoin service providers to retreive transaction, address, blockchain information. To push a transaction to the network. To determine optimal service fee for a transaction. Or to update your wallet’s balance.
Example: Get estimated transactionfee in Sathosis per Kb for confirmation within 5 blocks
>>> from bitcoinlib.services.services import Service >>> Service().estimatefee(5) 138964
Other Databases
Bitcoinlib uses the SQLite database by default but other databases are supported as well. See http://bitcoinlib.readthedocs.io/en/latest/_static/manuals.databases.html for instructions on how to use MySQL or PostgreSQL.
More examples
- Installation and Settings
- Installation
- Install with pip
- Install from source
- Package dependencies
- Other requirements Linux
- Development environment
- Other requirements Windows
- Create wallet
- Generate / show receive addresses
- Send funds / create transaction
- Restore wallet with passphrase
- Options Overview
- Steps to add a new provider
- Bitcoin node settings
- Connect using config files
- Connect using provider settings
- Connect using base_url argument
- Please note: Using a remote bitcoind server
- Using MySQL database
- Using PostgreSQL database
- Encrypt database
- Create an Encrypted Database for your Wallet
- Encrypt using Database URI
- What is cached?
- Using other databases
- Disable caching
- Troubleshooting
- Nothing is cached, what is the problem?
- I get incomplete or incorrect results!
Disclaimer
This library is still in development, please use at your own risk and test sufficiently before using it in a production environment.
Schematic overview
Indices and tables
© Copyright 2023, Coineva (mccwdev). Revision 38f86902 .
- Installation