8000 coinbase bot 401 issue · Issue #26300 · ccxt/ccxt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
coinbase bot 401 issue #26300
Closed
Closed
@Bibiby2

Description

@Bibiby2

Operating System

linux

Programming Languages

Python

CCXT Version

No response

Description

Hi there 👋,

First of all, thank you for this Coinbase trading bot project – I really want to use it with small trades like PEPE/USDC.

I'm trying to use the bot in Google Colab (Python 3) and I followed the README and set up the API with:

  • API Key ✅
  • API Secret ✅
  • API Passphrase ✅

I only activated "View" and "Trade" and selected my Default Portfolio.


❗️ Problem:

When I run the bot, I get this error: API Response Status Code: 401
API Response Text: Unauthorized

⚠️ Fehler: 401 Client Error: Unauthorized for url: https://api.coinbase.com/api/v3/brokerage/products/PEPE-USDC

KeyboardInterrupt Traceback (most recent call last)
/tmp/ipython-input-4-2035704011.py in <cell line: 0>()
110 # ▶️ Bot starten
111 if name == 'main':
--> 112 main()

/tmp/ipython-input-4-2035704011.py in main()
106 print(f"⚠️ Fehler: {e}")
107
--> 108 time.sleep(60) # alle 60 Sekunden prüfen
109
110 # ▶️ Bot starten

KeyboardInterrupt:

Code

import requests
import time
import hmac
import hashlib
import base64

# 🔐 Deine Coinbase Advanced API-Daten
api_key = 
api_secret = 
api_url = 'https://api.coinbase.com'

# 📆 Zeitstempel
def get_timestamp():
    return str(time.time())

# 🛡 Signatur generieren
def create_signature(timestamp, method, request_path, body=''):
    message = timestamp + method + request_path + body
    hmac_key = base64.b64decode(api_secret)
    signature = hmac.new(hmac_key, message.encode('utf-8'), hashlib.sha256)
    return base64.b64encode(signature.digest()).decode()

# 📡 Anfrage senden
def send_request(method, request_path, body=''):
    timestamp = get_timestamp()
    signature = create_signature(timestamp, method, request_path, body)
    headers = {
        'CB-ACCESS-KEY': api_key,
        'CB-ACCESS-SIGN': signature,
        'CB-ACCESS-TIMESTAMP': timestamp,
        'Content-Type': 'application/json'
    }
    url = api_url + request_path
    if method == 'GET':
        response = requests.get(url, headers=headers)
    else:
        response = requests.post(url, headers=headers, data=body)
    print("API Response Status Code:", response.status_code)
    print("API Response Text:", response.text)
    response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)
    return response.json()

# 📈 Preis abfragen
def get_market_price(product_
    response = send_request('GET', f'/api/v3/brokerage/products/{product_id}')
    return float(response['price'])

# 💰 Marktorder ausführen
def place_market_order(side, size, product_id='PEPE-USDC'):
    body = json.dumps({
        'side': side,
        'client_order_id': str(time.time()),
        'product_id': product_id,
        'order_configuration': {
            'market_market_ioc': {
                'quote_size': size
            }
        }
    })
    return send_request('POST', '/api/v3/brokerage/orders', body)

# 🔁 Hauptfunktion mit dynamischem TP/SL
def main():
    in_position = False
    entry_price = 0.0
    trade_size = 
    product_id = 

    while True:
        try:
            current_price = get_market_price(product_id)
            print(f"📊 PEPE/USDC Preis: {current_price} USDC")

            # Noch kein Trade aktiv → Einstieg prüfen
            if not in_position:
                # Beispielstrategie: Einstieg wenn Preis sehr niedrig
                if current_price <= 0.00000100:
                    print("💚 Einstieg erkannt – 
                    place_market_order('BUY', trade_size, product_id)
                    entry_price = current_price
                    in_position = True
                    print(f"🎯 Einstiegspreis gespeichert: {entry_price}")

            # Trade aktiv → prüfen ob Gewinnziel oder Verlustgrenze erreicht
            else:
                stop_loss = entry_price 
                take_profit = entry_price 

                print(f"🔒 SL: {stop_loss:.8f} | 🎯 TP: {take_profit:.8f}")

                if current_price <= stop_loss:
                    print("❌ STOP-LOSS erreicht – Verkaufe")
                    place_market_order('SELL', trade_size, product_id)
                    in_position = False

                elif current_price >= take_profit:
                    print("✅ TAKE-PROFIT erreicht – Verkaufe")
                    place_market_order('SELL', trade_size, product_id)
                    in_position = False

                else:
                    print("⏳ Warte – Zielbereich noch nicht erreicht")

        except Exception as e:
            print(f"⚠️ Fehler: {e}")

        time.sleep(60)  # alle 60 Sekunden prüfen

# ▶️ Bot starten
if __name__ == '__main__':
    main()
  

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0