@hummingbot/skills 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.
Files changed (35) hide show
  1. package/README.md +63 -0
  2. package/package.json +28 -0
  3. package/skills/candles-feed/SKILL.md +259 -0
  4. package/skills/candles-feed/scripts/calculate_indicator.sh +359 -0
  5. package/skills/candles-feed/scripts/get_candles.sh +158 -0
  6. package/skills/candles-feed/scripts/get_funding_rate.sh +112 -0
  7. package/skills/candles-feed/scripts/get_price.sh +86 -0
  8. package/skills/candles-feed/scripts/list_candle_connectors.sh +47 -0
  9. package/skills/executor-creator/SKILL.md +212 -0
  10. package/skills/executor-creator/scripts/clear_position.sh +54 -0
  11. package/skills/executor-creator/scripts/create_executor.sh +92 -0
  12. package/skills/executor-creator/scripts/get_executor.sh +37 -0
  13. package/skills/executor-creator/scripts/get_executor_schema.sh +37 -0
  14. package/skills/executor-creator/scripts/get_executors_summary.sh +30 -0
  15. package/skills/executor-creator/scripts/get_position.sh +44 -0
  16. package/skills/executor-creator/scripts/get_positions.sh +30 -0
  17. package/skills/executor-creator/scripts/list_executor_types.sh +30 -0
  18. package/skills/executor-creator/scripts/list_executors.sh +52 -0
  19. package/skills/executor-creator/scripts/setup_executor.sh +197 -0
  20. package/skills/executor-creator/scripts/stop_executor.sh +54 -0
  21. package/skills/hummingbot-api-setup/SKILL.md +308 -0
  22. package/skills/hummingbot-api-setup/references/original_setup.sh +628 -0
  23. package/skills/hummingbot-api-setup/scripts/check_prerequisites.sh +92 -0
  24. package/skills/hummingbot-api-setup/scripts/deploy_full_stack.sh +151 -0
  25. package/skills/hummingbot-api-setup/scripts/health_check.sh +100 -0
  26. package/skills/hummingbot-api-setup/scripts/step1_detect_system.sh +88 -0
  27. package/skills/hummingbot-api-setup/scripts/step2_check_dependencies.sh +81 -0
  28. package/skills/keys-manager/SKILL.md +132 -0
  29. package/skills/keys-manager/scripts/add_credentials.sh +106 -0
  30. package/skills/keys-manager/scripts/get_connector_config.sh +67 -0
  31. package/skills/keys-manager/scripts/list_account_credentials.sh +82 -0
  32. package/skills/keys-manager/scripts/list_connectors.sh +64 -0
  33. package/skills/keys-manager/scripts/remove_credentials.sh +79 -0
  34. package/skills/keys-manager/scripts/setup_connector.sh +214 -0
  35. package/skills.json +137 -0
