Trading with Coinbase Pro (GDAX) API in Python

Coinbase Pro (formerly known as GDAX) is one of the biggest cryptocurrency exchange, you can trade a large panel of cryptocurrencies against USD, EUR and GBP. I chose to trade on Coinbase Pro because it supports a lot of pairs and the liquidity is usually very good, we can easily implement an algorithmic trading strategy on this exchange.

The most traded currencies are:
– Bitcoin (BTC)
– Ethereum (ETH)
– yearn.finance (YFI)
– Litecoin (LTC)

The Setup

Fortunately for us, Coinbase Pro provides an API to get market data, to get balances for each currency and to send buy/sell orders to the market. You can find a documentation here.

I found a Python wrapper for their API on GitHub, this one is super easy to use.
You can install the package like this:

pip install cbpro

Once it’s installed, you need to insert the appropriate import in your code:

import cbpro

Now you need to get an API key in order to be able to retrieve your account balances and to send orders to the market. If you just want to get market data you can skip that part.
Go to https://pro.coinbase.com/profile/api , click on Create new key, now you have the API key and you may need to get some email validation to see the secret key (which you also need). Check the options you want, if you want to trade via the API, just select the appropriate check box, same for withdrawals.

Using the API

In your code, you need to set up the connection so that you can get authenticated:

auth_client = cbpro.AuthenticatedClient(key, b64secret, passphrase)

If you want to get market data for a ticker. Note that authentication is not required for this method:

auth_client.get_product_order_book('BTC-USD')

Now to send an order, it’s pretty simple:

# Buy 0.01 BTC @ 100 USD
auth_client.buy(price='100.00',#USD
size='0.01',#BTC
order_type='limit',
product_id='BTC-USD')

You’ll get a JSON object, with an id for the order that you can track using auth_client.get_fills(order_id=”d0c4560b-4e6d-41d9-e568-48c4bfca13e6″):

{
"id": "d0c4560b-4e6d-41d9-e568-48c4bfca13e6",
"price": "0.10000000",
"size": "0.01000000",
"product_id": "BTC-USD",
"side": "buy",
"stp": "dc",
"type": "limit",
"time_in_force": "GTC",
"post_only": false,
"created_at": "2020-11-20.T10:12:45.12345Z",
"fill_fees": "0.0000000000000000",
"filled_size": "0.00000000",
"executed_value": "0.0000000000000000",
"status": "pending",
"settled": false
}

To manage your risks, you’ll need to retrieve your balances:

balance = auth_client.get_accounts()
print("ETH="+str(balance[0]["balance"]))

With this basic API you can code any algorithmic strategy in Python for Coinbase Pro, you can try to predict the value of a cryptocurrency using our previous tutorials for example.

Will Bitcoin Ever Be Regulated?

This article by Vlad Andrei was originally published at Albaron Ventures

As Bitcoin and other digital assets continue to grow in adoption and popularity, a common topic for discussion is whether the U.S. government, or any government for that matter, can exert control of its use.

There are two core issues that lay the foundation of the Bitcoin regulation debate:

The digital assets pose a macro-economic risk. Bitcoin and other cryptocurrencies can act as surrogates for an international currency, which throws global economics a curveball. For example, countries such as Russia, China, Venezuela, and Iran have all explored using digital currency to circumvent United States sanctions, which puts the US government at risk of losing its global authority.
Bitcoin logo

International politics and economics are a very delicate issue, and often sanctions are used in place of military boots on the ground, arguably making the world a safer place.

The micro risks enabled by cryptocurrency weigh heavily in aggregate. One of the most attractive features of Bitcoin and other digital assets is that one can send anywhere between a few pennies-worth to billions of dollars of Bitcoin anywhere in the world at any time for a negligible fee (currently around $0.04 to $0.20 depending on the urgency.)

However, in the hands of malicious parties, this could be very dangerous. The illicit activities inherently supported by a global decentralized currency run the gamut: terrorist funding, selling and buying illegal drugs, ordering assassinations, dodging taxes, laundering money, and so on.

