Skip to content

Commit

Permalink
test: api timeout handling for plugin-binance (#2504)
Browse files Browse the repository at this point in the history
* test: api timeout handling for plugin-binance

* test: api timeout handling for plugin-binance - PR feedback

---------

Co-authored-by: Sayo <hi@sayo.wtf>
  • Loading branch information
ai16z-demirix and wtfsayo authored Jan 19, 2025
1 parent f8bfefe commit 3206ef4
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion packages/plugin-binance/__tests__/trade.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { TradeService } from '../src/services/trade';
import { AuthenticationError, InvalidSymbolError, MinNotionalError } from '../src/types/internal/error';
import { AuthenticationError, InvalidSymbolError, MinNotionalError, ApiError } from '../src/types/internal/error';
import { ORDER_TYPES, TIME_IN_FORCE } from '../src/constants/api';

// Mock the Binance client
Expand Down Expand Up @@ -207,5 +207,31 @@ describe('TradeService', () => {
// price is missing
})).rejects.toThrow('Price is required for LIMIT orders');
});

it('should handle API timeout', async () => {
// Mock successful exchange info response first
mockExchangeInfo.mockResolvedValueOnce(mockExchangeInfoResponse);

// Mock order request to timeout
mockNewOrder.mockImplementationOnce(() =>
Promise.reject(new ApiError('Request timed out', -1001))
);

const service = new TradeService({
apiKey: 'test',
secretKey: 'test',
timeout: 100 // Lower timeout as we're mocking the error
});

await expect(() => service.executeTrade({
symbol: 'BTCUSDT',
side: 'BUY',
type: ORDER_TYPES.MARKET,
quantity: 1
})).rejects.toMatchObject({
message: 'Request timed out',
code: -1001
});
});
});
});

0 comments on commit 3206ef4

Please # to comment.