func Scrape(last_timestamp int64) ([]model.Trade, error) { url := fmt.Sprintf("https://api.bitfinex.com/v1/trades/btcusd?timestamp=%d", last_timestamp+1) content, err := restclient.GetContent(url) if err != nil { return nil, err } bitfinex_trades := make([]BitfinexTrade, 0) err = json.Unmarshal(content, &bitfinex_trades) if err != nil { //fmt.Printf("%s", string(content)) return nil, err } //Bitfinex trade response has latest trade first, reverse trades := []model.Trade{} last := len(bitfinex_trades) - 1 for i, _ := range bitfinex_trades { trade := bitfinex_trades[last-i] var t model.Trade t.Timestamp = trade.Timestamp t.TradeId = trade.Tid t.Exchange = "bitfinex" t.Type = trade.Type t.Price, _ = strconv.ParseFloat(trade.Price, 64) t.Amount, _ = strconv.ParseFloat(trade.Amount, 64) trades = append(trades, t) } return trades, nil }
func Scrape(last_timestamp int64) ([]model.Trade, error) { url := "https://www.bitstamp.net/api/transactions/" //defaults to all trades from last hour content, err := restclient.GetContent(url) if err != nil { return nil, err } bitstamp_trades := make([]BitstampTrade, 0) err = json.Unmarshal(content, &bitstamp_trades) if err != nil { return nil, err } //Bitstamp trade response has latest trade first, reverse trades := []model.Trade{} last := len(bitstamp_trades) - 1 for i, _ := range bitstamp_trades { trade := bitstamp_trades[last-i] var t model.Trade t.Timestamp, _ = strconv.ParseInt(trade.Date, 10, 64) t.TradeId = trade.Tid t.Exchange = "bitstamp" if trade.Type == 0 { t.Type = "buy" } else if trade.Type == 1 { t.Type = "sell" } t.Price, _ = strconv.ParseFloat(trade.Price, 64) t.Amount, _ = strconv.ParseFloat(trade.Amount, 64) if t.Timestamp > last_timestamp { trades = append(trades, t) } } return trades, nil }