Using Python for Coinbase

去中心化金融社区 view 97 2021-12-17 11:27
share to
Scan QR code with WeChat

The field of cryptocurrency is a great way to experiment with different technologies. This sentence covers:

How to load data from Coinbase Pro into the Pandas dataframe?

How to update and analyze historical data of the cryptocurrency market?

How to add Easy Moving Average (SMA), Exponential Moving Average (EMA), MACD, MACD symbols?

How to see cryptocurrency market data using Plotly and Python?

This sentence contains only the most important Python code.

Python在Coinbase上的应用

By the end of this article, we will be able to develop a cryptocurrency candlestick chart that shows many performance and business models such as:

Python在Coinbase上的应用

The Bottom Line - OHLC Candlestick Chart with Industry Trends

Step 1: Log into Coinbase Pro

Logging into Coinbase Pro using the cbpro library is one line:

imprimer (server_time_now)

Launch public users for Coinbase Pro

We define constants to limit the number of results we want to identify. You also want to select a currency, such as the US dollar or the euro, and use that to represent the value of any currency.

Granularity = [days, 60 minutes, 15 minutes, 1 minute]

constant definition

Step 2: load statistics for the last 24 hours

Next, let's take a look at the key stats for each cryptocurrency over the past 24 hours. We will also add a “work” policy that describes performance from the start to the end of the reporting period. The rest of the number is responsible for formatting the number.

df_24hstats_formatted.style.hide_columns ([volume, volume_30 jours])

Load and Format 24 Hour Trade Data for All Cryptocurrencies in Coinbase Pro

Here is the output file of the Pandas dataframe:

Python在Coinbase上的应用

24 hour cryptocurrency information and processing

Step 3: Load historical data on different granularities

Next, we extract the data from the historical market using different time periods of granularity. So we need to repeat from every call like in step 2. Here is an example of how to recover data daily.

df_history[date] = pd.to_datetime(df_history[time], unit=s)

To save the data at the time of cutting, you need the following information:

ISO mode starts on the desired date

ISO format delay required

granularity in seconds (in this example 86400 seconds, equivalent to 24 hours)

To receive recordings from the last 300 hours, you can do the following:

data = public_client.get_product_historic_rates(txiaj - MY_BASE_CURRENCY, start=startdate, end=enddate, granularity=3600)

Now the Pandas data frame looks like this (a few more lines like year, month, and day for better readability):

Python在Coinbase上的应用

Historical market information for cryptocurrencies with daily time

Step 4: Add metrics

Now the hard part. I would like to add investment metrics to my data. This will easily improve the information we receive from business information. Add the following information:

SMA3 and SMA7 (Easy Moving Between the Previous 3 and 7 Time Slices): Price-based (or reaction) time indicators that indicate the average value of a security in the market. Moving the center eliminates "noise" when defining graphics. The volume has a change in value and volume. An easy-to-move mount is not a heavy mount. This means that all the time in the recording is of equal importance and has the same weight.

EMA12 and EMA26 (exponential movement between last 12 and 26 periods): EMAs are rarely traded as SMAs because they focus more on recent prices. Therefore, the rotation is faster than SMA. You can choose a different cutting time, but 12 and 26 usually take longer and we will use them in our example.

Moving Convergence / Diffusion (MACD): A good indicator of the overall security model. I want the difference between a short term EMA and a long term EMA. A good MACD price is an indicator of good trading. Negative MACD price is a sign of bad trading.

MACD Signal: The MACD signal line is the EMA for the special MACD line of the time group. Usually this value is set for 9 times cut.

MACD Line: The difference between MACD line and MACD signal line. A bullish cross occurs when the MACD line crosses above the MACD signal line. A bearish cross occurs when the MACD line crosses the bottom of the MACD signal line. Then when you see the data, you will see what it means.

Open-to-close operation: For all hours, the difference between the closing rate and the open hour for a given period is expressed as a percentage.

High-Low Range: The percentage difference between the highest value and the lowest value at a given time. This shows the difference in the cutting time.

Satisfaction of the last 3 sessions: This metric takes the performance of the last 3 sessions (also measured in the results selected by frequency).

Percentage of performance of the last 3 periods: This metric gives the performance of the last 3 cut periods as a relative value (percentage).

Bull or Bear: Write "bull" if the MACD histogram is good and "bear" if the MACD histogram is bad.

Continuing Trade: This phrase is "Slight" if the difference over the previous period is further reduced, and "False" if the pattern is reversed to identify the uptrend for a reversal and a reversal.

Thanks to how Panda's Power Vector works and works, we accomplished this in a few lines of code.

df_history_enhanced[market_trend_continued] = df_history_enhanced.bull_bear.eq(df_history_enhanced.bull_bear.shift()) & df_history_enhanced.currency.eq(df_history_enhanced.shift()d.

Step 5: Use data to make decisions

Now that we have a good foundation for further analysis, we can use this information to create custom Pandas documents. It stores important information about cryptocurrency options.

Python在Coinbase上的应用

Performance of various cryptocurrencies over the past 90 days

Step 6: Find Encrypted Business Data

In the last step we want to see the data below that we have created so far. It uses the Plotly Powerful library for visualization.

Before we see the data, we need to create another Pandas database which has the data we need to arrange the bearish (red) and bullish (green) boxes in the figure below. So you need to create a table that gives the time of the bull and the bear, including the start and end times. Thanks to Pandas, you can accomplish this easily with the following phrases:

df_history_market_trend_intervals = pd.concat(market_trend_interval_rows, ignore_index=True)

Pandas are working hard to change the cutting time

This code gives me the Pandas dataframe as below.

Python在Coinbase上的应用

Pandas data framework with compressed bullish and bearish times

Plotly code can be changed in Jupyter Notebooks. The output of Plotly is:

Python在Coinbase上的应用

Complex cryptocurrency candlestick charts include performance indicators and industry patterns

This image uses two y axes in Plotly. The y axis on the right is used to draw the diagram. The y axis on the left is used to draw the MACD and MACD signal lines.

Whenever the MACD line crosses the MACD signal line, it enters the trading circle, indicated by the green box. When the MACD line falls below the MACD signal line, we enter a trading cycle. This last information is indicated by the red box.

Contents

Now you have learned how to use an open source API like Coinbase Pro to remove trade data and modify it as needed.

btcfans公众号

Scan QR code with WeChat

Link
Disclaimer:

Previous: About the Ethereum Arrow Glacier Upgrade and Hard Bomb Next: Hainan Digital Yuan Tax Deal Honestly Started, 6 Banks Joined

Related