-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf19039
commit 376acbb
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package binance | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"bisonai.com/orakl/node/pkg/wss" | ||
) | ||
|
||
func Test() error { | ||
ctx := context.Background() | ||
conn, err := wss.NewConnection(ctx, wss.WithEndpoint(URL)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sub := subscription{ | ||
Method: "SUBSCRIBE", | ||
Params: []Stream{ | ||
"ethusdt@miniTicker", | ||
}, | ||
Id: 1, | ||
} | ||
|
||
err = conn.Write(ctx, sub) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ch := conn.ReadV2(ctx) | ||
for { | ||
select { | ||
case msg := <-ch: | ||
rawData, ok := msg.(map[string]interface{}) | ||
if !ok { | ||
return fmt.Errorf("received data is not a map[string]interface{}") | ||
} | ||
jsonData, err := json.Marshal(rawData) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var miniTicker MiniTicker | ||
err = json.Unmarshal(jsonData, &miniTicker) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println(miniTicker) | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package binance | ||
|
||
import "fmt" | ||
|
||
const ( | ||
URL = "wss://stream.binance.com:443/ws" | ||
) | ||
|
||
type Stream string | ||
|
||
type MiniTicker struct { | ||
EventType string `json:"e"` | ||
EventTime int64 `json:"E"` | ||
Symbol string `json:"s"` | ||
Price string `json:"c"` | ||
OpenPrice string `json:"o"` | ||
HighPrice string `json:"h"` | ||
LowPrice string `json:"l"` | ||
Volume string `json:"v"` | ||
QuoteVolume string `json:"q"` | ||
} | ||
|
||
func (m MiniTicker) String() string { | ||
return fmt.Sprintf( | ||
"EventType: %s, EventTime: %d, Symbol: %s, Price: %s, OpenPrice: %s, HighPrice: %s, LowPrice: %s, Volume: %s, QuoteVolume: %s\n", | ||
m.EventType, m.EventTime, m.Symbol, m.Price, m.OpenPrice, m.HighPrice, m.LowPrice, m.Volume, m.QuoteVolume, | ||
) | ||
} | ||
|
||
type subscription struct { | ||
Method string `json:"method"` | ||
Params []Stream `json:"params"` | ||
Id uint32 `json:"id"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"sync" | ||
|
||
"bisonai.com/orakl/node/pkg/wfetcher/binance" | ||
) | ||
|
||
func main() { | ||
var wg sync.WaitGroup | ||
wg.Add(1) | ||
binance.Test() | ||
wg.Wait() | ||
|
||
} |