@@ -0,0 +1,106 @@
1
+ #!/bin/bash
2
+ # Add exchange credentials to an account
3
+ # Usage: ./add_credentials.sh --connector CONNECTOR --credentials '{"key": "value"}' [--account ACCOUNT] [--force]
4
+
5
+ set -e
6
+
7
+ API_URL="${API_URL:-http://localhost:8000}"
8
+ API_USER="${API_USER:-admin}"
9
+ API_PASS="${API_PASS:-admin}"
10
+ CONNECTOR=""
11
+ CREDENTIALS=""
12
+ ACCOUNT="master_account"
13
+ FORCE=false
14
+
15
+ # Parse arguments
16
+ while [[ $# -gt 0 ]]; do
17
+ case $1 in
18
+ --connector)
19
+ CONNECTOR="$2"
20
+ shift 2
21
+ ;;
22
+ --credentials)
23
+ CREDENTIALS="$2"
24
+ shift 2
25
+ ;;
26
+ --account)
27
+ ACCOUNT="$2"
28
+ shift 2
29
+ ;;
30
+ --force)
31
+ FORCE=true
32
+ shift
33
+ ;;
34
+ --api-url)
35
+ API_URL="$2"
36
+ shift 2
37
+ ;;
38
+ --api-user)
39
+ API_USER="$2"
40
+ shift 2
41
+ ;;
42
+ --api-pass)
43
+ API_PASS="$2"
44
+ shift 2
45
+ ;;
46
+ *)
47
+ shift
48
+ ;;
49
+ esac
50
+ done
51
+
52
+ # Validate required arguments
53
+ if [ -z "$CONNECTOR" ]; then
54
+ echo '{"error": "connector is required. Use --connector CONNECTOR_NAME"}'
55
+ exit 1
56
+ fi
57
+
58
+ if [ -z "$CREDENTIALS" ]; then
59
+ echo '{"error": "credentials is required. Use --credentials JSON_OBJECT"}'
60
+ exit 1
61
+ fi
62
+
63
+ # Normalize connector name
64
+ CONNECTOR=$(echo "$CONNECTOR" | tr '[:upper:]' '[:lower:]' | tr '-' '_' | tr ' ' '_')
65
+
66
+ # Check if credentials already exist
67
+ EXISTING=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/$ACCOUNT/credentials")
68
+ if echo "$EXISTING" | jq -e "index(\"$CONNECTOR\")" > /dev/null 2>&1; then
69
+ if [ "$FORCE" = false ]; then
70
+ cat << EOF
71
+ {
72
+ "error": "Credentials for '$CONNECTOR' already exist on account '$ACCOUNT'",
73
+ "action_required": "Use --force to override existing credentials",
74
+ "existing_connectors": $EXISTING
75
+ }
76
+ EOF
77
+ exit 1
78
+ fi
79
+ fi
80
+
81
+ # Add credentials via API
82
+ RESPONSE=$(curl -s -X POST \
83
+ -u "$API_USER:$API_PASS" \
84
+ -H "Content-Type: application/json" \
85
+ -d "{\"connector_name\": \"$CONNECTOR\", \"credentials\": $CREDENTIALS}" \
86
+ "$API_URL/accounts/$ACCOUNT/credentials")
87
+
88
+ # Check for error
89
+ if echo "$RESPONSE" | jq -e '.detail' > /dev/null 2>&1; then
90
+ echo "{\"error\": \"Failed to add credentials\", \"detail\": $RESPONSE}"
91
+ exit 1
92
+ fi
93
+
94
+ # Verify credentials were added
95
+ UPDATED=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/$ACCOUNT/credentials")
96
+
97
+ cat << EOF
98
+ {
99
+ "status": "success",
100
+ "action": "credentials_added",
101
+ "connector": "$CONNECTOR",
102
+ "account": "$ACCOUNT",
103
+ "was_override": $FORCE,
104
+ "configured_connectors": $UPDATED
105
+ }
106
+ EOF
@@ -0,0 +1,67 @@
1
+ #!/bin/bash
2
+ # Get required credential fields for a specific connector
3
+ # Usage: ./get_connector_config.sh --connector CONNECTOR_NAME
4
+
5
+ set -e
6
+
7
+ API_URL="${API_URL:-http://localhost:8000}"
8
+ API_USER="${API_USER:-admin}"
9
+ API_PASS="${API_PASS:-admin}"
10
+ CONNECTOR=""
11
+
12
+ # Parse arguments
13
+ while [[ $# -gt 0 ]]; do
14
+ case $1 in
15
+ --connector)
16
+ CONNECTOR="$2"
17
+ shift 2
18
+ ;;
19
+ --api-url)
20
+ API_URL="$2"
21
+ shift 2
22
+ ;;
23
+ --api-user)
24
+ API_USER="$2"
25
+ shift 2
26
+ ;;
27
+ --api-pass)
28
+ API_PASS="$2"
29
+ shift 2
30
+ ;;
31
+ *)
32
+ shift
33
+ ;;
34
+ esac
35
+ done
36
+
37
+ if [ -z "$CONNECTOR" ]; then
38
+ echo '{"error": "connector is required. Use --connector CONNECTOR_NAME"}'
39
+ exit 1
40
+ fi
41
+
42
+ # Normalize connector name (lowercase, underscores)
43
+ CONNECTOR=$(echo "$CONNECTOR" | tr '[:upper:]' '[:lower:]' | tr '-' '_' | tr ' ' '_')
44
+
45
+ # Get config map for the connector
46
+ CONFIG_MAP=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/connectors/$CONNECTOR/config-map")
47
+
48
+ # Check for error
49
+ if echo "$CONFIG_MAP" | jq -e '.detail' > /dev/null 2>&1; then
50
+ echo "{\"error\": \"Connector '$CONNECTOR' not found\", \"detail\": $CONFIG_MAP}"
51
+ exit 1
52
+ fi
53
+
54
+ # Extract field names and build example credentials
55
+ FIELD_NAMES=$(echo "$CONFIG_MAP" | jq -r 'keys[]')
56
+ EXAMPLE_CREDS=$(echo "$CONFIG_MAP" | jq 'to_entries | map({(.key): "your_\(.key)"}) | add')
57
+
58
+ # Output result
59
+ cat << EOF
60
+ {
61
+ "connector": "$CONNECTOR",
62
+ "required_fields": $(echo "$CONFIG_MAP" | jq -c 'keys'),
63
+ "field_details": $CONFIG_MAP,
64
+ "example_credentials": $EXAMPLE_CREDS,
65
+ "documentation_hint": "Generate API keys from the exchange's API management page"
66
+ }
67
+ EOF
@@ -0,0 +1,82 @@
1
+ #!/bin/bash
2
+ # List credentials configured for an account
3
+ # Usage: ./list_account_credentials.sh [--account ACCOUNT]
4
+
5
+ set -e
6
+
7
+ API_URL="${API_URL:-http://localhost:8000}"
8
+ API_USER="${API_USER:-admin}"
9
+ API_PASS="${API_PASS:-admin}"
10
+ ACCOUNT=""
11
+
12
+ # Parse arguments
13
+ while [[ $# -gt 0 ]]; do
14
+ case $1 in
15
+ --account)
16
+ ACCOUNT="$2"
17
+ shift 2
18
+ ;;
19
+ --api-url)
20
+ API_URL="$2"
21
+ shift 2
22
+ ;;
23
+ --api-user)
24
+ API_USER="$2"
25
+ shift 2
26
+ ;;
27
+ --api-pass)
28
+ API_PASS="$2"
29
+ shift 2
30
+ ;;
31
+ *)
32
+ shift
33
+ ;;
34
+ esac
35
+ done
36
+
37
+ # If no account specified, list all accounts and their credentials
38
+ if [ -z "$ACCOUNT" ]; then
39
+ ACCOUNTS=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/")
40
+
41
+ RESULT="{"
42
+ FIRST=true
43
+
44
+ for account in $(echo "$ACCOUNTS" | jq -r '.[]'); do
45
+ CREDS=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/$account/credentials")
46
+
47
+ if [ "$FIRST" = true ]; then
48
+ FIRST=false
49
+ else
50
+ RESULT+=","
51
+ fi
52
+
53
+ RESULT+="\"$account\": {\"connectors\": $CREDS, \"count\": $(echo "$CREDS" | jq 'length')}"
54
+ done
55
+
56
+ RESULT+="}"
57
+
58
+ cat << EOF
59
+ {
60
+ "accounts": $ACCOUNTS,
61
+ "total_accounts": $(echo "$ACCOUNTS" | jq 'length'),
62
+ "credentials_by_account": $RESULT
63
+ }
64
+ EOF
65
+ else
66
+ # Get credentials for specific account
67
+ CREDS=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/$ACCOUNT/credentials")
68
+
69
+ # Check for error
70
+ if echo "$CREDS" | jq -e '.detail' > /dev/null 2>&1; then
71
+ echo "{\"error\": \"Account '$ACCOUNT' not found\", \"detail\": $CREDS}"
72
+ exit 1
73
+ fi
74
+
75
+ cat << EOF
76
+ {
77
+ "account": "$ACCOUNT",
78
+ "connectors": $CREDS,
79
+ "count": $(echo "$CREDS" | jq 'length')
80
+ }
81
+ EOF
82
+ fi
@@ -0,0 +1,64 @@
1
+ #!/bin/bash
2
+ # List all available exchange connectors and current account credentials
3
+ # Usage: ./list_connectors.sh [--api-url URL] [--api-user USERNAME] [--api-pass PASSWORD]
4
+
5
+ set -e
6
+
7
+ API_URL="${API_URL:-http://localhost:8000}"
8
+ API_USER="${API_USER:-admin}"
9
+ API_PASS="${API_PASS:-admin}"
10
+
11
+ # Parse arguments
12
+ while [[ $# -gt 0 ]]; do
13
+ case $1 in
14
+ --api-url)
15
+ API_URL="$2"
16
+ shift 2
17
+ ;;
18
+ --api-user)
19
+ API_USER="$2"
20
+ shift 2
21
+ ;;
22
+ --api-pass)
23
+ API_PASS="$2"
24
+ shift 2
25
+ ;;
26
+ *)
27
+ shift
28
+ ;;
29
+ esac
30
+ done
31
+
32
+ # Get list of available connectors
33
+ CONNECTORS=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/connectors/")
34
+
35
+ # Get list of accounts
36
+ ACCOUNTS=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/")
37
+
38
+ # Get credentials for each account
39
+ ACCOUNT_CREDENTIALS="{"
40
+ FIRST_ACCOUNT=true
41
+
42
+ for account in $(echo "$ACCOUNTS" | jq -r '.[]'); do
43
+ CREDS=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/$account/credentials")
44
+
45
+ if [ "$FIRST_ACCOUNT" = true ]; then
46
+ FIRST_ACCOUNT=false
47
+ else
48
+ ACCOUNT_CREDENTIALS+=","
49
+ fi
50
+
51
+ ACCOUNT_CREDENTIALS+="\"$account\": $CREDS"
52
+ done
53
+
54
+ ACCOUNT_CREDENTIALS+="}"
55
+
56
+ # Output combined result
57
+ cat << EOF
58
+ {
59
+ "available_connectors": $CONNECTORS,
60
+ "total_connectors": $(echo "$CONNECTORS" | jq 'length'),
61
+ "accounts": $ACCOUNTS,
62
+ "configured_credentials": $ACCOUNT_CREDENTIALS
63
+ }
64
+ EOF
@@ -0,0 +1,79 @@
1
+ #!/bin/bash
2
+ # Remove exchange credentials from an account
3
+ # Usage: ./remove_credentials.sh --connector CONNECTOR [--account ACCOUNT]
4
+
5
+ set -e
6
+
7
+ API_URL="${API_URL:-http://localhost:8000}"
8
+ API_USER="${API_USER:-admin}"
9
+ API_PASS="${API_PASS:-admin}"
10
+ CONNECTOR=""
11
+ ACCOUNT="master_account"
12
+
13
+ # Parse arguments
14
+ while [[ $# -gt 0 ]]; do
15
+ case $1 in
16
+ --connector)
17
+ CONNECTOR="$2"
18
+ shift 2
19
+ ;;
20
+ --account)
21
+ ACCOUNT="$2"
22
+ shift 2
23
+ ;;
24
+ --api-url)
25
+ API_URL="$2"
26
+ shift 2
27
+ ;;
28
+ --api-user)
29
+ API_USER="$2"
30
+ shift 2
31
+ ;;
32
+ --api-pass)
33
+ API_PASS="$2"
34
+ shift 2
35
+ ;;
36
+ *)
37
+ shift
38
+ ;;
39
+ esac
40
+ done
41
+
42
+ # Validate required arguments
43
+ if [ -z "$CONNECTOR" ]; then
44
+ echo '{"error": "connector is required. Use --connector CONNECTOR_NAME"}'
45
+ exit 1
46
+ fi
47
+
48
+ # Normalize connector name
49
+ CONNECTOR=$(echo "$CONNECTOR" | tr '[:upper:]' '[:lower:]' | tr '-' '_' | tr ' ' '_')
50
+
51
+ # Check if credentials exist
52
+ EXISTING=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/$ACCOUNT/credentials")
53
+ if ! echo "$EXISTING" | jq -e "index(\"$CONNECTOR\")" > /dev/null 2>&1; then
54
+ cat << EOF
55
+ {
56
+ "error": "Credentials for '$CONNECTOR' do not exist on account '$ACCOUNT'",
57
+ "existing_connectors": $EXISTING
58
+ }
59
+ EOF
60
+ exit 1
61
+ fi
62
+
63
+ # Remove credentials via API
64
+ RESPONSE=$(curl -s -X DELETE \
65
+ -u "$API_USER:$API_PASS" \
66
+ "$API_URL/accounts/$ACCOUNT/credentials/$CONNECTOR")
67
+
68
+ # Verify credentials were removed
69
+ UPDATED=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/$ACCOUNT/credentials")
70
+
71
+ cat << EOF
72
+ {
73
+ "status": "success",
74
+ "action": "credentials_removed",
75
+ "connector": "$CONNECTOR",
76
+ "account": "$ACCOUNT",
77
+ "remaining_connectors": $UPDATED
78
+ }
79
+ EOF
@@ -0,0 +1,214 @@
1
+ #!/bin/bash
2
+ # Setup exchange connector with progressive disclosure
3
+ #
4
+ # Flow:
5
+ # 1. No parameters → List available exchanges and current accounts
6
+ # 2. --connector only → Show required credential fields
7
+ # 3. --connector + --credentials → Select account (shows available accounts)
8
+ # 4. --connector + --credentials + --account → Connect (with --force for override)
9
+ #
10
+ # Usage:
11
+ # ./setup_connector.sh # Step 1: List exchanges
12
+ # ./setup_connector.sh --connector binance # Step 2: Show required fields
13
+ # ./setup_connector.sh --connector binance --credentials '{"api_key":"...","secret_key":"..."}' # Step 3: Select account
14
+ # ./setup_connector.sh --connector binance --credentials '{"api_key":"...","secret_key":"..."}' --account master_account # Step 4: Connect
15
+
16
+ set -e
17
+
18
+ API_URL="${API_URL:-http://localhost:8000}"
19
+ API_USER="${API_USER:-admin}"
20
+ API_PASS="${API_PASS:-admin}"
21
+ CONNECTOR=""
22
+ CREDENTIALS=""
23
+ ACCOUNT=""
24
+ FORCE=false
25
+
26
+ # Parse arguments
27
+ while [[ $# -gt 0 ]]; do
28
+ case $1 in
29
+ --connector) CONNECTOR="$2"; shift 2 ;;
30
+ --credentials) CREDENTIALS="$2"; shift 2 ;;
31
+ --account) ACCOUNT="$2"; shift 2 ;;
32
+ --force) FORCE=true; shift ;;
33
+ --api-url) API_URL="$2"; shift 2 ;;
34
+ --api-user) API_USER="$2"; shift 2 ;;
35
+ --api-pass) API_PASS="$2"; shift 2 ;;
36
+ *) shift ;;
37
+ esac
38
+ done
39
+
40
+ # Normalize connector name if provided
41
+ if [ -n "$CONNECTOR" ]; then
42
+ CONNECTOR=$(echo "$CONNECTOR" | tr '[:upper:]' '[:lower:]' | tr '-' '_' | tr ' ' '_')
43
+ fi
44
+
45
+ # Determine flow stage
46
+ if [ -z "$CONNECTOR" ]; then
47
+ STAGE="list_exchanges"
48
+ elif [ -z "$CREDENTIALS" ]; then
49
+ STAGE="show_config"
50
+ elif [ -z "$ACCOUNT" ]; then
51
+ STAGE="select_account"
52
+ else
53
+ STAGE="connect"
54
+ fi
55
+
56
+ case "$STAGE" in
57
+ list_exchanges)
58
+ # Step 1: List available connectors and current account status
59
+ CONNECTORS=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/connectors/")
60
+ ACCOUNTS=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/")
61
+
62
+ # Get credentials for each account
63
+ ACCOUNT_STATUS="{"
64
+ FIRST=true
65
+ for account in $(echo "$ACCOUNTS" | jq -r '.[]'); do
66
+ CREDS=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/$account/credentials")
67
+ if [ "$FIRST" = true ]; then
68
+ FIRST=false
69
+ else
70
+ ACCOUNT_STATUS+=","
71
+ fi
72
+ ACCOUNT_STATUS+="\"$account\": $CREDS"
73
+ done
74
+ ACCOUNT_STATUS+="}"
75
+
76
+ cat << EOF
77
+ {
78
+ "action": "list_exchanges",
79
+ "message": "Available exchange connectors. Select one to see required credentials.",
80
+ "connectors": $CONNECTORS,
81
+ "total_connectors": $(echo "$CONNECTORS" | jq 'length'),
82
+ "current_accounts": $ACCOUNT_STATUS,
83
+ "next_step": "Call again with --connector CONNECTOR_NAME to see required credential fields",
84
+ "example": "./setup_connector.sh --connector binance"
85
+ }
86
+ EOF
87
+ ;;
88
+
89
+ show_config)
90
+ # Step 2: Show required credential fields for the connector
91
+ CONFIG_MAP=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/connectors/$CONNECTOR/config-map")
92
+
93
+ if echo "$CONFIG_MAP" | jq -e '.detail' > /dev/null 2>&1; then
94
+ echo "{\"error\": \"Connector '$CONNECTOR' not found\", \"detail\": $CONFIG_MAP}"
95
+ exit 1
96
+ fi
97
+
98
+ # Build example credentials from config map (use -c for compact output)
99
+ EXAMPLE_CREDS=$(echo "$CONFIG_MAP" | jq -c 'to_entries | map({(.key): "your_\(.key)"}) | add')
100
+ REQUIRED_FIELDS=$(echo "$CONFIG_MAP" | jq -c '[to_entries[] | select(.value.required == true) | .key]')
101
+ OPTIONAL_FIELDS=$(echo "$CONFIG_MAP" | jq -c '[to_entries[] | select(.value.required != true) | .key]')
102
+ FIELD_DETAILS=$(echo "$CONFIG_MAP" | jq -c '.')
103
+
104
+ # Escape the example credentials for the command example
105
+ EXAMPLE_CREDS_ESCAPED=$(echo "$EXAMPLE_CREDS" | sed 's/"/\\"/g')
106
+
107
+ cat << EOF
108
+ {
109
+ "action": "show_config",
110
+ "message": "Required credentials for $CONNECTOR. Provide these to continue setup.",
111
+ "connector": "$CONNECTOR",
112
+ "required_fields": $REQUIRED_FIELDS,
113
+ "optional_fields": $OPTIONAL_FIELDS,
114
+ "field_details": $FIELD_DETAILS,
115
+ "example_credentials": $EXAMPLE_CREDS,
116
+ "next_step": "Call again with --credentials JSON to select an account",
117
+ "example": "./setup_connector.sh --connector $CONNECTOR --credentials '$EXAMPLE_CREDS_ESCAPED'"
118
+ }
119
+ EOF
120
+ ;;
121
+
122
+ select_account)
123
+ # Step 3: Show available accounts to select from
124
+ ACCOUNTS=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/")
125
+
126
+ # Check which accounts already have this connector
127
+ ACCOUNT_STATUS="["
128
+ FIRST=true
129
+ for account in $(echo "$ACCOUNTS" | jq -r '.[]'); do
130
+ CREDS=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/$account/credentials")
131
+ HAS_CONNECTOR=$(echo "$CREDS" | jq -e "index(\"$CONNECTOR\")" > /dev/null 2>&1 && echo "true" || echo "false")
132
+
133
+ if [ "$FIRST" = true ]; then
134
+ FIRST=false
135
+ else
136
+ ACCOUNT_STATUS+=","
137
+ fi
138
+ ACCOUNT_STATUS+="{\"account\": \"$account\", \"has_$CONNECTOR\": $HAS_CONNECTOR}"
139
+ done
140
+ ACCOUNT_STATUS+="]"
141
+
142
+ cat << EOF
143
+ {
144
+ "action": "select_account",
145
+ "message": "Ready to connect $CONNECTOR. Select an account to add credentials to.",
146
+ "connector": "$CONNECTOR",
147
+ "credentials_provided": true,
148
+ "accounts": $ACCOUNT_STATUS,
149
+ "default_account": "master_account",
150
+ "next_step": "Call again with --account ACCOUNT_NAME to complete setup",
151
+ "example": "./setup_connector.sh --connector $CONNECTOR --credentials '...' --account master_account",
152
+ "note": "Use --force to override if connector already exists on the account"
153
+ }
154
+ EOF
155
+ ;;
156
+
157
+ connect)
158
+ # Step 4: Actually connect the exchange
159
+
160
+ # Check if credentials already exist
161
+ EXISTING=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/$ACCOUNT/credentials")
162
+ HAS_CONNECTOR=$(echo "$EXISTING" | jq -e "index(\"$CONNECTOR\")" > /dev/null 2>&1 && echo "true" || echo "false")
163
+
164
+ if [ "$HAS_CONNECTOR" = "true" ] && [ "$FORCE" = "false" ]; then
165
+ cat << EOF
166
+ {
167
+ "action": "requires_confirmation",
168
+ "message": "WARNING: Connector '$CONNECTOR' already exists for account '$ACCOUNT'",
169
+ "account": "$ACCOUNT",
170
+ "connector": "$CONNECTOR",
171
+ "existing_connectors": $EXISTING,
172
+ "warning": "Adding credentials will override the existing connector configuration",
173
+ "next_step": "Add --force to override existing credentials",
174
+ "example": "./setup_connector.sh --connector $CONNECTOR --credentials '...' --account $ACCOUNT --force"
175
+ }
176
+ EOF
177
+ exit 0
178
+ fi
179
+
180
+ # Add credentials via API
181
+ RESPONSE=$(curl -s -X POST \
182
+ -u "$API_USER:$API_PASS" \
183
+ -H "Content-Type: application/json" \
184
+ -d "{\"connector_name\": \"$CONNECTOR\", \"credentials\": $CREDENTIALS}" \
185
+ "$API_URL/accounts/$ACCOUNT/credentials")
186
+
187
+ if echo "$RESPONSE" | jq -e '.detail' > /dev/null 2>&1; then
188
+ echo "{\"error\": \"Failed to add credentials\", \"detail\": $RESPONSE}"
189
+ exit 1
190
+ fi
191
+
192
+ # Verify credentials were added
193
+ UPDATED=$(curl -s -u "$API_USER:$API_PASS" "$API_URL/accounts/$ACCOUNT/credentials")
194
+
195
+ ACTION_TYPE="credentials_added"
196
+ MESSAGE_ACTION="connected"
197
+ if [ "$HAS_CONNECTOR" = "true" ]; then
198
+ ACTION_TYPE="credentials_overridden"
199
+ MESSAGE_ACTION="updated"
200
+ fi
201
+
202
+ cat << EOF
203
+ {
204
+ "action": "$ACTION_TYPE",
205
+ "message": "Successfully $MESSAGE_ACTION $CONNECTOR exchange to account $ACCOUNT",
206
+ "account": "$ACCOUNT",
207
+ "connector": "$CONNECTOR",
208
+ "was_override": $HAS_CONNECTOR,
209
+ "configured_connectors": $UPDATED,
210
+ "next_step": "Exchange is now ready for trading. Use get_portfolio_overview to verify the connection."
211
+ }
212
+ EOF
213
+ ;;
214
+ esac