func (c *Client) StreamPayments(ctx context.Context, accountID string, cursor *Cursor, handler PaymentHandler) (err error) {
	c.fixURLOnce.Do(c.fixURL)
	url := fmt.Sprintf("%s/accounts/%s/payments", c.URL, accountID)
	return c.stream(ctx, url, cursor, func(data []byte) error {
		var payment Payment
		err = json.Unmarshal(data, &payment)
		if err != nil {
			return errors.Wrap(err, "Error unmarshaling data")
		}
		handler(payment)
		return nil
	})
}
StreamPayments streams incoming payments. Use context.WithCancel to stop streaming or
context.Background() if you want to stream indefinitely.
package horizon
import (
	"bufio"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"net/url"
	"strconv"
	"strings"
	"github.com/stellar/go/support/errors"
	"github.com/stellar/go/xdr"
	"golang.org/x/net/context"
)
func (c *Client) HomeDomainForAccount(aid string) (string, error) {
	a, err := c.LoadAccount(aid)
	if err != nil {
		return "", errors.Wrap(err, "load account failed")
	}
	return a.HomeDomain, nil
}
func (c *Client) fixURL() {
	c.URL = strings.TrimRight(c.URL, "/")
}
func (c *Client) Root() (root Root, err error) {
	c.fixURLOnce.Do(c.fixURL)
	resp, err := c.HTTP.Get(c.URL)
	if err != nil {
		return
	}
	err = decodeResponse(resp, &root)
	return
}
func (c *Client) LoadAccount(accountID string) (account Account, err error) {
	c.fixURLOnce.Do(c.fixURL)
	resp, err := c.HTTP.Get(c.URL + "/accounts/" + accountID)
	if err != nil {
		return
	}
	err = decodeResponse(resp, &account)
	return
}
func (c *Client) LoadAccountOffers(accountID string, params ...interface{}) (offers OffersPage, err error) {
	c.fixURLOnce.Do(c.fixURL)
	endpoint := ""
	query := url.Values{}
	for _, param := range params {
		switch param := param.(type) {
		case At:
			endpoint = string(param)
		case Limit:
			query.Add("limit", strconv.Itoa(int(param)))
		case Order:
			query.Add("order", string(param))
		case Cursor:
			query.Add("cursor", string(param))
		default:
			err = fmt.Errorf("Undefined parameter (%T): %+v", param, param)
			return
		}
	}
	if endpoint == "" {
		endpoint = fmt.Sprintf(
			"%s/accounts/%s/offers?%s",
			c.URL,
			accountID,
			query.Encode(),
		)
	}
	_, err = url.Parse(endpoint)
	if err != nil {
		err = errors.Wrap(err, "failed to parse endpoint")
		return
	}
	resp, err := c.HTTP.Get(endpoint)
	if err != nil {
		err = errors.Wrap(err, "failed to load endpoint")
		return
	}
	err = decodeResponse(resp, &offers)
	return
}
func (c *Client) LoadMemo(p *Payment) (err error) {
	res, err := c.HTTP.Get(p.Links.Transaction.Href)
	if err != nil {
		return errors.Wrap(err, "load transaction failed")
	}
	defer res.Body.Close()
	return json.NewDecoder(res.Body).Decode(&p.Memo)
}
func (c *Client) SequenceForAccount(
	accountID string,
) (xdr.SequenceNumber, error) {
	a, err := c.LoadAccount(accountID)
	if err != nil {
		return 0, errors.Wrap(err, "load account failed")
	}
	seq, err := strconv.ParseUint(a.Sequence, 10, 64)
	if err != nil {
		return 0, errors.Wrap(err, "parse sequence failed")
	}
	return xdr.SequenceNumber(seq), nil
}
func (c *Client) LoadOrderBook(selling Asset, buying Asset, params ...interface{}) (orderBook OrderBookSummary, err error) {
	c.fixURLOnce.Do(c.fixURL)
	query := url.Values{}
	query.Add("selling_asset_type", selling.Type)
	query.Add("selling_asset_code", selling.Code)
	query.Add("selling_asset_issuer", selling.Issuer)
	query.Add("buying_asset_type", buying.Type)
	query.Add("buying_asset_code", buying.Code)
	query.Add("buying_asset_issuer", buying.Issuer)
	for _, param := range params {
		switch param := param.(type) {
		case Limit:
			query.Add("limit", strconv.Itoa(int(param)))
		default:
			err = fmt.Errorf("Undefined parameter (%T): %+v", param, param)
			return
		}
	}
	resp, err := c.HTTP.Get(c.URL + "/order_book?" + query.Encode())
	if err != nil {
		return
	}
	err = decodeResponse(resp, &orderBook)
	return
}
func (c *Client) stream(ctx context.Context, baseURL string, cursor *Cursor, handler func(data []byte) error) error {
	query := url.Values{}
	if cursor != nil {
		query.Set("cursor", string(*cursor))
	}
	for {
		req, err := http.NewRequest("GET", fmt.Sprintf("%s?%s", baseURL, query.Encode()), nil)
		if err != nil {
			return err
		}
		req.Header.Set("Accept", "text/event-stream")
		resp, err := c.HTTP.Do(req)
		if err != nil {
			return err
		}
		defer resp.Body.Close()
		scanner := bufio.NewScanner(resp.Body)
		scanner.Split(splitSSE)
		var objectBytes []byte
		for scanner.Scan() {
			select {
			case <-ctx.Done():
				return nil
			default:
			}
			if len(scanner.Bytes()) == 0 {
				continue
			}
			ev, err := parseEvent(scanner.Bytes())
			if err != nil {
				return err
			}
			if ev.Event != "message" {
				continue
			}
			switch data := ev.Data.(type) {
			case string:
				err = handler([]byte(data))
				objectBytes = []byte(data)
			case []byte:
				err = handler(data)
				objectBytes = data
			default:
				err = errors.New("Invalid ev.Data type")
			}
			if err != nil {
				return err
			}
		}
		err = scanner.Err()
		if err == nil || err == io.ErrUnexpectedEOF {
			object := struct {
				PT string `json:"paging_token"`
			}{}
			err := json.Unmarshal(objectBytes, &object)
			if err != nil {
				return errors.Wrap(err, "Error unmarshaling objectBytes")
			}
			if object.PT != "" {
				query.Set("cursor", object.PT)
			} else {
				return errors.New("no paging_token in object: cannot continue")
			}
			continue
		}
		if err != nil {
			return err
		}
	}
}
func (c *Client) StreamLedgers(ctx context.Context, cursor *Cursor, handler LedgerHandler) (err error) {
	c.fixURLOnce.Do(c.fixURL)
	url := fmt.Sprintf("%s/ledgers", c.URL)
	return c.stream(ctx, url, cursor, func(data []byte) error {
		var ledger Ledger
		err = json.Unmarshal(data, &ledger)
		if err != nil {
			return errors.Wrap(err, "Error unmarshaling data")
		}
		handler(ledger)
		return nil
	})
}