@@ -47,6 +47,14 @@ type LargeAmountAlertConfig struct {
4747 Amount fixedpoint.Value `json:"amount"`
4848}
4949
50+ type InterativeOrderConfig struct {
51+ Enabled bool `json:"enabled"`
52+ // Delay is the delay duration for interactive order confirmation in Slack
53+ Delay types.Duration `json:"delay"`
54+ // MinAmount is the minimum amount required for interactive order confirmation in Slack
55+ MinAmount fixedpoint.Value `json:"minAmount"`
56+ }
57+
5058type Strategy struct {
5159 * bbgo.Environment
5260 ActiveTransferInterval types.Duration `json:"interval"` // keep the same tag name for backward compatibility
@@ -60,11 +68,9 @@ type Strategy struct {
6068 Duration types.Duration `json:"for"`
6169 InstantAlignAmount fixedpoint.Value `json:"instantAlignAmount"`
6270 Disabled bool `json:"disabled"`
63- // InteractiveOrderDelay is the delay duration for interactive order confirmation in Slack
64- InteractiveOrderDelay types.Duration `json:"interactiveOrderDelay"`
65- // InteractiveOrderEnabled enables interactive order confirmation in Slack
66- InteractiveOrderEnabled bool `json:"interactiveOrderEnabled"`
67- // isInteractiveOrderEnabled is true iff InteractiveOrderEnabled = true and the interactive order dispatcher is available
71+
72+ InterativeOrderConfig * InterativeOrderConfig `json:"interactiveOrder,omitempty"`
73+ // isInteractiveOrderEnabled is a internal flag to indicate if interactive order is enabled
6874 isInteractiveOrderEnabled bool
6975
7076 WarningDuration types.Duration `json:"warningFor"`
@@ -149,8 +155,12 @@ func (s *Strategy) Defaults() error {
149155 s .InstantAlignAmount = fixedpoint .NewFromFloat (50.0 )
150156 }
151157
152- if s .InteractiveOrderDelay == 0 {
153- s .InteractiveOrderDelay = types .Duration (5 * time .Minute )
158+ if s .InterativeOrderConfig == nil {
159+ s .InterativeOrderConfig = & InterativeOrderConfig {
160+ Enabled : false ,
161+ Delay : types .Duration (5 * time .Minute ),
162+ MinAmount : s .InstantAlignAmount ,
163+ }
154164 }
155165
156166 return nil
@@ -455,7 +465,7 @@ func (s *Strategy) CrossRun(
455465 dispatcher , err := interact .GetDispatcher ()
456466 if err != nil {
457467 bbgo .Notify ("[xalign] interactive order is not enabled: %s" , err .Error ())
458- } else if s .InteractiveOrderEnabled {
468+ } else if s .InterativeOrderConfig . Enabled {
459469 s .isInteractiveOrderEnabled = true
460470 bbgo .Notify ("[xalign] interactive order is enabled: %s" , s .InstanceID ())
461471 setupSlackInteractionCallback (s .slackEvtID , dispatcher )
@@ -758,13 +768,19 @@ func (s *Strategy) align(ctx context.Context, sessions bbgo.ExchangeSessionMap)
758768 if s .DryRun {
759769 return activeTransferExists
760770 }
771+
772+ // place the order immediately if one of the conditions met:
773+ // 1. the amount is small enough (<= InstantAlignAmount)
774+ // 2. interactive order is not enabled
761775 if isInstantAmount || ! s .isInteractiveOrderEnabled {
762- // place the order immediately if one of the conditions met:
763- // 1. the amount is small enough (<= InstantAlignAmount)
764- // 2. interactive order is not enabled
765776 createdOrder , err := selectedSession .Exchange .SubmitOrder (ctx , * submitOrder )
766777 s .onSubmittedOrderCallback (selectedSession , submitOrder , createdOrder , err )
767- } else {
778+ // continue to the next currency
779+ continue
780+ }
781+
782+ // check if we need to place interactive order
783+ if amount .Compare (s .InterativeOrderConfig .MinAmount ) >= 0 {
768784 // submit the order via interactive order with slack confirmation
769785 // first we check if there is already a delayed interactive order for the same symbol and slack event ID
770786 foundDelayedOrder := false
@@ -790,11 +806,14 @@ func (s *Strategy) align(ctx context.Context, sessions bbgo.ExchangeSessionMap)
790806 }
791807 itOrder := NewInteractiveSubmitOrder (
792808 * submitOrder ,
793- s .InteractiveOrderDelay .Duration (),
809+ s .InterativeOrderConfig . Delay .Duration (),
794810 mentions ,
795811 s .slackEvtID ,
796812 )
797813 itOrder .AsyncSubmit (ctx , selectedSession , s .onSubmittedOrderCallback )
814+ } else {
815+ createdOrder , err := selectedSession .Exchange .SubmitOrder (ctx , * submitOrder )
816+ s .onSubmittedOrderCallback (selectedSession , submitOrder , createdOrder , err )
798817 }
799818 }
800819 }
0 commit comments