Hands-On Bitcoin Programming with Python
eBook - ePub

Hands-On Bitcoin Programming with Python

Build powerful online payment centric applications with Python

Harish Kumar Garg

Share book
  1. 90 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Hands-On Bitcoin Programming with Python

Build powerful online payment centric applications with Python

Harish Kumar Garg

Book details
Book preview
Table of contents
Citations

About This Book

Simplified Python programming for Bitcoin and blockchain

Key Features

  • Build Bitcoin applications in Python with the help of simple examples
  • Mine Bitcoins, program Bitcoin-enabled APIs and transaction graphs, and build trading bots
  • Analyze Bitcoin transactions and produce visualizations using Python data analysis tools

Book Description

Bitcoin is a cryptocurrency that's changing the face of online payments. Hands-On Bitcoin Programming with Python teaches you to build software applications for mining and creating Bitcoins using Python.

This book starts with the basics of both Bitcoin and blockchain and gives you an overview of these inherent concepts by showing you how to build Bitcoin-driven applications with Python. Packed with clear instructions and practical examples, you will learn to understand simple Python coding examples that work with this cryptocurrency.

By the end of the book, you'll be able to mine Bitcoins, accept Bitcoin payments on the app, and work with the basics of blockchain technology to create simply distributed ledgers.

What you will learn

  • Master the Bitcoin APIs in Python to manipulate Bitcoin from your Python apps
  • Build your own Bitcoin trading bots to buy Bitcoins at a lower price and sell them at a higher price
  • Write scripts to process Bitcoin payments through a website or app
  • Develop software for Bitcoin mining to create Bitcoin currency on your own computer hardware
  • Create your own keys, addresses, and wallets in Python code
  • Write software to analyze Bitcoin transactions and produce reports, graphs, and other visualizations

Who this book is for

Hands-On Bitcoin Programming with Python consists of examples that will teach you to build your own Bitcoin application. You will learn to write scripts, build software for mining, and create Bitcoins using Python. Anyone with prior Python experience, who wants to explore Python Bitcoin programming and start building Bitcoin-driven Python apps, will find this book useful.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on ā€œCancel Subscriptionā€ - itā€™s as simple as that. After you cancel, your membership will stay active for the remainder of the time youā€™ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlegoā€™s features. The only differences are the price and subscription period: With the annual plan youā€™ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weā€™ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Hands-On Bitcoin Programming with Python an online PDF/ePUB?
Yes, you can access Hands-On Bitcoin Programming with Python by Harish Kumar Garg in PDF and/or ePUB format, as well as other popular books in Informatica & Programmazione in Python. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781789533163

Bitcoin Data Analysis

In this chapter, we will explore the manipulation and visualization of bitcoin price data using Python. We will also explore bitcoin transaction graphs, along with collecting and analyzing Bitcoin Dice game data using Python.

Manipulating and visualizing bitcoin price data

In this section, we will introduce the following topics:
  • Getting set up for data analysis
  • Getting, reading in, and cleaning bitcoin price data
  • Exploring, manipulating, and visualizing the cleaned-up data
We first need to install several Python libraries, which includes installing the pandas module for reading in data, and also doing some exploratory analysis. We'll also be installing matplotlib for creating plots and charts, as well as Jupyter Notebooks, as they are the best for this kind of work involving data analysis.

Getting set up for data analysis

To install the Python modules, open the command-line program. In the command line, to install pandas, execute the following command:
pip install pandas
Similarly, to install matplotlib, execute the following command:
pip install matplotlib
To install Jupyter, execute the following command:
pip install jupyter
Having finished installing the required modules, launch the Jupyter Notebook by executing the jupyter notebook command. This will open up a new browser window, or a tab, where it will display the list of files that are already there from the folder where we executed the jupyter notebook command. The following screenshot shows the jupyter notebook command:
Next, choose to create a new Python 3 notebook, as shown in the following screenshot:

Getting, reading in, and cleaning bitcoin price data

We will start by importing the necessary modules.
Import pandas to enable you to read in the data and start exploring it. The following screenshot shows the import pandas command:
Also, import matplotlib for drawing plots from the data.
We need to set some options for pandas and matplotlib. The following screenshot shows the command for importing matplotlib:
The first option we will set is called options.mode.chained_assignment = None.
The preceding option is to make sure that the operations are for the cleanup, which will be performed on the pandas DataFrame objects; we want the cleanup to happen on the original DataFrame objects and not on copies.
The following screenshot shows the options.mode.chained_assignment = None option:
Also, set matplotlib to visualize and display all the charts shown in the following screenshot:
The price data we have is from coindesk.com, as shown in the following screenshot, and it is freely available for download:
Download the data in CSV format and read this data using pandas. This is a CSV file, so we will use the read_CSV method from pandas, as shown in the following screenshot:

DataFrame

The data in a pandas data object is called a DataFrame. A DataFrame is in a tabular data format. Now, print out some records to see how this looks. To print this out, we can call a method called head() on the price DataFrame.
When we do this, we get two columnsā€”Date and Close Priceā€”for the bitcoin in USD for that day. We also have a default index for the rows starting from 0, which was inserted by pandas by default while reading in the data. The following screenshot shows the two columns, Date and Close Price...

Table of contents