Can Bitcoin Even Be Regulated?

Before diving deeper, it’s worth asking whether Bitcoin can be regulated in the first place.

The cryptocurrency was built with the primary purpose of being decentralized and distributed– two very important qualities that could make or break Bitcoin’s regulation.

By being decentralized, Bitcoin doesn’t have a single controlling entity. The control of Bitcoin is shared among several independent entities all over the world, making it nearly impossible for a single entity to wrangle full control over the network and manipulate it as they please.

By being distributed, Bitcoin exists at many different locations at the same time. This makes it very difficult for a single regulatory power to enforce its will across borders. This means that a government or other third party can’t technically raid an office and shut anything down.

That being said, there are several chokepoints that could severely hinder Bitcoin’s adoption and use.

1. Targeting centralized entities: exchanges and wallets

A logical first move is to regulate the fiat onramps (exchanges) , which the United States government has finally been getting around to. In cryptocurrency’s nascent years, cryptocurrency exchanges didn’t require much input or approval from regulatory authorities to run. However, the government started stepping in when cryptocurrency starting hitting the mainstream.

The SEC, FinCEN (Financial Crimes Enforcement Network), and CFTChave all played a role in pushing Know Your Customer (KYC) protocols and Anti-Money Laundering (AML) policies across all exchanges operating within U.S borders.

Cryptocurrency exchanges have no options but to adhere to whatever the U.S. government wants. The vast majority of cryptocurrency users rely on some cryptocurrency exchange to utilize their cryptocurrency, so they will automatically bend to exchange-imposed regulation.

Regulators might not be able to shut down the underlying technology that powers Bitcoin, but they can completely wreck the user experience for the great majority of cryptocurrency users, which serves as enough of an impediment to diminish the use of cryptocurrency for most.

2. Targeting users

The government can also target individual cryptocurrency users. Contrary to popular opinion, Bitcoin (and even some privacy coins) aren’t anonymous. An argument can be made that Bitcoin is even easier to track than fiat because of its public, transparent ledger.

Combined with every cryptocurrency exchange’s willingness to work with U.S. authorities, a federal task force could easily track money sent and received from certain addresses and pinpoint the actual individual with it. Companies such as Elliptic and Chainalysis have already created solid partnerships with law enforcement in many countries to track down illicit cryptocurrency uses and reveals the identities behind the transactions.

Beyond that, we dive into the dark web and more professional illicit cryptocurrency usage. Although trickier, the government likely has enough cyber firepower to snipe out the majority of cryptocurrency-related cybercrime. In fact, coin mixers (cryptoMixer.io), coin swap services (ShapeShift) and P2P bitcoin transactions (localbitcoins.com) have been investigated for several years now and most of them have had to add KYC and adhere to strict AML laws.

Final Thoughts

Ultimately, it’s going to take a lot to enforce any sort of significant global regulation on Bitcoin, with the most important factor being a centralization and consensus of opinion. The majority of the U.S. regulatory alphabet agencies fall into the same camp of “protect the good guys, stop the bad guys”, but there isn’t really a single individual piece of guidance to follow. Currently, cryptocurrencies are regulated in the US by several institutions: CFTC, SEC, IRS, making it difficult to create overarching regulatory guidelines.

In short, yes– Bitcoin can be regulated. In fact, its regulation has already started with the fiat onramps and adherence to strict KYC & AML laws. While in countries such as Ecuador, Bolivia, Egypt and Morocco Bitcoin ownership is illegal, in the US, it would take some bending of the moral fabric of the Constitution in order for cryptocurrency ownership rights to be infringed.

However, it cannot be shut down. There are still ways to buy, sell, and trade Bitcoin P2P, without a centralized exchange. It would take an enormous effort by any government to completely uproot something as decentralized as Bitcoin, but that future seems more dystopian than tangible.

