@@ -29,29 +29,34 @@ type MarketDataStream struct {
2929 subs subscriptions
3030}
3131
32+ type candleSub struct {
33+ interval pb.SubscriptionInterval
34+ waitingClose bool
35+ }
36+
3237type subscriptions struct {
33- candles map [string ]pb. SubscriptionInterval
38+ candles map [string ]candleSub
3439 orderBooks map [string ]int32
3540 trades map [string ]struct {}
3641 tradingStatuses map [string ]struct {}
3742 lastPrices map [string ]struct {}
3843}
3944
4045// SubscribeCandle - Метод подписки на свечи с заданным интервалом
41- func (mds * MarketDataStream ) SubscribeCandle (ids []string , interval pb.SubscriptionInterval ) (<- chan * pb.Candle , error ) {
42- err := mds .sendCandlesReq (ids , interval , pb .SubscriptionAction_SUBSCRIPTION_ACTION_SUBSCRIBE )
46+ func (mds * MarketDataStream ) SubscribeCandle (ids []string , interval pb.SubscriptionInterval , waitingClose bool ) (<- chan * pb.Candle , error ) {
47+ err := mds .sendCandlesReq (ids , interval , pb .SubscriptionAction_SUBSCRIPTION_ACTION_SUBSCRIBE , waitingClose )
4348 if err != nil {
4449 return nil , err
4550 }
4651 for _ , id := range ids {
47- mds .subs .candles [id ] = interval
52+ mds .subs .candles [id ] = candleSub { interval : interval , waitingClose : waitingClose }
4853 }
4954 return mds .candle , nil
5055}
5156
5257// UnSubscribeCandle - Метод отписки от свечей
53- func (mds * MarketDataStream ) UnSubscribeCandle (ids []string , interval pb.SubscriptionInterval ) error {
54- err := mds .sendCandlesReq (ids , interval , pb .SubscriptionAction_SUBSCRIPTION_ACTION_UNSUBSCRIBE )
58+ func (mds * MarketDataStream ) UnSubscribeCandle (ids []string , interval pb.SubscriptionInterval , waitingClose bool ) error {
59+ err := mds .sendCandlesReq (ids , interval , pb .SubscriptionAction_SUBSCRIPTION_ACTION_UNSUBSCRIBE , waitingClose )
5560 if err != nil {
5661 return err
5762 }
@@ -61,7 +66,7 @@ func (mds *MarketDataStream) UnSubscribeCandle(ids []string, interval pb.Subscri
6166 return nil
6267}
6368
64- func (mds * MarketDataStream ) sendCandlesReq (ids []string , interval pb.SubscriptionInterval , act pb.SubscriptionAction ) error {
69+ func (mds * MarketDataStream ) sendCandlesReq (ids []string , interval pb.SubscriptionInterval , act pb.SubscriptionAction , waitingClose bool ) error {
6570 instruments := make ([]* pb.CandleInstrument , 0 , len (ids ))
6671 for _ , id := range ids {
6772 instruments = append (instruments , & pb.CandleInstrument {
@@ -70,14 +75,12 @@ func (mds *MarketDataStream) sendCandlesReq(ids []string, interval pb.Subscripti
7075 })
7176 }
7277
73- WCFlag := interval == pb .SubscriptionInterval_SUBSCRIPTION_INTERVAL_ONE_MINUTE
74-
7578 return mds .stream .Send (& pb.MarketDataRequest {
7679 Payload : & pb.MarketDataRequest_SubscribeCandlesRequest {
7780 SubscribeCandlesRequest : & pb.SubscribeCandlesRequest {
7881 SubscriptionAction : act ,
7982 Instruments : instruments ,
80- WaitingClose : WCFlag ,
83+ WaitingClose : waitingClose ,
8184 }}})
8285}
8386
@@ -307,14 +310,14 @@ func (mds *MarketDataStream) Stop() {
307310func (mds * MarketDataStream ) UnSubscribeAll () error {
308311 ids := make ([]string , 0 )
309312 if len (mds .subs .candles ) > 0 {
310- intervals := make (map [pb. SubscriptionInterval ][]string , 0 )
313+ candleSubs := make (map [candleSub ][]string , 0 )
311314
312- for id , interval := range mds .subs .candles {
313- intervals [ interval ] = append (intervals [ interval ], id )
315+ for id , c := range mds .subs .candles {
316+ candleSubs [ c ] = append (candleSubs [ c ], id )
314317 delete (mds .subs .candles , id )
315318 }
316- for interval , ids := range intervals {
317- err := mds .UnSubscribeCandle (ids , interval )
319+ for c , ids := range candleSubs {
320+ err := mds .UnSubscribeCandle (ids , c . interval , c . waitingClose )
318321 if err != nil {
319322 return err
320323 }
0 commit comments