Coder Social home page Coder Social logo

rhettre / coinbase-advancedtrade-python Goto Github PK

View Code? Open in Web Editor NEW
39.0 6.0 20.0 68 KB

This is the unofficial Python client for the Coinbase Advanced Trade API. It allows users to interact with the API to manage their cryptocurrency trading activities on the Coinbase platform.

Home Page: https://rhett.blog/youtube

License: MIT License

Python 100.00%

coinbase-advancedtrade-python's Introduction

Coinbase Advanced Trade API Python Client

This is the unofficial Python client for the Coinbase Advanced Trade API. It allows users to interact with the API to manage their cryptocurrency trading activities on the Coinbase platform.

Features

  • Easy-to-use Python wrapper for the Coinbase Advanced Trade API
  • Supports all endpoints and methods provided by the official API
  • Lightweight and efficient wrapper
  • Added support for trading strategies covered on the YouTube channel

Setup

  1. Clone this repository or download the source files by running
       pip install coinbase-advancedtrade-python
    
  2. Set your API key and secret in config.py. To obtain your API key and secret, follow the steps below:
    • Log in to your Coinbase account.
    • Navigate to API settings.
    • Create a new API key with the appropriate permissions.
    • Copy the API key and secret to config.py.

Authentication

Here's an example of how to authenticate:

from coinbase_advanced_trader.config import set_api_credentials

# Set your API key and secret
API_KEY = "ABCD1234"
API_SECRET = "XYZ9876"

# Set the API credentials once, and it updates the CBAuth singleton instance
set_api_credentials(API_KEY, API_SECRET)

Usage of Strategies

Here's an example of how to use the strategies package to buy $20 worth of Bitcoin:

from coinbase_advanced_trader.strategies.limit_order_strategies import fiat_limit_buy

# Define the trading parameters
product_id = "BTC-USD"  # Replace with your desired trading pair
usd_size = 20  # Replace with your desired USD amount to spend``

# Perform a limit buy
limit_buy_order = fiat_limit_buy(product_id, usd_size)

Usage of Fear and Greed Index

from coinbase_advanced_trader.strategies.fear_and_greed_strategies import trade_based_on_fgi_simple

# Define the product id
product_id = "BTC-USD"

# Implement the strategy
trade_based_on_fgi_simple(product_id, 10)

Usage of Fear and Greed Index (Pro)

from coinbase_advanced_trader.strategies.fear_and_greed_strategies import trade_based_on_fgi_pro

# Define the product id
product_id = "BTC-USD"

# Define the custom schedule
custom_schedule = [
    {"threshold": 20, "factor": 1, "action": "buy"},
    {"threshold": 80, "factor": 0.5, "action": "buy"},
    {"threshold": 100, "factor": 1, "action": "sell"},
]

# Implement the strategy
response = trade_based_on_fgi_pro(product_id, 10, custom_schedule)

Documentation

For more information about the Coinbase Advanced Trader API, consult the official API documentation.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Author

Rhett Reisman

Email: [email protected]

GitHub: https://github.com/rhettre/coinbase-advancedtrade-python

Disclaimer

This project is not affiliated with, maintained, or endorsed by Coinbase. Use this software at your own risk. Trading cryptocurrencies carries a risk of financial loss. The developers of this software are not responsible for any financial losses or damages incurred while using this software. Nothing in this software should be seen as an inducement to trade with a particular strategy or as financial advice.

coinbase-advancedtrade-python's People

Contributors

rhettre avatar davidmkcodes avatar thomaslc66 avatar

Stargazers

 avatar RafaelM avatar Artem avatar Youran Pan avatar  avatar  avatar Cody avatar Michael Reynolds avatar  avatar  avatar Rossi Meacham avatar Eric B Martin avatar  avatar Luc Rieffel avatar Matt Faltyn avatar Cody Cordova avatar  avatar Carlos Javier Navarro avatar  avatar Erce Amet avatar Jan Kuča avatar  avatar Bryan Grace avatar Optato0tatpO avatar Dehan avatar Adam Goyer avatar Jameson Woodell avatar David Kivlehan avatar Nathan M avatar mrnobody314 avatar  avatar Luke Macken avatar  avatar  avatar  avatar saltyballs avatar  avatar Exius avatar  avatar

Watchers