Three Strategies for Choosing What Cryptocurrency to Invest in Next

This article by Steven Buchko was originally published at CoinCentral.com

Finding the Next Bitcoin

You’ve probably thought it at one point or another: “I missed the Bitcoin payday. How do I decide what cryptocurrency to invest in now that I know about the market?”

The bad news: It’s unlikely that any other cryptocurrency will see the same astronomical growth that Bitcoin experienced over the last few years, and impossible to predict it.

The good news: There’s still plenty of opportunities to invest in up-and-coming cryptocurrencies that could potentially bring you 10-100x returns. This comes with a heavy note of caution, because as you may know, cryptocurrencies are incredibly volatile. This is not investment advice, and you should gain/lose money on your own research and intuition.

In this article, we’ll go over some basic strategies you can follow when searching for what cryptocurrency to invest in next. We’re focusing on high risk, high reward options here. If you’re looking for general investment tips, you should check out our article on how to build a proper cryptocurrency portfolio instead.

Scour Initial Coin Offerings (ICOs)

Initial Coin Offerings (ICOs) have quickly become the standard for blockchain startups to raise funding for their project. In an ICO, the team hosts a crowdsale in which you purchase tokens that you can use on their platform. You can also trade these tokens in the secondary market (exchanges) after the ICO.

For example, Golem held an ICO to distribute the first GNT tokens. The purpose of these tokens is to purchase computing power in the Golem network, but traders also buy and sell them on exchanges.

Participating in ICOs can be a lucrative trading strategy. If you invested in the NEO crowdsale (at the time the project was called AntShares), your return on investment (ROI) would be ~160,000% currently. Populous, about 5,000%. OmiseGo, around 4,000%. You get the picture.
ICO ROIs

Source: ICOBench

ICO gains do come with the highest amount of risk, though. The majority of ICOs will fail, and already almost half have done so already.

ICO Research

It’s important that you do your due diligence when picking what cryptocurrency to invest in pre-ICO. There are a ton of things to look at when evaluating a cryptocurrency, but the most important attributes are:

Team and advisors – The team should have experience in blockchain technology or at least the industry that they’re targeting. Preferably both. Having reputable advisors is also a strong sign that the ICO could succeed.
Clear problem/solution – The project’s white paper should clearly define what problem the project is aiming to solve and how the cryptocurrency solves it. Make sure it’s not just a document full of marketing BS.
Token distribution – The team should be distributing over fifty percent of the tokens to crowdsale participants if not much, much more. Be hesitant about projects in which the team and advisors keep a significant proportion of tokens.

Other things to take note of are: any notable partnerships, whether the team has already created a product, and the size of the industry they’re targeting. All of these things could lead to a favorable investment.

Check Lesser Known Exchanges

Even if you missed your chance to participate in an interesting ICO, you can still invest once the coin hits exchanges. At this time, there’s often a brief spike followed by an immediate dump as ICO investors look to cash-in on short-term gains. This is a prime opportunity to get coins you’re interested in for ICO-level (or even lower) prices.

Beyond the short post-ICO period, you still have time to invest in a coin before major exchanges begin to list it. Cryptopia and decentralized exchanges such as IDEX are goldmines for these types of coins. The same research strategies mentioned above apply to coins in this category as well.

IDEX Exchange

Search through coins with a small market cap (<$100 million) that haven’t been listed on a large exchange like Binance yet. You can check CoinMarketCap to see which exchanges coins are on. Make sure you research appropriately and find coins that you believe to have solid fundamentals.

Once you’ve found a coin you’re confident in, purchase it, and (this is the hardest part) wait. It could take days, weeks, or even months for your coin to reach a respectable amount of awareness. If you truly believe in the fundamentals of the coin, though, this timeframe shouldn’t matter. Once the coin joins a major exchange, feel free to trade it accordingly.

Time Important Events

Another popular strategy in selecting what cryptocurrency to invest in is to choose coins based on project roadmaps and event calendars. This is a short-term strategy and usually much harder to execute than the other ones that we’ve covered.

