-
Create configuration object.
More in README
package main
import (
"github.com/beyang-crypto/CCXT_beYANG/config"
. "github.com/beyang-crypto/CCXT_beYANG_Binance/binance/spotAndMargin/rest/enums"
)
func main() {
path := "config-prod.yaml"
cfg := config.NewAuth(path, 0, MainnetEndpoint, true)
}
-
Create configuration object by passing config object and relative path to logger file for logging purposes.
b := New(cfg, "binanceRespLog.log")
-
Create a structure with parameters necessary for the function. In this example we use Test New Order function.
Test New Order in library
Test New Order in Binance API
path := "config-prod.yaml"
cfg := config.NewAuth(path, 0, TestnetEndpoint, true)
connRest := client.New(cfg, "binanceRespLog.log")
symbol, _ := connRest.GetPair("btc", "usdt")
parm := spotRest.TestNewOrderParam{
Symbol: symbol,
Side: OrderSideBUY,
Type: OrderTypeLimit,
TimeInForce: TimeInForceGTC,
Quantity: 0.01,
NewClientOrderId: "my_order_id_1",
Price: 9000.0,
}
-
Launch
ans, err := spotRest.TestNewOrder(connRest, parm)
if err != nil {
log.Fatalln(err)
}
log.Printf("MAIN response %v", ans)
-
Create configuration object.
More in README CCXT_BeYANG
cfg := NewConfiguration(binanceWs.HostBaseUrl_1, true)
-
Create a structure with parameters necessary for the function. In this example we use Test New Order function.
connWs := binanceWs.New(ws.FuturesTrading, cfg, "binanceTestLog.log")
connWs.Start()
-
Create pair(s) and subscribe to the channels we need. We create an array of currency pairs to which we will subscribe, inside one connection.
symbols1 := []string{
"btc",
"eth",
"xrp",
"ada",
"sol",
"doge",
"matic",
"shib",
"trx",
"uni",
"avax",
"ltc",
"etc",
"link",
"atom",
}
symbol2 := "usdt"
var pairs []string
for _, symbol1 := range symbols1 {
pairs = append(pairs, connWs.GetPair(symbol1, symbol2))
}
ws.Subscribe(connWs, binanceWs.ChannelTicker, pairs)
-
Connect to the stream with the channel to which we just subscribed, pass the callback as an argument.
Callback-function example:
func handleBookTicker(name string, symbol string, data binanceWs.BookTicker) {
log.Printf("%s Ticker %s: %v", name, symbol, data)
}
Connection:
connWs.GetEmitter().On(binanceWs.ChannelTicker, handleBookTicker)
-
Create a channel so that the function doesn't end. This is necessary to keep the app alive.
forever := make(chan struct{})
<-forever