Documentation
¶
Index ¶
- Constants
- type Category
- type Client
- func (c *Client) Connect() error
- func (c *Client) Disconnect()
- func (c *Client) GetAllPrices(ctx context.Context) (*PricesResponse, error)
- func (c *Client) GetPrice(ctx context.Context, symbol string) (*Price, error)
- func (c *Client) GetPricesByCategory(ctx context.Context, category Category) (*PricesResponse, error)
- func (c *Client) IsConnected() bool
- func (c *Client) OnConnect(handler func())
- func (c *Client) OnConnectError(handler func(error))
- func (c *Client) OnDataLive(handler func())
- func (c *Client) OnDataStale(handler func())
- func (c *Client) OnDisconnect(handler func())
- func (c *Client) OnPrices(event string, handler func([]Price))
- func (c *Client) Subscribe(symbols []string) error
- func (c *Client) Unsubscribe(symbols []string) error
- type Error
- type Option
- type Price
- type PricesResponse
Constants ¶
const ( // DefaultBaseURL — REST API kök adresi. DefaultBaseURL = "https://altinapi.com/api/v1" // DefaultSocketURL — Socket.IO kök adresi. DefaultSocketURL = "https://altinapi.com" // DefaultTimeout — REST istekleri için varsayılan zaman aşımı. DefaultTimeout = 10 * time.Second // Version — SDK sürümü. Version = "0.1.0" )
const ( // EventConnect — bağlantı kuruldu. EventConnect = "connect" // EventDisconnect — bağlantı kapandı. EventDisconnect = "disconnect" // EventConnectError — bağlantı hatası. EventConnectError = "connect_error" // EventPricesSnapshot — bağlantı anında tüm güncel fiyatlar. EventPricesSnapshot = "prices:snapshot" // EventPricesUpdate — fiyat değişimi. EventPricesUpdate = "prices:update" // EventDataStale — kaynak bağlantısı koptu, veri eski olabilir. EventDataStale = "data:stale" // EventDataLive — kaynak yeniden bağlandı. EventDataLive = "data:live" )
Sunucu tarafından yayınlanan WebSocket olayları.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Category ¶
type Category string
Category — altinapi'nin tanımladığı sembol kategorileri. String tipinde tutulur; sabit değerler aşağıda.
const ( // CategoryDoviz — döviz kurları (USDTRY, EURTRY, ...). CategoryDoviz Category = "DOVIZ" // CategoryMaden — değerli metaller (ALTIN, XAUUSD, GUMUSD, PLATIN, PALADYUM). CategoryMaden Category = "MADEN" // CategoryParite — uluslararası pariteler (EURUSD, GBPUSD, ...). CategoryParite Category = "PARITE" // CategoryGramAltin — ağırlığa göre altın (5/10/20/50/100 gr). CategoryGramAltin Category = "GRAM ALTIN" // CategorySarrafiye — Türk sarrafiye altınları (çeyrek, yarım, tam, ata). CategorySarrafiye Category = "SARRAFIYE" )
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client — altinapi REST + WebSocket istemcisi.
REST çağrıları thread-safe'dir. WebSocket için Connect/On/Subscribe sırası önemli değildir — handler'lar connect'ten önce kaydedilebilir.
func NewClient ¶
NewClient — yeni bir altinapi istemcisi kurar.
c := altinapi.NewClient("hapi_xxx")
c := altinapi.NewClient("hapi_xxx", altinapi.WithTimeout(5*time.Second))
func (*Client) Connect ¶
Connect — Socket.IO bağlantısını açar. Bloklayıcı değildir; goroutine'de dinler. Birden çok kez çağrılırsa idempotent davranır.
func (*Client) GetAllPrices ¶
func (c *Client) GetAllPrices(ctx context.Context) (*PricesResponse, error)
GetAllPrices — tüm sembollerin (250+) güncel fiyatları.
func (*Client) GetPricesByCategory ¶
func (c *Client) GetPricesByCategory(ctx context.Context, category Category) (*PricesResponse, error)
GetPricesByCategory — kategori bazlı fiyat listesi. category: DOVIZ, MADEN, PARITE, GRAM ALTIN, SARRAFIYE.
func (*Client) IsConnected ¶
IsConnected — anlık bağlantı durumu.
func (*Client) OnConnect ¶
func (c *Client) OnConnect(handler func())
OnConnect — bağlantı kurulduğunda çağrılır.
func (*Client) OnConnectError ¶
OnConnectError — bağlantı hatası olduğunda çağrılır.
func (*Client) OnDataLive ¶
func (c *Client) OnDataLive(handler func())
OnDataLive — kaynak yeniden bağlandığında çağrılır.
func (*Client) OnDataStale ¶
func (c *Client) OnDataStale(handler func())
OnDataStale — kaynak bağlantısı koptuğunda çağrılır.
func (*Client) OnDisconnect ¶
func (c *Client) OnDisconnect(handler func())
OnDisconnect — bağlantı koptuğunda çağrılır.
func (*Client) OnPrices ¶
OnPrices — prices:snapshot veya prices:update için tip-güvenli handler kaydı. Payload normalization burada yapılır: server Price veya {data: Price} gönderebilir; her iki durumda da handler'a düz []Price geçer.
func (*Client) Subscribe ¶
Subscribe — belirli sembollere abone ol. Çağrılmazsa tüm güncellemeler gelir.
func (*Client) Unsubscribe ¶
Unsubscribe — daha önce abone olunan sembollerden ayrıl.
type Error ¶
type Error struct {
Message string
StatusCode int
// Cause altta yatan hatayı tutar (errors.Is/As ile kullanılabilir).
Cause error
}
Error — altinapi SDK tarafından döndürülen hata. StatusCode 0 ise ağ hatası, aksi halde HTTP durum kodu.
type Option ¶
type Option func(*Client)
Option — Client kurarken kullanılan fonksiyonel seçenek.
func WithHTTPClient ¶
WithHTTPClient — özel *http.Client kullan (testlerde yararlı).
type Price ¶
type Price struct {
Symbol string `json:"symbol"`
Category string `json:"category"`
Bid float64 `json:"bid"`
Ask float64 `json:"ask"`
Timestamp string `json:"timestamp"` // ISO 8601
Description string `json:"description,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
}
Price — tek bir sembol için fiyat kaydı.
API yanıtının JSON şekli ile birebir eşleşir. omitempty alanları (Description, CreatedAt) server göndermezse boş kalır.
type PricesResponse ¶
type PricesResponse struct {
Data []Price `json:"data"`
UpdatedAt string `json:"updatedAt"`
Stale bool `json:"stale"`
}
PricesResponse — /prices ve /prices/category endpoint'lerinin yanıt şekli.