Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mk committed Jan 18, 2024
1 parent d7f06f5 commit a5d31fa
Show file tree
Hide file tree
Showing 6 changed files with 1,238 additions and 1,095 deletions.
33 changes: 33 additions & 0 deletions getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ func BitstampGetter(ticker string) (float64, error) {
if err != nil {
return 0, err
}
//fmt.Printf("Bitstamp %s %s\n", ticker, string(body))
//fmt.Println(url)
var tickerData BitstampTicker
err = json.Unmarshal(body, &tickerData)
if err != nil {
Expand Down Expand Up @@ -324,3 +326,34 @@ func BitflyerGetter(ticker string) (float64, error) {
}
return (tickerData.Ask + tickerData.Bid) / 2, nil
}

type OkxTicker struct {
Data []struct {
Ask string `json:"askPx"`
Bid string `json:"bidPx"`
} `json:"data"`
}

func OkxGetter(ticker string) (float64, error) {
url := "https://www.okx.com/api/v5/market/ticker?instId=" + ticker
body, err := getHTTPResponseBodyFromUrl(url)
if err != nil {
return 0, err
}
var tickerData OkxTicker
err = json.Unmarshal(body, &tickerData)
if err != nil {
return 0, err
}
a := tickerData.Data[0].Ask
b := tickerData.Data[0].Bid
af, err := strconv.ParseFloat(a, 64)
if err != nil {
return 0, err
}
bf, err := strconv.ParseFloat(b, 64)
if err != nil {
return 0, err
}
return (af + bf) / 2, nil
}
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
Gateio Exchange = "gateio"
Bitfinex Exchange = "bitfinex"
Bybit Exchange = "bybit"
Okx Exchange = "okx"
)

var exchangeGetters = map[Exchange]TickerGetter{
Expand All @@ -54,6 +55,7 @@ var exchangeGetters = map[Exchange]TickerGetter{
Gateio: GateIOGetter,
Bitfinex: BitfinexGetter,
Bybit: BybitGetter,
Okx: OkxGetter,
}

func getExchangeTickerPrice(et ExTick) (*ExTickPri, error) {
Expand Down Expand Up @@ -90,6 +92,7 @@ var exchangeSymbols = map[Exchange][]string{
Gateio: symbols.Gateio,
Bitfinex: symbols.Bitfinex,
Bybit: symbols.Bybit,
Okx: symbols.Okx,
}

func findExTick(symbol string) (*ExTick, error) {
Expand Down Expand Up @@ -149,8 +152,10 @@ func searchForExchangeTicker(symbol string) []ExTick {
for k, v := range exchangeSymbols {
for _, t := range v {
lowerT := strings.ToLower(t)
lowerTNoDashNoSlash := strings.ReplaceAll(strings.ReplaceAll(lowerT, "-", ""), "/", "")
lowerSymbol := strings.ToLower(symbol)
if strings.Contains(lowerT, lowerSymbol) {
lowerSymbolNoDashNoSlash := strings.ReplaceAll(strings.ReplaceAll(lowerSymbol, "-", ""), "/", "")
if strings.Contains(lowerTNoDashNoSlash, lowerSymbolNoDashNoSlash) {
found = append(found, ExTick{k, t})
}
}
Expand Down
3 changes: 2 additions & 1 deletion nots
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ curl https://www.bitstamp.net/api/v2/ticker/ > bs.json
curl https://data.gateapi.io/api2/1/pairs > gio
curl "https://api.huobi.pro/market/tickers" > huo.json
curl -L api.kucoin.com/api/v2/symbols
curl --url 'https://api-pub.bitfinex.com/v2/tickers?symbols=ALL'
curl "https://api-pub.bitfinex.com/v2/conf/pub:list:pair:exchange"
curl https://www.okx.com/api/v5/market/tickers\?instType\=SPOT
Loading

0 comments on commit a5d31fa

Please sign in to comment.