Skip to content

Conversation

dboyliao
Copy link
Collaborator

  • refactor channel bridging logic
    • handle the bridging on connection
  • fix message handling
    • emit proper bbgo events
  • update tests

@dboyliao dboyliao force-pushed the dboy/refactor-bridge-channel branch from 9802a9f to 4dc1d4e Compare March 24, 2025 06:49
@dboyliao dboyliao force-pushed the dboy/refactor-bridge-channel branch from 0676901 to cbcb027 Compare March 24, 2025 07:49
userOrderOnly bool
bbgoChannelsOnly bool
authEnabled bool
subLocalChannelsMap map[types.Channel]struct{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locking the map is necessary to prevent race conditions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update the map only in the body of OnConnect.
After that, I'll only read from the map.
So I think it's not necessary to add a lock here.

Comment on lines 124 to 144
switch types.Channel(channel) {
switch channel {
case rfqMatchChannel:
subType = "subscriptions"
default:
subType = "subscribe"
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider:

subType = "subscribe"
if channel == rfqMatchChannel {
    subType = "subscriptions"
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

case rfqMatchChannel:
subType = "subscriptions"
default:
subType = "subscribe"
}
var subCmd any
switch types.Channel(channel) {
switch channel {
case statusChannel:
subCmd = subscribeMsgType1{
Type: subType,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I handle the authentication here.

@@ -300,7 +318,13 @@ func (s *Stream) handleMatchMessage(msg *MatchMessage) {
return
}
trade := msg.Trade()
s.EmitTradeUpdate(trade)
if _, fullExist := s.subLocalChannelsMap[fullChannel]; fullExist {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use isPublicOnly

Copy link
Collaborator Author

@dboyliao dboyliao Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want it to be more explicit.
Though PublicOnly == true does imply fullExist.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a second thought, I think you are right.
The logic is simpler to check on .PublicOnly.
It's fixed.

@dboyliao dboyliao requested review from c9s and bailantaotao March 24, 2025 08:06
@@ -79,11 +80,11 @@ func Test_OrdersAPI(t *testing.T) {
break
}
time.Sleep(time.Millisecond * 500)
order, err = ex.QueryOrder(ctx, types.OrderQuery{Symbol: "ETHUSD", OrderID: order.UUID, ClientOrderID: order.UUID})
order, err = ex.QueryOrder(ctx, types.OrderQuery{Symbol: symbol, OrderID: order.UUID, ClientOrderID: order.UUID})
assert.NoError(t, err)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert "order" is not nil?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// full: all orders/trades on Coinbase Exchange
// user: orders/trades belong to the user
var localChannel types.Channel
if s.PublicOnly {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MarketTradeChannel is only available in the publicOnly mode

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dboyliao dboyliao force-pushed the dboy/refactor-bridge-channel branch from 8214d8f to c549032 Compare March 25, 2025 04:32
@dboyliao dboyliao requested a review from c9s March 25, 2025 05:39
@dboyliao dboyliao force-pushed the dboy/refactor-bridge-channel branch from c549032 to c99eb16 Compare March 27, 2025 02:13
@dboyliao dboyliao force-pushed the dboy/refactor-bridge-channel branch from c99eb16 to 3ff403f Compare March 27, 2025 08:52
@dboyliao dboyliao force-pushed the dboy/refactor-bridge-channel branch from d6b68b3 to ee9867f Compare March 27, 2025 13:05
@dboyliao dboyliao enabled auto-merge March 27, 2025 13:06
@dboyliao dboyliao merged commit 7d860a1 into main Mar 27, 2025
3 checks passed
@dboyliao dboyliao deleted the dboy/refactor-bridge-channel branch March 27, 2025 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants