Open
Conversation
In Bitget one-way position mode (buy_single/sell_single): - sell_single can be either open_short (profit=0) or close_long (profit!=0) - buy_single can be either open_long (profit=0) or close_short (profit!=0) The previous logic incorrectly mapped sell_single → close_long always, which caused new short positions to be misidentified as closing long trades. This fix uses the profit field to distinguish: - profit != 0: closing trade (has realized PnL) - profit == 0: opening trade (no realized PnL yet) Fixes issue where ETH short positions were not recorded to database.
In Bitget one-way position mode, positions are stored with side='BOTH' instead of LONG/SHORT. The GetOpenPositionBySymbol function only matched exact side values, causing it to fail when trying to find positions to close. This fix updates the query to match both the specified side and 'BOTH': (side = ? OR side = 'BOTH') This ensures positions in one-way mode can be found and properly closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
📝 Description
Fix critical bug in Bitget exchange integration where short positions were not being recorded to the database.
Root Cause: In Bitget one-way position mode, the OrderSync logic incorrectly mapped
sell_singletrades toclose_longaction always. This caused:Solution: Use the
profitfield to distinguish between opening and closing trades:profit != 0: closing trade (has realized PnL)profit == 0: opening trade (no realized PnL yet)Also fixed
GetOpenPositionBySymbolto match both exact side andBOTHside (used in one-way mode).Verification: ETH short position opened at 22:46 is now correctly recorded:
🎯 Type of Change
🔗 Related Issues
📋 Changes Made
order_sync.go - Fix trade action detection
GetTrades()to useprofitfield for distinguishing open/close tradessell_singlenow correctly maps toopen_shortwhenprofit == 0buy_singlenow correctly maps toopen_longwhenprofit == 0store/position.go- Fix position lookup for one-way modeGetOpenPositionBySymbol()to match both exact side andBOTHsideside='BOTH'but need to be found when searching for specific directions(side = ? OR side = 'BOTH')🧪 Testing
trader_positionstable✅ Checklist
Code Quality
Documentation
Git
fix: ...)devbranch📚 Additional Notes
This fix addresses a critical data integrity issue where positions opened via Bitget were not persisted to the local database. The system would show positions as open in memory/Bitget API but they would be missing from the database, causing:
The fix has been tested with actual ETH short position and verified in the database.
By submitting this PR, I confirm:
🌟 Thank you for your contribution!