John Tashiro avatar  avatar Carlos Banales avatar RafaelM avatar Luc Rieffel avatar  avatar

coinbase-advancedtrade-python's Issues

Error while cancelling orders

I'm getting the error 'proto:\xa0syntax error (line 1:1): unexpected token "{\\"order_ids\\": [{\\"market\\": \\"BTC-USD\\", \\"order_id\\": \\"6659a34f-8ec2-4689-8030-22f02113140d\\"}]}"' while trying to cancel orders.

This is my function:

def cancell_all_pending_orders(self):
        open_orders = coinbase_client.listOrders()
        order_ids = [{'market': order['product_id'], 'order_id': order['order_id']} for order in open_orders]
        order_cancelled = coinbase_client.cancelOrders(order_ids)
        print(f"ORDERS MANAGEMENT | {order_ids} cancelled succesfully")

listAccounts not working?

I ran the example code -you know the one with the buy_bitcoin method- and I add this to the end of it:

accounts = coinbase_client.listAccounts()
print(accounts)

in return I get:
"{'error': 'NOT_FOUND', 'error_details': "Could not find user's accounts information", 'message': "Could not find user's accounts information"}"

getProductCandles “granularity argument is invalid” error

while using getProductCandles function, I was not able to get a response back due to an error I was seeing via granularity argument being invalid.

I saw someone else was having the same issue: https://forums.coinbasecloud.dev/t/granularity-argument-is-invalid-error/5080

I tested passing in the values into the url as query parameters and was able to get a response back

    return cb_auth(
        Method.GET.value,
        f"/api/v3/brokerage/products/{product_id}/candles?start={start}&end={end}&granularity={granularity}",
    )

Buy and Sell for X% Higher Strategy

Is there a way to look up your last buy and list a limit sell for the same amount of BTC but at a price that is X% higher than I paid for it?

Based on the youtube comment from @mattlaurabullard5115

listAccounts() doesn't respect cursor/pagination

Really like your work on this coinbase advanced trader API! I have added several methods to my working copy of the codebase and noticed that the listAccounts() method was only returning partial account info. I'd like to provide code for you to review - let me know the best path for that.

Limit order doesnt work, fails on "order_details['success']"

Running this code:

from coinbase_advanced_trader.strategies.limit_order_strategies import fiat_limit_buy
from coinbase_advanced_trader.config import set_api_credentials

# Set your API key and secret
API_KEY = 'foo'
API_SECRET = 'bar'

# Set the API credentials once, and it updates the CBAuth singleton instance
set_api_credentials(API_KEY, API_SECRET)

# Define the trading parameters
product_id = "BTC-USD"  # Replace with your desired trading pair
usd_size = 1  # Replace with your desired USD amount to spend``

# Perform a limit buy
limit_buy_order = fiat_limit_buy(product_id, usd_size)

(venv) [me@host coinbase-advancedtrade-python]$ python test_order.py
Authenticating with Coinbase
Traceback (most recent call last):
File "/home/me/Code/coinbase-advancedtrade-python/test_order.py", line 16, in
limit_buy_order = fiat_limit_buy(product_id, usd_size)
File "/home/me/Code/coinbase-advancedtrade-python/coinbase_advanced_trader/strategies/limit_order_strategies.py", line 66, in fiat_limit_buy
print (order_details['success'])
KeyError: 'success'

MarketOrders

create functionality for market orders similar to how we did limit orders

Invalid order error handling

Implement better error handling around methods when users try to make invalid orders

Youtube comment:
this is great! thanks for sharing, I have tried fiat_limit_buy and noticed when I pass on a float like 1.001 inside the price_multiplier to place a buy order slightly above the current price (to instantly buy) it comes back with an an unknown error. When I change the float to something like 0.9 then it does work but the order is below the current price. How can I make it place the limit order above the current price ?

Telegram version

Hey,

Wanted to thank you for your cool work.

I've forked you repo and improved it with some telegram bot command that you can use to set and create order directly with the telegram bot.

Also I've improved the security putting api key in an env file and I created a dockerfile with documentation to build it directly to run.

The telegram bot improvement make the script run continuously and let you send buy order whenever you want and also create DCA order

Have a look and let me know what you think?
https://github.com/thomaslc66/coinbase-advancedtrade-python

Cheers.

Thomas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.