@adaptic/utils 0.0.360 → 0.0.362

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/dist/index.cjs CHANGED
@@ -1083,16 +1083,18 @@ async function makeRequest(auth, params) {
1083
1083
  fetchOptions.body = JSON.stringify(body);
1084
1084
  }
1085
1085
  const response = await fetch(url, fetchOptions);
1086
- if (!response.ok) {
1087
- const errorText = await response.text();
1088
- console.error(`Alpaca API error (${response.status}): ${errorText}`, {
1089
- account: auth.adapticAccountId || 'direct',
1090
- source: 'AlpacaAPI',
1091
- type: 'error'
1092
- });
1093
- throw new Error(`Alpaca API error (${response.status}): ${errorText}`);
1086
+ // Handle 207 Multi-Status responses (used by closeAll positions)
1087
+ if (response.status === 207 || response.ok) {
1088
+ return await response.json();
1094
1089
  }
1095
- return await response.json();
1090
+ // Handle errors
1091
+ const errorText = await response.text();
1092
+ console.error(`Alpaca API error (${response.status}): ${errorText}`, {
1093
+ account: auth.adapticAccountId || 'direct',
1094
+ source: 'AlpacaAPI',
1095
+ type: 'error'
1096
+ });
1097
+ throw new Error(`Alpaca API error (${response.status}): ${errorText}`);
1096
1098
  }
1097
1099
  catch (err) {
1098
1100
  const error = err;
@@ -1240,9 +1242,10 @@ async function closeAllPositions(auth, params = { cancel_orders: true, useLimitO
1240
1242
  }
1241
1243
  }
1242
1244
  else {
1243
- await makeRequest(auth, {
1245
+ const response = await makeRequest(auth, {
1244
1246
  endpoint: '/v2/positions', method: 'DELETE', queryString: cancel_orders ? '?cancel_orders=true' : ''
1245
1247
  });
1248
+ return response;
1246
1249
  }
1247
1250
  }
1248
1251
  /**