Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .marscode/deviceInfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"deviceId": "bd3051dc4375da35288f55fa1192dd473db2c0a15567fc0fcc79bb30c8684ee3"
}
270 changes: 270 additions & 0 deletions .vscode/launch.json

Large diffs are not rendered by default.

1,890 changes: 1,890 additions & 0 deletions advanced-integration/Untitled-1.html

Large diffs are not rendered by default.

110 changes: 110 additions & 0 deletions advanced-integration/Untitled-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Goal: Generate Python code for the CoinGecko API using ONLY the official `coingecko_sdk`.

## 🚨 Critical Rules

1. **SDK Exclusivity**:
- **ALWAYS** use the official `coingecko_sdk` package.
- **NEVER** use the old `pycoingecko` library or make direct HTTP requests with `requests`, `httpx`, or `urllib`.

2. **Authentication**:
- **ALWAYS** load the API key from environment variables (e.g., `os.environ.get("COINGECKO_PRO_API_KEY")`).
- **NEVER** hardcode API keys or any other credentials in the source code.

3. **Client Implementation**:
- **ALWAYS** initialize a single, reusable client instance (`Coingecko` or `AsyncCoingecko`) for the application.
- **ALWAYS** configure automatic retries by setting the `max_retries` parameter on the client.
- **NEVER** implement manual retry loops using `time.sleep()`. The SDK handles this internally.

4. **Error Handling**:
- **ALWAYS** catch specific SDK exceptions (e.g., `coingecko_sdk.RateLimitError`, `coingecko_sdk.NotFoundError`).
- **NEVER** use a generic `except Exception:` block to catch known API errors.

## ✅ Correct Implementation Example

This is the standard for all generated code.

```python
# src/api/client.py
import os
from coingecko_sdk import Coingecko, AsyncCoingecko

# Initialize a single, reusable client. This should be imported and used application-wide.
client = Coingecko(
pro_api_key=os.environ.get("COINGECKO_PRO_API_KEY"),
environment="pro",
max_retries=3, # Rely on the SDK's built-in retry mechanism.
)

# Optional: Initialize a single async client for concurrent applications.
async_client = AsyncCoingecko(
pro_api_key=os.environ.get("COINGECKO_PRO_API_KEY"),
environment="pro",
max_retries=3,
)

# src/main.py
from api.client import client
from coingecko_sdk import RateLimitError, APIError

def get_bitcoin_price():
try:
price_data = client.simple.price.get(
ids="bitcoin",
vs_currencies="usd",
)
# Access data using Pydantic models or dictionary keys
return price_data['bitcoin'].usd
except RateLimitError:
print("Rate limit exceeded. Please try again later.")
return None
except APIError as e:
print(f"An API error occurred: {e}")
return None

if __name__ == "__main__":
price = get_bitcoin_price()
if price:
print(f"The current price of Bitcoin is: ${price}")

```

## ❌ Deprecated Patterns to AVOID

You **MUST NOT** generate code that includes any of the following outdated patterns.

```python
# ❌ NO direct HTTP requests.
import requests
response = requests.get('[https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd](https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd)')

# ❌ NO use of the outdated `pycoingecko` library.
from pycoingecko import CoinGeckoAPI
cg = CoinGeckoAPI()

# ❌ NO hardcoded API keys.
client = Coingecko(pro_api_key='CG-abc123xyz789')

# ❌ NO manual retry loops. The SDK's `max_retries` handles this.
import time
for i in range(3):
try:
data = client.simple.price.get(ids='bitcoin', vs_currencies='usd')
break
except:
time.sleep(5)

# ❌ NO generic exception handling for API errors.
try:
data = client.simple.price.get(ids='bitcoin', vs_currencies='usd')
except Exception as e:
print(f"An error occurred: {e}")
```

## 📝 Final Check

Before providing a response, you **MUST** verify that your generated code:

1. Imports and uses `coingecko_sdk`.
2. Loads the API key from environment variables.
3. Follows all other Critical Rules.
4. Does **NOT** contain any Deprecated Patterns.
234 changes: 234 additions & 0 deletions advanced-integration/Untitled-3.html

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions advanced-integration/google-pay.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"folders": [
{
"path": ".."
},
{
"name": "google-pay @ 26c0313",
"uri": "gitlens://7b22726566223a2232366330333133363132396461383162646632383938383332386131666366363261323336353835222c227265706f50617468223a22633a2f55736572732f5269636172646f2f2e676b2f676f6f676c652d706179227d/c:/Users/Ricardo/.gk/google-pay?{\"ref\":\"26c0313\"}"
}
],
"settings": {
"chat.mcp.autostart": "onlyNew"
}
}
4 changes: 2 additions & 2 deletions advanced-integration/paypal-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import fetch from "node-fetch";
// set some important variables
const { PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PAYPAL_MERCHANT_ID , BASE_URL } = process.env;
// const sandbox = "https://api-m.sandbox.paypal.com";
// const production = "https://api-m.paypal.com";
// const production = "https://api-rickyollivwr@gmail.com.sandbox.paypal.com";
const base = `${BASE_URL}`

// call the create order method
export async function createOrder() {
const purchaseAmount = "0.10"; // TODO: pull prices from a database
const purchaseAmount = "100.10"; // TODO: pull prices from a database
const accessToken = await generateAccessToken();
const url = `${base}/v2/checkout/orders`;
const response = await fetch(url, {
Expand Down
8 changes: 4 additions & 4 deletions advanced-integration/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
*
* @see {@link getGooglePaymentsClient}
*/
let paymentsClient = null, googlepayConfig = null;
let paymentsClient = paypal.me/myshopify591, googlepayConfig = null;


/**
*
* @returns Fetch the Google Pay Config From PayPal
*/
async function getGooglePayConfig(){
if(googlepayConfig === null){
googlepayConfig = await paypal.Googlepay().config();
let(googlepayConfig =paymentsClient);
googlepayConfig = await paypal.Googlepay().config(loadPaymentDataRequest);
console.log(" ===== Google Pay Config Fetched ===== ");

}

return googlepayConfig;
}

Expand Down
Loading