The price of cryptocurrency tends to rise after an important partnership announcement or development milestone. If you follow certain projects on Twitter or are active in their Telegram channel, you usually find out about these announcements ahead of the less involved general public.

With that information, you can sometimes buy into a project early and ride the wave up following the announcement. This has some potential downsides, though. Correct timing is incredibly difficult to accomplish. And, in a bear market, even the most impressive announcements can get crushed under the negative sentiment.

Additionally, the rest of the market may not react to the news the way that you expect. A recent example of this is Verge’s PornHub partnership announcement. While some supporters saw this as positive news, the majority of the market didn’t, and the price crashed accordingly.

Stay Vigilant

Most importantly, you just need to stay vigilant when looking for what cryptocurrency to invest in. New investment opportunities occur every day when you’re actively looking for them. Join subreddits, follow crypto traders on Twitter, constantly research new projects – in essence, engulf yourself in the blockchain space. You never know what gems you’ll stumble upon.

Trading with Poloniex API in Python

Poloniex is a cryptocurrency exchange, you can trade ~80 cryptocurrencies against Bitcoin and a few others against Ethereum. I chose to trade on Poloniex because it supports a lot of currencies and the liquidity is usually very good, we can easily implement an algorithmic trading strategy on this exchange.

The most traded currencies are:
– Bitcoin (BTC)
– Ethereum (ETH)
– Monero (XMR)
– Tether (USDT)

The Setup

Fortunately for us, Poloniex provides an API to get market data, to get balances for each currency and to send buy/sell orders to the market. You can find a documentation here.

I found a Python wrapper for their API on GitHub, this one is super easy to use.
You can install the package like this:

pip install https://github.com/s4w3d0ff/python-poloniex/archive/v0.3.5.zip

Once it’s installed, you need to insert the appropriate import in your code:

from poloniex import Poloniex

Now you need to get an API key in order to be able to retrieve your account balances and to send orders to the market. If you just want to get market data you can skip that part.
Go to https://poloniex.com/apiKeys , click on Create new key, now you have the API key and you may need to get some email validation to see the secret key (which you also need). Check the options you want, if you want to trade via the API, just select the appropriate check box, same for withdrawals.

Using the API

In your code, you need to set up the connection so that you can get authenticated. You can just use the commented line if you only want to access the public API:

apiKey = "API_KEY"
secret = "SECRET_KEY"
polo = Poloniex(apiKey, secret)
# polo = Poloniex()

If you want to get market data for a ticker:

market_data = polo.returnTicker()['BTC_ETH']
bid = market_data["highestBid"]
ask = market_data["lowestAsk"]
volume = market_data["baseVolume"]

Now to send an order, it’s pretty simple:

pair = "BTC_ETH"
price = 0.1
order = polo.buy("BTC_ETH", price, 1)
order = polo.sell("BTC_ETH", price, 1)

You’ll get an order object in JSON, resultingtrades is an array of trades generated by the order, the order can be filled straight away with multiple trades:

{‘orderNumber’: ‘0000000’, ‘resultingTrades’: []}

To manage your risks, you’ll need to retrieve your balances:

balance = polo.returnBalances()
print("ETH="+str(balance ["ETH"]))

With this basic API you can code any algorithmic strategy in Python for Poloniex, you can try to predict the value of a cryptocurrency using our previous tutorials for example.

Common Mistakes to Avoid When Cryptocurrency Trading

This article by Steven Buchko was originally published at CoinCentral.com

Whether you’re a crypto expert or just getting your feet wet with investing, there’s plenty to be aware of when trading your way through the cryptocurrency industry. Unlike in traditional markets, cryptocurrency trading is chock full of volatility, nefarious players, and irrational price movements.

In this article, we’ll teach you about some of the common mistakes in cryptocurrency trading and how you can avoid them.

Mistake #1: Chasing Pumps aka FOMO

