///////////////////////////
//below is both json and xml versions, currently it looks like XML is more optimized on the Ally server
below is both json and xml versions, currently it looks like XML is more optimized on the Ally server
/////////////////////////// // below is both json and xml versions currently it looks like XML is more optimized on the Ally server
func allyJsonQuoteToSibylStockQuoteRecord(quote jsonQuote) (*core.SibylStockQuoteRecord, error) {
	var err error
	timeRegex := regexp.MustCompile(`(?P<hour>\d{2}):(?P<min>\d{2})`)
	var match []string
	var Timestamp int64
	if Timestamp, err = strconv.ParseInt(quote.Timestamp, 10, 64); err != nil {
		return nil, fmt.Errorf("allyJsonStockQuoteToSibylQuote: the timestamp for %v was %v and could not convert", quote.Symbol, quote.Timestamp)
	}
	if Timestamp == 0 {
		return nil, fmt.Errorf("allyJsonStockQuoteToSibylQuote: the timestamp for %v was erroneous: %v", quote.Symbol, quote.Timestamp)
	}
	var Ask sql.NullFloat64
	if Ask.Float64, err = strconv.ParseFloat(quote.Ask, 64); err == nil {
		Ask.Valid = true
	}
	var AskTime sql.NullInt64
	match = timeRegex.FindStringSubmatch(quote.AskTime)
	if match != nil {
		if hour, err := strconv.ParseInt(match[1], 10, 64); err == nil {
			if min, err := strconv.ParseInt(match[2], 10, 64); err == nil {
				AskTime.Int64 = hour*100 + min
				AskTime.Valid = true
			}
		}
	}
	var AskSize sql.NullInt64
	if AskSize.Int64, err = strconv.ParseInt(quote.AskSize, 10, 64); err == nil {
		AskSize.Valid = true
	}
	var Beta sql.NullFloat64
	if Beta.Float64, err = strconv.ParseFloat(quote.Beta, 64); err == nil {
		Beta.Valid = true
	}
	var Bid sql.NullFloat64
	if Bid.Float64, err = strconv.ParseFloat(quote.Bid, 64); err == nil {
		Bid.Valid = true
	}
	var BidTime sql.NullInt64
	match = timeRegex.FindStringSubmatch(quote.BidTime)
	if match != nil {
		if hour, err := strconv.ParseInt(match[1], 10, 64); err == nil {
			if min, err := strconv.ParseInt(match[2], 10, 64); err == nil {
				BidTime.Int64 = hour*100 + min
				BidTime.Valid = true
			}
		}
	}
	var BidSize sql.NullInt64
	if BidSize.Int64, err = strconv.ParseInt(quote.BidSize, 10, 64); err == nil {
		BidSize.Valid = true
	}
	var Change sql.NullFloat64
	if Change.Float64, err = strconv.ParseFloat(quote.Change, 64); err == nil {
		if strings.ToLower(quote.ChangeSign) != "na" {
			Change.Valid = true
			if quote.ChangeSign == "d" {
				Change.Float64 *= -1
			}
		}
	}
	var HighPrice sql.NullFloat64
	if HighPrice.Float64, err = strconv.ParseFloat(quote.HighPrice, 64); err == nil {
		HighPrice.Valid = true
	}
	var LastTradePrice sql.NullFloat64
	if LastTradePrice.Float64, err = strconv.ParseFloat(quote.LastTrade, 64); err == nil {
		LastTradePrice.Valid = true
	}
	var LastTradeTimestamp sql.NullInt64
	if t, err := time.Parse("2006-01-02T15:04:05-07:00", quote.LastTradeTimestamp); err == nil {
		LastTradeTimestamp.Int64 = t.Unix() 
		LastTradeTimestamp.Valid = true
	}
	var LastTradeVolume sql.NullInt64
	if LastTradeVolume.Int64, err = strconv.ParseInt(quote.LastTradeVolume, 10, 64); err == nil {
		LastTradeVolume.Valid = true
	}
	var LowPrice sql.NullFloat64
	if LowPrice.Float64, err = strconv.ParseFloat(quote.LowPrice, 64); err == nil {
		LowPrice.Valid = true
	}
	var Volume sql.NullInt64
	if Volume.Int64, err = strconv.ParseInt(quote.Volume, 10, 64); err == nil {
		Volume.Valid = true
	}
	var VolWeightedAvgPrice sql.NullFloat64
	if VolWeightedAvgPrice.Float64, err = strconv.ParseFloat(quote.VolWeightedAvgPrice, 64); err == nil {
		VolWeightedAvgPrice.Valid = true
	}
	return &core.SibylStockQuoteRecord{
		Ask:                 Ask,
		AskTime:             AskTime,
		AskSize:             AskSize,
		Beta:                Beta,
		Bid:                 Bid,
		BidTime:             BidTime,
		BidSize:             BidSize,
		Change:              Change,
		HighPrice:           HighPrice,
		LastTradePrice:      LastTradePrice,
		LastTradeTimestamp:  LastTradeTimestamp,
		LastTradeVolume:     LastTradeVolume,
		LowPrice:            LowPrice,
		Symbol:              core.StockSymbolType(quote.Symbol),
		Timestamp:           core.NewTimestampTypeFromUnix(Timestamp),
		Volume:              Volume,
		VolWeightedAvgPrice: VolWeightedAvgPrice,
	}, nil
}
func allyJsonQuoteToSibylStockQuoteRecord ( quote jsonQuote ) ( * core . SibylStockQuoteRecord , error ) { var err error timeRegex := regexp . MustCompile ( `(?P<hour>\d{2}):(?P<min>\d{2})` ) var match [ ] string var Timestamp int64 if Timestamp , err = strconv . ParseInt ( quote . Timestamp , 10 , 64 ) ; err != nil { return nil , fmt . Errorf ( " " , quote . Symbol , quote . Timestamp ) } if Timestamp == 0 { return nil , fmt . Errorf ( " " , quote . Symbol , quote . Timestamp ) } var Ask sql . NullFloat64 if Ask . Float64 , err = strconv . ParseFloat ( quote . Ask , 64 ) ; err == nil { Ask . Valid = true } var AskTime sql . NullInt64 match = timeRegex . FindStringSubmatch ( quote . AskTime ) if match != nil { if hour , err := strconv . ParseInt ( match [ 1 ] , 10 , 64 ) ; err == nil { if min , err := strconv . ParseInt ( match [ 2 ] , 10 , 64 ) ; err == nil { AskTime . Int64 = hour * 100 + min AskTime . Valid = true } } } var AskSize sql . NullInt64 if AskSize . Int64 , err = strconv . ParseInt ( quote . AskSize , 10 , 64 ) ; err == nil { AskSize . Valid = true } var Beta sql . NullFloat64 if Beta . Float64 , err = strconv . ParseFloat ( quote . Beta , 64 ) ; err == nil { Beta . Valid = true } var Bid sql . NullFloat64 if Bid . Float64 , err = strconv . ParseFloat ( quote . Bid , 64 ) ; err == nil { Bid . Valid = true } var BidTime sql . NullInt64 match = timeRegex . FindStringSubmatch ( quote . BidTime ) if match != nil { if hour , err := strconv . ParseInt ( match [ 1 ] , 10 , 64 ) ; err == nil { if min , err := strconv . ParseInt ( match [ 2 ] , 10 , 64 ) ; err == nil { BidTime . Int64 = hour * 100 + min BidTime . Valid = true } } } var BidSize sql . NullInt64 if BidSize . Int64 , err = strconv . ParseInt ( quote . BidSize , 10 , 64 ) ; err == nil { BidSize . Valid = true } var Change sql . NullFloat64 if Change . Float64 , err = strconv . ParseFloat ( quote . Change , 64 ) ; err == nil { if strings . ToLower ( quote . ChangeSign ) != " " { Change . Valid = true if quote . ChangeSign == " " { Change . Float64 *= - 1 } } } var HighPrice sql . NullFloat64 if HighPrice . Float64 , err = strconv . ParseFloat ( quote . HighPrice , 64 ) ; err == nil { HighPrice . Valid = true } var LastTradePrice sql . NullFloat64 if LastTradePrice . Float64 , err = strconv . ParseFloat ( quote . LastTrade , 64 ) ; err == nil { LastTradePrice . Valid = true } var LastTradeTimestamp sql . NullInt64 if t , err := time . Parse ( " " , quote . LastTradeTimestamp ) ; err == nil { LastTradeTimestamp . Int64 = t . Unix ( ) LastTradeTimestamp . Valid = true } var LastTradeVolume sql . NullInt64 if LastTradeVolume . Int64 , err = strconv . ParseInt ( quote . LastTradeVolume , 10 , 64 ) ; err == nil { LastTradeVolume . Valid = true } var LowPrice sql . NullFloat64 if LowPrice . Float64 , err = strconv . ParseFloat ( quote . LowPrice , 64 ) ; err == nil { LowPrice . Valid = true } var Volume sql . NullInt64 if Volume . Int64 , err = strconv . ParseInt ( quote . Volume , 10 , 64 ) ; err == nil { Volume . Valid = true } var VolWeightedAvgPrice sql . NullFloat64 if VolWeightedAvgPrice . Float64 , err = strconv . ParseFloat ( quote . VolWeightedAvgPrice , 64 ) ; err == nil { VolWeightedAvgPrice . Valid = true } return & core . SibylStockQuoteRecord { Ask : Ask , AskTime : AskTime , AskSize : AskSize , Beta : Beta , Bid : Bid , BidTime : BidTime , BidSize : BidSize , Change : Change , HighPrice : HighPrice , LastTradePrice : LastTradePrice , LastTradeTimestamp : LastTradeTimestamp , LastTradeVolume : LastTradeVolume , LowPrice : LowPrice , Symbol : core . StockSymbolType ( quote . Symbol ) , Timestamp : core . NewTimestampTypeFromUnix ( Timestamp ) , Volume : Volume , VolWeightedAvgPrice : VolWeightedAvgPrice , } , nil }
below is both json and xml versions, currently it looks like XML is more optimized on the Ally server
below is both json and xml versions currently it looks like XML is more optimized on the Ally server
/////////////////////// //if the timestamp was erroneous so bail /////////////////////// /////////////////////// /////////////////////// /////////////////////// /////////////////////// /////////////////////// /////////////////////// /////////////////////// /////////////////////// /////////////////////// /////////////////////// // example: 2018-09-21T00:00:00-04:00 //number of seconds since epoch /////////////////////// /////////////////////// /////////////////////// ///////////////////////