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.
 
 

74 lines
2.1 KiB

package mapping
import (
"sig-pub/api/pb"
"sig-pub/pkg/data/entity"
)
func TradeInstance2Proto(inst *entity.TradeInstance) (pbInst *pb.TradeInstance) {
pbInst = new(pb.TradeInstance)
if inst == nil {
return
}
pbInst.InstId = inst.InstId
pbInst.InstPair = inst.InstPair
pbInst.InstCoin = inst.InstCoin
pbInst.InstType = pb.TradeInstanceType(inst.InstType)
pbInst.Status = inst.Status
pbInst.PriceSz = inst.PriceSz
pbInst.QuantitySz = inst.QuantitySz
pbInst.Icon = inst.Icon
pbInst.UpdateBy = inst.UpdateBy
pbInst.UpdateTime = inst.UpdateTime
pbInst.Leverages = inst.Leverages
for _, ex := range inst.Exchanges {
pbInst.Exchanges = append(pbInst.Exchanges, ExchangeInstance2Proto(ex))
}
return
}
func ExchangeInstance2Proto(exInst *entity.TradeInstanceExchange) (pbExInst *pb.TradeInstanceExchange) {
pbExInst = &pb.TradeInstanceExchange{
ExchangeInstId: exInst.ExchangeInstId,
InstId: exInst.InstId,
Status: exInst.Status,
Exchange: pb.ExchangeType(exInst.Exchange),
UpdateBy: exInst.UpdateBy,
UpdateTime: exInst.UpdateTime,
}
return
}
func Proto2TradeInstance(pbInst *pb.TradeInstance) (inst *entity.TradeInstance) {
inst = new(entity.TradeInstance)
if pbInst == nil {
return
}
inst.InstId = pbInst.InstId
inst.InstPair = pbInst.InstPair
inst.InstCoin = pbInst.InstCoin
inst.InstType = int32(pbInst.InstType)
inst.Status = pbInst.Status
inst.PriceSz = pbInst.PriceSz
inst.QuantitySz = pbInst.QuantitySz
inst.Icon = pbInst.Icon
inst.UpdateBy = pbInst.UpdateBy
inst.UpdateTime = pbInst.UpdateTime
inst.Leverages = pbInst.Leverages
for _, ex := range pbInst.Exchanges {
inst.Exchanges = append(inst.Exchanges, Proto2ExchangeTradeInstance(ex))
}
return
}
func Proto2ExchangeTradeInstance(pbExInst *pb.TradeInstanceExchange) (exInst *entity.TradeInstanceExchange) {
exInst = &entity.TradeInstanceExchange{
ExchangeInstId: pbExInst.ExchangeInstId,
InstId: pbExInst.InstId,
Status: pbExInst.Status,
Exchange: int32(pbExInst.Exchange),
UpdateBy: pbExInst.UpdateBy,
UpdateTime: pbExInst.UpdateTime,
}
return
}