Probably the most common (and easiest) mistake to make in cryptocurrency trading is buying into a coin after it’s already risen a significant amount. Investors that bought into Ripple (XRP) and Tron (TRX) at the peak of their runs in 2017 definitely felt the pain just a few weeks later in 2018. It may be your instinct to throw some money in the ring when you see a coin shoot up 30-40% because it’s “hot.” Don’t.

ripple fomo chart

Extreme increases in price are almost always accompanied by some type of pullback. By the time you hear about a “hot” coin, it’s usually too late. Unless you’ve done your research, believe in the fundamentals of the coin, and want to hold it for the long-term (>1 year), wait until the pullback to invest.

Pump and Dumps

Pump and dumps (PnDs) are a special breed of pumps that are guaranteed to leave you burned. If you see an unknown coin skyrocket all of a sudden, be wary. It’s most likely part of a PnD scheme. They’re basically coordinated efforts to artificially drive up the price of a coin (the pump) before selling it to those who FOMO’d in (the dump).

When you come across a coin like this, the first thing to check is the trading volume. CoinMarketCap is a great resource for this. Any 24-hour trading volume under $1 million should raise a red flag.

Mistake #2: Not Knowing Your Investments

Don’t just blindly follow the advice of some Twitter or YouTube “guru” for investment picks. Many times, these high-profile individuals are paid to promote certain coins. Even John McAfee, one of the most well-known figures in the space admitted that he gets paid to promote projects. Question the coins that you’re told to invest in.

At the bare minimum, you should devote a half hour to researching any project in which you plan to invest in. Check out what problem it’s attempting to solve, the team building it, and the economics of the coin. Has the project partnered with anyone significant? Any notable names as advisors? These are all things you should know.

Even a quick Google search could unveil some information that turns what may seem like gold into trash. Taking it a step further, you should ideally read the white paper of each project you invest in.

bitconnect scam google search

Joining or forming an investment group can do wonders to help with this. It forces you to do research so you can explain your investment reasoning to your peers. It also puts you an environment in which you have to challenge your assumptions as others question your reasoning.

Mistake #3: Selling At Inappropriate Times

The opposite of chasing pumps, emotion-driven selling is still cut from the same cloth. It’s difficult, but you need to stay level-headed when trading – keep emotions out of it. Time and time again, coins have dipped down double-digit percentages before rocketing to 200-300% gains.

When a coin you own starts to drop in value, before you sell, re-evaluate your position. If you invested because you believe in the coin’s fundamentals, there are a few questions you can ask yourself:

Have any of the fundamentals changed?
Were there any announcements that would have affected the price?
Have you stopped believing in the long-term vision of the coin?

If your answer to all of these questions is “No”, then consider holding on. This strategy becomes much easier when you follow the golden rule of cryptocurrency trading: Don’t invest more money than you’re comfortable losing.

On the other side of this equation, seeing some solid gains may also tempt you to sell. Although taking profits is wise, you may want to avoid selling your entire stack. Depending on the situation, the coin could rise further. A popular trading strategy is to take out your initial investment while keeping your earnings invested in the coin after gaining a certain percentage. This decreases your downside risk while still exposing you to the upside potential.

Mistake #4: Being Uninformed

In a market that moves as rapidly as cryptocurrency does, you need to stay up-to-date with industry news. Without tuning in weekly, or even daily, the investment tides could shift without you even knowing.

Twitter, Reddit, and projects’ Telegram channels are also great resources you can use to stay informed. Oftentimes, teams share project updates and important announcements on these platforms before they hit mainstream media. Joining these communities also gives you the opportunity to be more involved with the projects while sometimes even impacting future development.

Good Luck Out There

Even with these tips, there’s bound to be mistakes that you make. Don’t let that discourage you – it happens to everyone. Part of the investing process is to learn from those mistakes and not make them again.

Continuous improvement is the name of the game. And, as long as you’ve got that going for you, you’ll be a trading whiz in no time.