@intentsolutionsio/crypto-derivatives-tracker 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +22 -0
- package/LICENSE +21 -0
- package/README.md +173 -0
- package/agents/derivatives-agent.md +408 -0
- package/package.json +43 -0
- package/skills/skill-adapter/assets/README.md +6 -0
- package/skills/skill-adapter/assets/config-template.json +32 -0
- package/skills/skill-adapter/assets/skill-schema.json +28 -0
- package/skills/skill-adapter/assets/test-data.json +27 -0
- package/skills/skill-adapter/references/README.md +4 -0
- package/skills/skill-adapter/references/best-practices.md +69 -0
- package/skills/skill-adapter/references/examples.md +73 -0
- package/skills/skill-adapter/scripts/README.md +8 -0
- package/skills/skill-adapter/scripts/helper-template.sh +42 -0
- package/skills/skill-adapter/scripts/validation.sh +32 -0
- package/skills/tracking-crypto-derivatives/ARD.md +376 -0
- package/skills/tracking-crypto-derivatives/PRD.md +258 -0
- package/skills/tracking-crypto-derivatives/SKILL.md +127 -0
- package/skills/tracking-crypto-derivatives/config/settings.yaml +152 -0
- package/skills/tracking-crypto-derivatives/references/errors.md +224 -0
- package/skills/tracking-crypto-derivatives/references/examples.md +460 -0
- package/skills/tracking-crypto-derivatives/references/implementation.md +113 -0
- package/skills/tracking-crypto-derivatives/scripts/basis_calculator.py +377 -0
- package/skills/tracking-crypto-derivatives/scripts/derivatives_tracker.py +579 -0
- package/skills/tracking-crypto-derivatives/scripts/formatters.py +459 -0
- package/skills/tracking-crypto-derivatives/scripts/funding_tracker.py +308 -0
- package/skills/tracking-crypto-derivatives/scripts/liquidation_monitor.py +356 -0
- package/skills/tracking-crypto-derivatives/scripts/oi_analyzer.py +338 -0
- package/skills/tracking-crypto-derivatives/scripts/options_analyzer.py +373 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"skill": {
|
|
3
|
+
"name": "skill-name",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"enabled": true,
|
|
6
|
+
"settings": {
|
|
7
|
+
"verbose": false,
|
|
8
|
+
"autoActivate": true,
|
|
9
|
+
"toolRestrictions": true
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"triggers": {
|
|
13
|
+
"keywords": [
|
|
14
|
+
"example-trigger-1",
|
|
15
|
+
"example-trigger-2"
|
|
16
|
+
],
|
|
17
|
+
"patterns": []
|
|
18
|
+
},
|
|
19
|
+
"tools": {
|
|
20
|
+
"allowed": [
|
|
21
|
+
"Read",
|
|
22
|
+
"Grep",
|
|
23
|
+
"Bash"
|
|
24
|
+
],
|
|
25
|
+
"restricted": []
|
|
26
|
+
},
|
|
27
|
+
"metadata": {
|
|
28
|
+
"author": "Plugin Author",
|
|
29
|
+
"category": "general",
|
|
30
|
+
"tags": []
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "Claude Skill Configuration",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"required": ["name", "description"],
|
|
6
|
+
"properties": {
|
|
7
|
+
"name": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"pattern": "^[a-z0-9-]+$",
|
|
10
|
+
"maxLength": 64,
|
|
11
|
+
"description": "Skill identifier (lowercase, hyphens only)"
|
|
12
|
+
},
|
|
13
|
+
"description": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"maxLength": 1024,
|
|
16
|
+
"description": "What the skill does and when to use it"
|
|
17
|
+
},
|
|
18
|
+
"allowed-tools": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "Comma-separated list of allowed tools"
|
|
21
|
+
},
|
|
22
|
+
"version": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"pattern": "^\\d+\\.\\d+\\.\\d+$",
|
|
25
|
+
"description": "Semantic version (x.y.z)"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"testCases": [
|
|
3
|
+
{
|
|
4
|
+
"name": "Basic activation test",
|
|
5
|
+
"input": "trigger phrase example",
|
|
6
|
+
"expected": {
|
|
7
|
+
"activated": true,
|
|
8
|
+
"toolsUsed": ["Read", "Grep"],
|
|
9
|
+
"success": true
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"name": "Complex workflow test",
|
|
14
|
+
"input": "multi-step trigger example",
|
|
15
|
+
"expected": {
|
|
16
|
+
"activated": true,
|
|
17
|
+
"steps": 3,
|
|
18
|
+
"toolsUsed": ["Read", "Write", "Bash"],
|
|
19
|
+
"success": true
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"fixtures": {
|
|
24
|
+
"sampleInput": "example data",
|
|
25
|
+
"expectedOutput": "processed result"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Skill Best Practices
|
|
2
|
+
|
|
3
|
+
Guidelines for optimal skill usage and development.
|
|
4
|
+
|
|
5
|
+
## For Users
|
|
6
|
+
|
|
7
|
+
### Activation Best Practices
|
|
8
|
+
|
|
9
|
+
1. **Use Clear Trigger Phrases**
|
|
10
|
+
- Match phrases from skill description
|
|
11
|
+
- Be specific about intent
|
|
12
|
+
- Provide necessary context
|
|
13
|
+
|
|
14
|
+
2. **Provide Sufficient Context**
|
|
15
|
+
- Include relevant file paths
|
|
16
|
+
- Specify scope of analysis
|
|
17
|
+
- Mention any constraints
|
|
18
|
+
|
|
19
|
+
3. **Understand Tool Permissions**
|
|
20
|
+
- Check allowed-tools in frontmatter
|
|
21
|
+
- Know what the skill can/cannot do
|
|
22
|
+
- Request appropriate actions
|
|
23
|
+
|
|
24
|
+
### Workflow Optimization
|
|
25
|
+
|
|
26
|
+
- Start with simple requests
|
|
27
|
+
- Build up to complex workflows
|
|
28
|
+
- Verify each step before proceeding
|
|
29
|
+
- Use skill consistently for related tasks
|
|
30
|
+
|
|
31
|
+
## For Developers
|
|
32
|
+
|
|
33
|
+
### Skill Development Guidelines
|
|
34
|
+
|
|
35
|
+
1. **Clear Descriptions**
|
|
36
|
+
- Include explicit trigger phrases
|
|
37
|
+
- Document all capabilities
|
|
38
|
+
- Specify limitations
|
|
39
|
+
|
|
40
|
+
2. **Proper Tool Permissions**
|
|
41
|
+
- Use minimal necessary tools
|
|
42
|
+
- Document security implications
|
|
43
|
+
- Test with restricted tools
|
|
44
|
+
|
|
45
|
+
3. **Comprehensive Documentation**
|
|
46
|
+
- Provide usage examples
|
|
47
|
+
- Document common pitfalls
|
|
48
|
+
- Include troubleshooting guide
|
|
49
|
+
|
|
50
|
+
### Maintenance
|
|
51
|
+
|
|
52
|
+
- Keep version updated
|
|
53
|
+
- Test after tool updates
|
|
54
|
+
- Monitor user feedback
|
|
55
|
+
- Iterate on descriptions
|
|
56
|
+
|
|
57
|
+
## Performance Tips
|
|
58
|
+
|
|
59
|
+
- Scope skills to specific domains
|
|
60
|
+
- Avoid overlapping trigger phrases
|
|
61
|
+
- Keep descriptions under 1024 chars
|
|
62
|
+
- Test activation reliability
|
|
63
|
+
|
|
64
|
+
## Security Considerations
|
|
65
|
+
|
|
66
|
+
- Never include secrets in skill files
|
|
67
|
+
- Validate all inputs
|
|
68
|
+
- Use read-only tools when possible
|
|
69
|
+
- Document security requirements
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Skill Usage Examples
|
|
2
|
+
|
|
3
|
+
This document provides practical examples of how to use this skill effectively.
|
|
4
|
+
|
|
5
|
+
## Basic Usage
|
|
6
|
+
|
|
7
|
+
### Example 1: Simple Activation
|
|
8
|
+
|
|
9
|
+
**User Request:**
|
|
10
|
+
```
|
|
11
|
+
[Describe trigger phrase here]
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
**Skill Response:**
|
|
15
|
+
1. Analyzes the request
|
|
16
|
+
2. Performs the required action
|
|
17
|
+
3. Returns results
|
|
18
|
+
|
|
19
|
+
### Example 2: Complex Workflow
|
|
20
|
+
|
|
21
|
+
**User Request:**
|
|
22
|
+
```
|
|
23
|
+
[Describe complex scenario]
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Workflow:**
|
|
27
|
+
1. Step 1: Initial analysis
|
|
28
|
+
2. Step 2: Data processing
|
|
29
|
+
3. Step 3: Result generation
|
|
30
|
+
4. Step 4: Validation
|
|
31
|
+
|
|
32
|
+
## Advanced Patterns
|
|
33
|
+
|
|
34
|
+
### Pattern 1: Chaining Operations
|
|
35
|
+
|
|
36
|
+
Combine this skill with other tools:
|
|
37
|
+
```
|
|
38
|
+
Step 1: Use this skill for [purpose]
|
|
39
|
+
Step 2: Chain with [other tool]
|
|
40
|
+
Step 3: Finalize with [action]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Pattern 2: Error Handling
|
|
44
|
+
|
|
45
|
+
If issues occur:
|
|
46
|
+
- Check trigger phrase matches
|
|
47
|
+
- Verify context is available
|
|
48
|
+
- Review allowed-tools permissions
|
|
49
|
+
|
|
50
|
+
## Tips & Best Practices
|
|
51
|
+
|
|
52
|
+
- ✅ Be specific with trigger phrases
|
|
53
|
+
- ✅ Provide necessary context
|
|
54
|
+
- ✅ Check tool permissions match needs
|
|
55
|
+
- ❌ Avoid vague requests
|
|
56
|
+
- ❌ Don't mix unrelated tasks
|
|
57
|
+
|
|
58
|
+
## Common Issues
|
|
59
|
+
|
|
60
|
+
**Issue:** Skill doesn't activate
|
|
61
|
+
**Solution:** Use exact trigger phrases from description
|
|
62
|
+
|
|
63
|
+
**Issue:** Unexpected results
|
|
64
|
+
**Solution:** Check input format and context
|
|
65
|
+
|
|
66
|
+
## See Also
|
|
67
|
+
|
|
68
|
+
- Main SKILL.md for full documentation
|
|
69
|
+
- scripts/ for automation helpers
|
|
70
|
+
- assets/ for configuration examples
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
*[Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)*
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Scripts
|
|
2
|
+
|
|
3
|
+
Bundled resources for crypto-derivatives-tracker skill
|
|
4
|
+
|
|
5
|
+
- [ ] fetch_derivatives_data.py: Script to fetch and parse derivatives data from various exchanges.
|
|
6
|
+
- [ ] analyze_funding_rates.py: Script to analyze funding rates and identify potential trading signals.
|
|
7
|
+
- [ ] calculate_open_interest.py: Script to calculate open interest across different exchanges and contracts.
|
|
8
|
+
- [ ] liquidation_levels.py: Script to determine liquidation levels based on current market conditions.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Helper script template for skill automation
|
|
3
|
+
# Customize this for your skill's specific needs
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
function show_usage() {
|
|
8
|
+
echo "Usage: $0 [options]"
|
|
9
|
+
echo ""
|
|
10
|
+
echo "Options:"
|
|
11
|
+
echo " -h, --help Show this help message"
|
|
12
|
+
echo " -v, --verbose Enable verbose output"
|
|
13
|
+
echo ""
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
# Parse arguments
|
|
17
|
+
VERBOSE=false
|
|
18
|
+
|
|
19
|
+
while [[ $# -gt 0 ]]; do
|
|
20
|
+
case $1 in
|
|
21
|
+
-h|--help)
|
|
22
|
+
show_usage
|
|
23
|
+
exit 0
|
|
24
|
+
;;
|
|
25
|
+
-v|--verbose)
|
|
26
|
+
VERBOSE=true
|
|
27
|
+
shift
|
|
28
|
+
;;
|
|
29
|
+
*)
|
|
30
|
+
echo "Unknown option: $1"
|
|
31
|
+
show_usage
|
|
32
|
+
exit 1
|
|
33
|
+
;;
|
|
34
|
+
esac
|
|
35
|
+
done
|
|
36
|
+
|
|
37
|
+
# Your skill logic here
|
|
38
|
+
if [ "$VERBOSE" = true ]; then
|
|
39
|
+
echo "Running skill automation..."
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
echo "✅ Complete"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Skill validation helper
|
|
3
|
+
# Validates skill activation and functionality
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
echo "🔍 Validating skill..."
|
|
8
|
+
|
|
9
|
+
# Check if SKILL.md exists
|
|
10
|
+
if [ ! -f "../SKILL.md" ]; then
|
|
11
|
+
echo "❌ Error: SKILL.md not found"
|
|
12
|
+
exit 1
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
# Validate frontmatter
|
|
16
|
+
if ! grep -q "^---$" "../SKILL.md"; then
|
|
17
|
+
echo "❌ Error: No frontmatter found"
|
|
18
|
+
exit 1
|
|
19
|
+
fi
|
|
20
|
+
|
|
21
|
+
# Check required fields
|
|
22
|
+
if ! grep -q "^name:" "../SKILL.md"; then
|
|
23
|
+
echo "❌ Error: Missing 'name' field"
|
|
24
|
+
exit 1
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
if ! grep -q "^description:" "../SKILL.md"; then
|
|
28
|
+
echo "❌ Error: Missing 'description' field"
|
|
29
|
+
exit 1
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
echo "✅ Skill validation passed"
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
# ARD: Crypto Derivatives Tracker
|
|
2
|
+
|
|
3
|
+
> Part of [Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)
|
|
4
|
+
|
|
5
|
+
## Architecture Pattern
|
|
6
|
+
|
|
7
|
+
**Multi-Exchange Aggregation with Real-Time Processing**
|
|
8
|
+
|
|
9
|
+
This skill aggregates derivatives data from multiple exchanges, normalizes formats, and provides unified analysis across funding rates, open interest, liquidations, and options markets.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Architectural Overview
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
17
|
+
│ derivatives_tracker.py (CLI) │
|
|
18
|
+
│ funding | oi | liquidations | options | basis commands │
|
|
19
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
20
|
+
│
|
|
21
|
+
┌────────────────────────┼────────────────────────┐
|
|
22
|
+
▼ ▼ ▼
|
|
23
|
+
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
|
24
|
+
│ FundingTracker │ │ OIAnalyzer │ │LiquidationMonitor│
|
|
25
|
+
│ Multi-exchange │ │ Position data │ │ Heatmap & alerts │
|
|
26
|
+
│ rate aggregation│ │ trend analysis │ │ cascade risk │
|
|
27
|
+
└─────────────────┘ └─────────────────┘ └─────────────────┘
|
|
28
|
+
│ │ │
|
|
29
|
+
└────────────────────────┼────────────────────────┘
|
|
30
|
+
▼
|
|
31
|
+
┌─────────────────────────┐
|
|
32
|
+
│ ExchangeClient │
|
|
33
|
+
│ Unified API interface │
|
|
34
|
+
│ Rate limit handling │
|
|
35
|
+
└─────────────────────────┘
|
|
36
|
+
│
|
|
37
|
+
┌────────────────────────┼────────────────────────┐
|
|
38
|
+
▼ ▼ ▼
|
|
39
|
+
┌─────────┐ ┌─────────┐ ┌─────────┐
|
|
40
|
+
│ Binance │ │ Bybit │ │ Deribit │
|
|
41
|
+
│ API │ │ API │ │ API │
|
|
42
|
+
└─────────┘ └─────────┘ └─────────┘
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Workflow
|
|
48
|
+
|
|
49
|
+
### Step 1: Exchange Client Initialization
|
|
50
|
+
Configure API connections for each supported exchange with rate limiting.
|
|
51
|
+
|
|
52
|
+
### Step 2: Data Fetching
|
|
53
|
+
Parallel fetch from all exchanges for:
|
|
54
|
+
- Funding rates (perpetuals)
|
|
55
|
+
- Open interest (futures + perps)
|
|
56
|
+
- Recent liquidations
|
|
57
|
+
- Options data (Deribit primarily)
|
|
58
|
+
|
|
59
|
+
### Step 3: Data Normalization
|
|
60
|
+
Standardize formats across exchanges:
|
|
61
|
+
- Convert funding to 8-hour basis
|
|
62
|
+
- Normalize OI to USD equivalent
|
|
63
|
+
- Unify liquidation formats
|
|
64
|
+
|
|
65
|
+
### Step 4: Analysis & Aggregation
|
|
66
|
+
- Calculate weighted averages
|
|
67
|
+
- Detect divergences
|
|
68
|
+
- Generate signals
|
|
69
|
+
|
|
70
|
+
### Step 5: Output
|
|
71
|
+
Present in requested format (console/JSON).
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Data Flow
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
Exchange APIs Normalization Analysis Output
|
|
79
|
+
┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────┐
|
|
80
|
+
│ Binance │─────────│ Funding │─────────│ Rate │─────────│Console│
|
|
81
|
+
│ funding │ │ Normalize │ │ Comparison│ │ JSON │
|
|
82
|
+
└───────────┘ └───────────┘ └───────────┘ └───────┘
|
|
83
|
+
│ │ │
|
|
84
|
+
┌───────────┐ ┌───────────┐ ┌───────────┐
|
|
85
|
+
│ Bybit │─────────│ OI │─────────│ Trend │
|
|
86
|
+
│ OI data │ │ Normalize │ │ Analysis │
|
|
87
|
+
└───────────┘ └───────────┘ └───────────┘
|
|
88
|
+
│ │ │
|
|
89
|
+
┌───────────┐ ┌───────────┐ ┌───────────┐
|
|
90
|
+
│ Deribit │─────────│ Options │─────────│ Flow │
|
|
91
|
+
│ options │ │ Normalize │ │ Analysis │
|
|
92
|
+
└───────────┘ └───────────┘ └───────────┘
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Progressive Disclosure Strategy
|
|
98
|
+
|
|
99
|
+
### Level 1: Quick Summary
|
|
100
|
+
Single-line current funding rate or OI.
|
|
101
|
+
```
|
|
102
|
+
BTC Funding: +0.015% (Binance) | OI: $18.5B (+2.3% 24h)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Level 2: Standard Report
|
|
106
|
+
Tabular view across exchanges with key metrics.
|
|
107
|
+
```
|
|
108
|
+
BTC FUNDING RATES
|
|
109
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
110
|
+
Exchange Current 24h Avg Annualized
|
|
111
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
112
|
+
Binance +0.0150% +0.0120% +16.43%
|
|
113
|
+
Bybit +0.0180% +0.0140% +19.71%
|
|
114
|
+
...
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Level 3: Deep Analysis
|
|
118
|
+
Full derivatives dashboard with all metrics, signals, and risk assessment.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Tool Permission Strategy
|
|
123
|
+
|
|
124
|
+
```yaml
|
|
125
|
+
allowed-tools: Read, Write, Edit, Grep, Glob, Bash(crypto:derivatives-*)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Tool Justification
|
|
129
|
+
|
|
130
|
+
| Tool | Usage |
|
|
131
|
+
|------|-------|
|
|
132
|
+
| Read | Load config, API credentials |
|
|
133
|
+
| Write | Save reports, cache data |
|
|
134
|
+
| Edit | Update configuration |
|
|
135
|
+
| Grep | Search historical data |
|
|
136
|
+
| Glob | Find data files |
|
|
137
|
+
| Bash(crypto:derivatives-*) | Execute data fetching scripts |
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Directory Structure
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
skills/tracking-crypto-derivatives/
|
|
145
|
+
├── SKILL.md # Core skill instructions
|
|
146
|
+
├── PRD.md # Product requirements
|
|
147
|
+
├── ARD.md # This file
|
|
148
|
+
├── scripts/
|
|
149
|
+
│ ├── derivatives_tracker.py # Main CLI entry point
|
|
150
|
+
│ ├── exchange_client.py # Unified exchange interface
|
|
151
|
+
│ ├── funding_tracker.py # Funding rate analysis
|
|
152
|
+
│ ├── oi_analyzer.py # Open interest analysis
|
|
153
|
+
│ ├── liquidation_monitor.py # Liquidation tracking
|
|
154
|
+
│ ├── options_analyzer.py # Options market analysis
|
|
155
|
+
│ ├── basis_calculator.py # Basis/arbitrage calculations
|
|
156
|
+
│ └── formatters.py # Output formatting
|
|
157
|
+
├── config/
|
|
158
|
+
│ └── settings.yaml # Exchange configs, thresholds
|
|
159
|
+
└── references/
|
|
160
|
+
├── errors.md # Error handling guide
|
|
161
|
+
├── examples.md # Usage examples
|
|
162
|
+
└── implementation.md # Implementation details
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## API Integration Architecture
|
|
168
|
+
|
|
169
|
+
### Exchange Client Interface
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
class ExchangeClient:
|
|
173
|
+
"""Unified interface for all exchanges."""
|
|
174
|
+
|
|
175
|
+
def get_funding_rate(self, symbol: str) -> FundingRate
|
|
176
|
+
def get_open_interest(self, symbol: str) -> OpenInterest
|
|
177
|
+
def get_liquidations(self, symbol: str, limit: int) -> List[Liquidation]
|
|
178
|
+
def get_options_data(self, symbol: str) -> OptionsData
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Supported Exchanges
|
|
182
|
+
|
|
183
|
+
| Exchange | Funding | OI | Liquidations | Options |
|
|
184
|
+
|----------|---------|-------|--------------|---------|
|
|
185
|
+
| Binance | ✓ | ✓ | ✓ | ✗ |
|
|
186
|
+
| Bybit | ✓ | ✓ | ✓ | ✓ |
|
|
187
|
+
| OKX | ✓ | ✓ | ✓ | ✓ |
|
|
188
|
+
| Deribit | ✓ | ✓ | ✗ | ✓ (primary) |
|
|
189
|
+
| BitMEX | ✓ | ✓ | ✓ | ✗ |
|
|
190
|
+
|
|
191
|
+
### Rate Limiting Strategy
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
RATE_LIMITS = {
|
|
195
|
+
"binance": {"requests_per_minute": 1200, "weight_per_request": 1},
|
|
196
|
+
"bybit": {"requests_per_minute": 120, "weight_per_request": 1},
|
|
197
|
+
"okx": {"requests_per_minute": 60, "weight_per_request": 1},
|
|
198
|
+
"deribit": {"requests_per_day": 10000, "weight_per_request": 1},
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Data Models
|
|
205
|
+
|
|
206
|
+
### FundingRate
|
|
207
|
+
```python
|
|
208
|
+
@dataclass
|
|
209
|
+
class FundingRate:
|
|
210
|
+
exchange: str
|
|
211
|
+
symbol: str
|
|
212
|
+
rate: Decimal # Current 8-hour rate
|
|
213
|
+
predicted_rate: Decimal # Next predicted rate
|
|
214
|
+
next_payment: datetime # Time until next payment
|
|
215
|
+
annualized: float # Annualized yield
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### OpenInterest
|
|
219
|
+
```python
|
|
220
|
+
@dataclass
|
|
221
|
+
class OpenInterest:
|
|
222
|
+
exchange: str
|
|
223
|
+
symbol: str
|
|
224
|
+
oi_usd: Decimal # Total OI in USD
|
|
225
|
+
oi_contracts: Decimal # Total contracts
|
|
226
|
+
change_24h_pct: float # 24h change
|
|
227
|
+
change_7d_pct: float # 7d change
|
|
228
|
+
long_ratio: float # Long/short ratio
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Liquidation
|
|
232
|
+
```python
|
|
233
|
+
@dataclass
|
|
234
|
+
class Liquidation:
|
|
235
|
+
exchange: str
|
|
236
|
+
symbol: str
|
|
237
|
+
side: str # "long" or "short"
|
|
238
|
+
price: Decimal
|
|
239
|
+
quantity: Decimal
|
|
240
|
+
value_usd: Decimal
|
|
241
|
+
timestamp: datetime
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### OptionsSnapshot
|
|
245
|
+
```python
|
|
246
|
+
@dataclass
|
|
247
|
+
class OptionsSnapshot:
|
|
248
|
+
symbol: str
|
|
249
|
+
expiry: date
|
|
250
|
+
atm_iv: float # At-the-money IV
|
|
251
|
+
put_call_ratio: float # By volume
|
|
252
|
+
put_call_oi: float # By open interest
|
|
253
|
+
max_pain: Decimal # Max pain price
|
|
254
|
+
total_oi_usd: Decimal
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Error Handling Strategy
|
|
260
|
+
|
|
261
|
+
### Exchange Errors
|
|
262
|
+
|
|
263
|
+
| Error Type | Handling |
|
|
264
|
+
|------------|----------|
|
|
265
|
+
| API Rate Limit | Exponential backoff, queue requests |
|
|
266
|
+
| API Timeout | Retry with fallback exchange |
|
|
267
|
+
| Invalid Symbol | Skip exchange, continue others |
|
|
268
|
+
| Auth Failed | Log warning, use public endpoints |
|
|
269
|
+
|
|
270
|
+
### Data Quality
|
|
271
|
+
|
|
272
|
+
| Issue | Handling |
|
|
273
|
+
|-------|----------|
|
|
274
|
+
| Stale Data | Flag staleness, show warning |
|
|
275
|
+
| Missing Exchange | Exclude from aggregation |
|
|
276
|
+
| Inconsistent Units | Normalize to standard format |
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Composability & Stacking
|
|
281
|
+
|
|
282
|
+
### Works With
|
|
283
|
+
|
|
284
|
+
| Skill | Integration |
|
|
285
|
+
|-------|-------------|
|
|
286
|
+
| market-price-tracker | Spot price for basis calculations |
|
|
287
|
+
| arbitrage-finder | Cross-exchange funding arbitrage |
|
|
288
|
+
| options-flow-analyzer | Deep options analysis |
|
|
289
|
+
| whale-alert-monitor | Large liquidation correlation |
|
|
290
|
+
|
|
291
|
+
### Output Formats
|
|
292
|
+
|
|
293
|
+
- **Console**: Formatted tables and reports
|
|
294
|
+
- **JSON**: Machine-readable for pipelines
|
|
295
|
+
- **CSV**: Export for spreadsheet analysis
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## Performance & Scalability
|
|
300
|
+
|
|
301
|
+
### Caching Strategy
|
|
302
|
+
|
|
303
|
+
```python
|
|
304
|
+
CACHE_TTL = {
|
|
305
|
+
"funding_rates": 60, # 1 minute
|
|
306
|
+
"open_interest": 30, # 30 seconds
|
|
307
|
+
"liquidations": 10, # 10 seconds
|
|
308
|
+
"options_data": 300, # 5 minutes
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### Parallel Fetching
|
|
313
|
+
|
|
314
|
+
```python
|
|
315
|
+
async def fetch_all_funding(symbols: List[str]) -> Dict[str, FundingRate]:
|
|
316
|
+
"""Fetch funding from all exchanges in parallel."""
|
|
317
|
+
tasks = [
|
|
318
|
+
fetch_funding(exchange, symbol)
|
|
319
|
+
for exchange in EXCHANGES
|
|
320
|
+
for symbol in symbols
|
|
321
|
+
]
|
|
322
|
+
return await asyncio.gather(*tasks)
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## Testing Strategy
|
|
328
|
+
|
|
329
|
+
### Unit Tests
|
|
330
|
+
- Funding rate calculations
|
|
331
|
+
- OI normalization
|
|
332
|
+
- Liquidation aggregation
|
|
333
|
+
- Basis calculations
|
|
334
|
+
|
|
335
|
+
### Integration Tests
|
|
336
|
+
- Exchange API connectivity
|
|
337
|
+
- Rate limit handling
|
|
338
|
+
- Error recovery
|
|
339
|
+
|
|
340
|
+
### Mock Data
|
|
341
|
+
- Simulated exchange responses
|
|
342
|
+
- Historical liquidation data
|
|
343
|
+
- Options chain snapshots
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## Security & Compliance
|
|
348
|
+
|
|
349
|
+
### API Key Handling
|
|
350
|
+
- Keys stored in environment variables or config
|
|
351
|
+
- Read-only permissions only (no trading)
|
|
352
|
+
- No key logging in outputs
|
|
353
|
+
|
|
354
|
+
### Data Privacy
|
|
355
|
+
- No personal data collected
|
|
356
|
+
- No trading history stored
|
|
357
|
+
- Analysis only, no execution
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## Monitoring & Alerts
|
|
362
|
+
|
|
363
|
+
### Alert Thresholds (Configurable)
|
|
364
|
+
|
|
365
|
+
```yaml
|
|
366
|
+
alerts:
|
|
367
|
+
funding_extreme: 0.1 # 0.1% 8-hour funding
|
|
368
|
+
oi_change_large: 15 # 15% OI change
|
|
369
|
+
liquidation_large: 1000000 # $1M liquidation
|
|
370
|
+
iv_extreme: 100 # 100% IV
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Alert Outputs
|
|
374
|
+
- Console warnings with emoji indicators
|
|
375
|
+
- JSON alerts for webhook integration
|
|
376
|
+
- Summary at end of report
|