@adaptic/utils 0.0.361 → 0.0.363

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.mjs CHANGED
@@ -1061,16 +1061,18 @@ async function makeRequest(auth, params) {
1061
1061
  fetchOptions.body = JSON.stringify(body);
1062
1062
  }
1063
1063
  const response = await fetch(url, fetchOptions);
1064
- if (!response.ok) {
1065
- const errorText = await response.text();
1066
- console.error(`Alpaca API error (${response.status}): ${errorText}`, {
1067
- account: auth.adapticAccountId || 'direct',
1068
- source: 'AlpacaAPI',
1069
- type: 'error'
1070
- });
1071
- throw new Error(`Alpaca API error (${response.status}): ${errorText}`);
1064
+ // Handle 207 Multi-Status responses (used by closeAll positions)
1065
+ if (response.status === 207 || response.ok) {
1066
+ return await response.json();
1072
1067
  }
1073
- return await response.json();
1068
+ // Handle errors
1069
+ const errorText = await response.text();
1070
+ console.error(`Alpaca API error (${response.status}): ${errorText}`, {
1071
+ account: auth.adapticAccountId || 'direct',
1072
+ source: 'AlpacaAPI',
1073
+ type: 'error'
1074
+ });
1075
+ throw new Error(`Alpaca API error (${response.status}): ${errorText}`);
1074
1076
  }
1075
1077
  catch (err) {
1076
1078
  const error = err;
@@ -1218,9 +1220,10 @@ async function closeAllPositions(auth, params = { cancel_orders: true, useLimitO
1218
1220
  }
1219
1221
  }
1220
1222
  else {
1221
- await makeRequest(auth, {
1223
+ const response = await makeRequest(auth, {
1222
1224
  endpoint: '/v2/positions', method: 'DELETE', queryString: cancel_orders ? '?cancel_orders=true' : ''
1223
1225
  });
1226
+ return response;
1224
1227
  }
1225
1228
  }
1226
1229
  /**