Scheduled buying of BTC, ETH, and LTC from Coinbase Pro (formerly GDAX) optimally!
This is a Python script you can use to automatically buy Bitcoin, Ethereum,Litecoin, and more using the Coinbase Pro API. By default, it buys these 3 currencies,weighted by market cap (as reported bycoinmarketcap.com), using a form of dollar costaveraging according tothe following logic (assuming default values):
In effect, this script mimmicks the behaviour of a market cap weighted indexfund, but without the fees. It also only supports the coins that trade on Coinbase Pro(because that's the only exchange that has an API for ACH deposits AFAIK).
You can also use the same script to schedule deposits from your bank accountperiodically, such as when you're paid. The parameters may be configured to suityour preferences, such as which coins to buy, external balances, discountvalues, number of steps, etc.
Orders, deposits, and withdrawals are tracked in a SQLite DB, and the withdrawnbalances are added to the balances on Coinbase Pro to make sure the weights aremaintained over time. The SQLite DB can be swapped out for any DB thatSQLAlchemy supports.
A note on the default parameters: it's likely you'll want to change--starting-discount
, --discount-step
, or --order-count
. The more spreadout the orders are (i.e., difference between the current price and the lowestpriced order), the longer they will take to fill (if they fill), and the closerthe orders are, the more likely you are to miss out on bigger price drops. Youshould consider your appetite for risk and how much you want to optimize forcatching those dips vs. not missing out on gains. There is no magic here. Mypersonal advice is to stick somewhat close to the defaults, and try tocontinuously deposit a little more fiat every week to spread the risk but alsocatch some dips.
Ideally, this script would help to make sure that when we dip—
we buy.
Duh. Not my fault if you lose everything.
Unless you place absolute trust in me, some guy from the Internet, I suggestyou clone the repo and build your own container to protect yourself from anytype of funny business.
The package itself can be used as a Docker container, or by installing thepip package with pip install optimal-buy-cbpro
. Using the Docker containeris recommended to avoid Python environment issues. Instructions for runningwith Docker and systemd are as follows:
Set up a Coinbase Pro account, and link your bank account
Create a Coinbase Pro API key with view, trade, manage, transfer, and bypass-2fapermissions
Determine the payment_method_id value by using theCoinbase Pro API (you can use your browser'sdeveloper toolbar,here's a quick video showing how)
Get a machine somewhere (GCE, EC2, Digital Ocean) with Docker and systemd
Copy systemd files over:
$ sudo cp systemd/optimal-buy-cbpro-*.{service,timer} /etc/systemd/system
Edit /etc/systemd/system/optimal-buy-cbpro-buy.service
,/etc/systemd/system/optimal-buy-cbpro-buy.timer
,/etc/systemd/system/optimal-buy-cbpro-deposit.service
, and/etc/systemd/system/optimal-buy-cbpro-deposit.timer
to your liking. Make sure you:
Enable the systemd units:
$ sudo systemctl enable optimal-buy-cbpro-buy.service
$ sudo systemctl enable optimal-buy-cbpro-buy.timer
$ sudo systemctl enable optimal-buy-cbpro-deposit.service
$ sudo systemctl enable optimal-buy-cbpro-deposit.timer
Start the systemd timers:$sudo systemctl start optimal-buy-cbpro-buy.timer$ sudo systemctl start optimal-buy-cbpro-deposit.timer
Enjoy!
usage: optimal-buy-cbpro [-h] --mode MODE [--amount AMOUNT] --key KEY
--b64secret B64SECRET --passphrase PASSPHRASE
[--api-url API_URL]
[--payment-method-id PAYMENT_METHOD_ID]
[--starting-discount STARTING_DISCOUNT]
[--discount-step DISCOUNT_STEP]
[--order-count ORDER_COUNT]
[--fiat-currency FIAT_CURRENCY]
[--withdrawal-amount WITHDRAWAL_AMOUNT]
[--db-engine DB_ENGINE] [--max-retries MAX_RETRIES]
[--coins COINS] [--base-fee BASE_FEE]
Buy coins!
optional arguments:
-h, --help show this help message and exit
--mode MODE mode (deposit or buy)
--amount AMOUNT amount to deposit
--key KEY API key
--b64secret B64SECRET
API secret
--passphrase PASSPHRASE
API passphrase
--api-url API_URL API URL (default: https://api.pro.coinbase.com)
--payment-method-id PAYMENT_METHOD_ID
Payment method ID for fiat deposits
--starting-discount STARTING_DISCOUNT
starting discount (default: 0.005)
--discount-step DISCOUNT_STEP
discount step between orders (default: 0.01)
--order-count ORDER_COUNT
number of orders (default: 5)
--fiat-currency FIAT_CURRENCY
Fiat currency (default: USD)
--withdrawal-amount WITHDRAWAL_AMOUNT
withdraw when fiat balance drops below this amount
(default: 25)
--db-engine DB_ENGINE
SQLAlchemy DB engine (default:
sqlite:///cbpro_history.db)
--max-retries MAX_RETRIES
Maximum number of times to retry if there are any
failures, such as API issues (default: 3)
--coins COINS Coins to trade, minimum trade size, withdrawal
addresses and external balances. Accepts a JSON
string.
--base-fee BASE_FEE Default base fee to subtract from overall balance.
Default coins are as follows:
{
"BTC":{
"name":"Bitcoin",
"withdrawal_address":null,
"external_balance":0
},
"ETH":{
"name":"Ethereum",
"withdrawal_address":null,
"external_balance":0
},
"LTC":{
"name":"Litecoin",
"withdrawal_address":null,
"external_balance":0
}
}
By default, there are 5 orders placed (for each currency) in steps of 1%,starting at a 0.5% discount from the current price. To illustrate, if thecurrent price was $100 (per LTC, let's say), and you had$100 to buy, the orderswould look like this:
Order | Size | Price |
---|---|---|
1 | 0.2010 LTC | $99.5 |
2 | 0.2030 LTC | $98.5 |
3 | 0.2051 LTC | $97.5 |
4 | 0.2072 LTC | $96.5 |
5 | 0.2094 LTC | $95.5 |
Furthermore, the amount of each currency to buy will be based on the currentmarket cap weighting of each coin. For example, at the time of writing theweights are:
Coin | Market Cap (USD) | Weight |
---|---|---|
BTC | $195,824,365,435 | 0.791 |
ETH | $46,080,472,372 | 0.186 |
LTC | $5,592,776,540 | 0.023 |
So if your USD account had $1000, the amount purchased of each wouldbecome:
Coin | Weight | Amount Purchased |
---|---|---|
BTC | 0.791 | $791 |
ETH | 0.186 | $186 |
LTC | 0.023 | $23 |
--withdrawal-amount
) sitting in your account at all times,even when all orders have been filled because it's not always possible tofill all orders and there may be small rounding errors (on the order of cents)Optimal-LSH 提供了可高效执行的局部性敏感哈希(LSH)。实现了 LSH 最优参数计算。
利用 React / Node 实现的应用。项目不怎么复杂,但是五脏六腑俱全,适合新手学习。 English 博客总结 技术栈和主要框架 �� React 全家桶:react + redux + react-router 4.0 + immutable.js �� ES6 + ES7 �� 网络请求:axios + socket.io �� 页面相应式框架:antd mobile ✏️ 后台:ex
1.1 题目 Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the sto
Question leetcode: Best Time to Buy and Sell Stock | LeetCode OJ lintcode: (149) Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a given stock on day i.
Best Time to Buy and Sell Stock 描述 Say you have an array for which the i-th element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one
Question leetcode: Best Time to Buy and Sell Stock IV | LeetCode OJ lintcode: (393) Best Time to Buy and Sell Stock IV Say you have an array for which the ith element is the price of a given stock on