You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
3.1 KiB
131 lines
3.1 KiB
2 months ago
|
package consumer
|
||
|
|
||
|
import (
|
||
|
"github.com/streadway/amqp"
|
||
|
"matchmaking-system/internal/conf"
|
||
|
"matchmaking-system/internal/pkg/flags"
|
||
|
"matchmaking-system/internal/pkg/logging/applogger"
|
||
|
)
|
||
|
|
||
|
// ChanEntrustStatus
|
||
|
// @Description:
|
||
|
type ChanEntrustStatus struct {
|
||
|
ShareUsMq chan []byte // 美股
|
||
|
ShareMysMq chan []byte // 马股
|
||
|
ShareIdnMq chan []byte // 印尼股
|
||
|
ShareThaMq chan []byte // 泰股
|
||
|
ShareInrMq chan []byte // 印度股
|
||
|
ShareGbxMq chan []byte // 英股
|
||
|
ShareSgdMq chan []byte // 新加坡股
|
||
|
ShareHkdMq chan []byte // 港股
|
||
|
ShareEurMq chan []byte // 德股
|
||
|
ShareFurMq chan []byte // 法股
|
||
|
ShareBrlMq chan []byte // 巴西股
|
||
|
ShareJpyMq chan []byte // 日本股
|
||
|
OptionInrMq chan []byte // 期权(印度)
|
||
|
ContractMq chan []byte // 合约
|
||
|
ForexMq chan []byte // 外汇
|
||
|
}
|
||
|
|
||
|
// ConsumerEntrust
|
||
|
// @Description: 持仓消息队列【委托--持仓】
|
||
|
type ConsumerEntrust struct {
|
||
|
Conn *amqp.Connection
|
||
|
Channel *amqp.Channel
|
||
|
Queue *amqp.Queue
|
||
|
}
|
||
|
|
||
|
// NewEntrust
|
||
|
//
|
||
|
// @Description: 初始化持仓消息列队
|
||
|
// @param f
|
||
|
// @param con
|
||
|
// @return *ConsumerEntrust
|
||
|
// @return error
|
||
|
func NewEntrust(f *conf.Data, con *amqp.Connection) (*ConsumerEntrust, error) {
|
||
|
var err error
|
||
|
var queue amqp.Queue
|
||
|
ce := new(ConsumerEntrust)
|
||
|
|
||
|
// Producer Link Service
|
||
|
ce.Conn = con
|
||
|
|
||
|
// Create a consumer channel
|
||
|
ce.Channel, err = ce.Conn.Channel()
|
||
|
if err != nil {
|
||
|
applogger.Error("channel err:%v", err)
|
||
|
return ce, err
|
||
|
}
|
||
|
|
||
|
// Declare a queue
|
||
|
queue, err = ce.Channel.QueueDeclare(
|
||
|
f.Mq.Entrust,
|
||
|
true,
|
||
|
false,
|
||
|
false,
|
||
|
false,
|
||
|
nil,
|
||
|
)
|
||
|
ce.Queue = &queue
|
||
|
|
||
|
return ce, nil
|
||
|
}
|
||
|
|
||
|
// ConsumerNotice
|
||
|
//
|
||
|
// @Description: 处理接收到的消息
|
||
|
// @receiver c
|
||
|
func (c *ConsumerEntrust) ConsumerNotice() {
|
||
|
msgs, err := c.Channel.Consume(
|
||
|
c.Queue.Name,
|
||
|
flags.SetNull,
|
||
|
true,
|
||
|
false,
|
||
|
false,
|
||
|
false,
|
||
|
nil,
|
||
|
)
|
||
|
if err != nil {
|
||
|
applogger.Error("ConsumerNotice err:%v", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
applogger.Info("消费者消息接受通道........")
|
||
|
|
||
|
for value := range msgs {
|
||
|
// TODO: 处理接收到的消息进行平仓操作
|
||
|
switch flags.CheckEnvironment {
|
||
|
case flags.CheckContract:
|
||
|
ConsumerEntrustMq.ContractMq <- value.Body
|
||
|
case flags.CheckForex:
|
||
|
ConsumerEntrustMq.ForexMq <- value.Body
|
||
|
case flags.CheckShareUs:
|
||
|
ConsumerEntrustMq.ShareUsMq <- value.Body
|
||
|
case flags.CheckShareMys:
|
||
|
ConsumerEntrustMq.ShareMysMq <- value.Body
|
||
|
case flags.CheckShareTha:
|
||
|
ConsumerEntrustMq.ShareThaMq <- value.Body
|
||
|
case flags.CheckShareIdn:
|
||
|
ConsumerEntrustMq.ShareIdnMq <- value.Body
|
||
|
case flags.CheckShareInr:
|
||
|
ConsumerEntrustMq.ShareInrMq <- value.Body
|
||
|
case flags.CheckShareSgd:
|
||
|
ConsumerEntrustMq.ShareSgdMq <- value.Body
|
||
|
case flags.CheckShareHkd:
|
||
|
ConsumerEntrustMq.ShareHkdMq <- value.Body
|
||
|
case flags.CheckShareGbx:
|
||
|
ConsumerEntrustMq.ShareGbxMq <- value.Body
|
||
|
case flags.CheckShareEur:
|
||
|
ConsumerEntrustMq.ShareEurMq <- value.Body
|
||
|
case flags.CheckShareFur:
|
||
|
ConsumerEntrustMq.ShareFurMq <- value.Body
|
||
|
case flags.CheckShareBrl:
|
||
|
ConsumerEntrustMq.ShareBrlMq <- value.Body
|
||
|
case flags.CheckOptionInr:
|
||
|
ConsumerEntrustMq.OptionInrMq <- value.Body
|
||
|
default:
|
||
|
applogger.Error("服务启动标识错误.")
|
||
|
}
|
||
|
}
|
||
|
}
|