mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 23:16:52 +00:00
New logging system (#319)
* First pass at adding new logging system * NewLogger * NewLogger * WIP * silly bug fix * :D removed files * removed old logging interface * added tests * added tests * Started to add new lines to all f calls * Added subsystem log types * Logger improvements * Further performance improvements * changes to logger and sublogger creation * Renamed Logging types * removed old print statement * changes based on feedback * moved sublogger types to own file * :) * added console as output type * added get level command * added get/set log level via grpc command * added check for output being empty for migration support * first pass at log rotation * added log rotation * :D derp fixed * added tests * changes based on feedback * changed log type * comments * renamed file -> fileSettings * typo fix * changes based on feedback * gofmt ran on additional files * gofmt ran on additional files
This commit is contained in:
@@ -20,25 +20,25 @@ func (a *Alphapoint) WebsocketClient() {
|
||||
a.WebsocketConn, _, err = Dialer.Dial(a.API.Endpoints.WebsocketURL, http.Header{})
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("%s Unable to connect to Websocket. Error: %s\n", a.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s Unable to connect to Websocket. Error: %s\n", a.Name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if a.Verbose {
|
||||
log.Debugf("%s Connected to Websocket.\n", a.Name)
|
||||
log.Debugf(log.ExchangeSys, "%s Connected to Websocket.\n", a.Name)
|
||||
}
|
||||
|
||||
err = a.WebsocketConn.WriteMessage(websocket.TextMessage, []byte(`{"messageType": "logon"}`))
|
||||
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
return
|
||||
}
|
||||
|
||||
for a.Enabled {
|
||||
msgType, resp, err := a.WebsocketConn.ReadMessage()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
break
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func (a *Alphapoint) WebsocketClient() {
|
||||
msgType := MsgType{}
|
||||
err := common.JSONDecode(resp, &msgType)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -58,13 +58,13 @@ func (a *Alphapoint) WebsocketClient() {
|
||||
ticker := WebsocketTicker{}
|
||||
err = common.JSONDecode(resp, &ticker)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
a.WebsocketConn.Close()
|
||||
log.Debugf("%s Websocket client disconnected.", a.Name)
|
||||
log.Debugf(log.ExchangeSys, "%s Websocket client disconnected.", a.Name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ func (a *ANX) GetOrderList(isActiveOrdersOnly bool) ([]OrderResponse, error) {
|
||||
}
|
||||
|
||||
if response.ResultCode != "OK" {
|
||||
log.Errorf("Response code is not OK: %s\n", response.ResultCode)
|
||||
log.Errorf(log.ExchangeSys, "Response code is not OK: %s\n", response.ResultCode)
|
||||
return nil, errors.New(response.ResultCode)
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ func (a *ANX) OrderInfo(orderID string) (OrderResponse, error) {
|
||||
}
|
||||
|
||||
if response.ResultCode != "OK" {
|
||||
log.Errorf("Response code is not OK: %s\n", response.ResultCode)
|
||||
log.Errorf(log.ExchangeSys, "Response code is not OK: %s\n", response.ResultCode)
|
||||
return OrderResponse{}, errors.New(response.ResultCode)
|
||||
}
|
||||
return response.Order, nil
|
||||
@@ -263,7 +263,7 @@ func (a *ANX) Send(currency, address, otp, amount string) (string, error) {
|
||||
}
|
||||
|
||||
if response.ResultCode != "OK" {
|
||||
log.Errorf("Response code is not OK: %s\n", response.ResultCode)
|
||||
log.Errorf(log.ExchangeSys, "Response code is not OK: %s\n", response.ResultCode)
|
||||
return "", errors.New(response.ResultCode)
|
||||
}
|
||||
return response.TransactionID, nil
|
||||
@@ -289,7 +289,7 @@ func (a *ANX) CreateNewSubAccount(currency, name string) (string, error) {
|
||||
}
|
||||
|
||||
if response.ResultCode != "OK" {
|
||||
log.Errorf("Response code is not OK: %s\n", response.ResultCode)
|
||||
log.Errorf(log.ExchangeSys, "Response code is not OK: %s\n", response.ResultCode)
|
||||
return "", errors.New(response.ResultCode)
|
||||
}
|
||||
return response.SubAccount, nil
|
||||
@@ -323,7 +323,7 @@ func (a *ANX) GetDepositAddressByCurrency(currency, name string, newAddr bool) (
|
||||
}
|
||||
|
||||
if response.ResultCode != "OK" {
|
||||
log.Errorf("Response code is not OK: %s\n", response.ResultCode)
|
||||
log.Errorf(log.ExchangeSys, "Response code is not OK: %s\n", response.ResultCode)
|
||||
return "", errors.New(response.ResultCode)
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ func (a *ANX) SendAuthenticatedHTTPRequest(path string, params map[string]interf
|
||||
}
|
||||
|
||||
if a.Verbose {
|
||||
log.Debugf("Request JSON: %s\n", PayloadJSON)
|
||||
log.Debugf(log.ExchangeSys, "Request JSON: %s\n", PayloadJSON)
|
||||
}
|
||||
|
||||
hmac := crypto.GetHMAC(crypto.HashSHA512, []byte(path+string("\x00")+string(PayloadJSON)), []byte(a.API.Credentials.Secret))
|
||||
@@ -430,7 +430,7 @@ func (a *ANX) GetAccountInformation() (AccountInformation, error) {
|
||||
}
|
||||
|
||||
if response.ResultCode != "OK" {
|
||||
log.Errorf("Response code is not OK: %s\n", response.ResultCode)
|
||||
log.Errorf(log.ExchangeSys, "Response code is not OK: %s\n", response.ResultCode)
|
||||
return response, errors.New(response.ResultCode)
|
||||
}
|
||||
return response, nil
|
||||
@@ -453,7 +453,7 @@ func (a *ANX) CheckAPIWithdrawPermission() (bool, error) {
|
||||
}
|
||||
|
||||
if !apiAllowsWithdraw {
|
||||
log.Warn("API key is missing withdrawal permissions")
|
||||
log.Warn(log.ExchangeSys, "API key is missing withdrawal permissions")
|
||||
}
|
||||
|
||||
return apiAllowsWithdraw, nil
|
||||
|
||||
@@ -130,12 +130,13 @@ func (a *ANX) Run() {
|
||||
if !common.StringDataContains(a.GetEnabledPairs(asset.Spot).Strings(), "_") ||
|
||||
!common.StringDataContains(a.GetAvailablePairs(asset.Spot).Strings(), "_") {
|
||||
enabledPairs := currency.NewPairsFromStrings([]string{"BTC_USD,BTC_HKD,BTC_EUR,BTC_CAD,BTC_AUD,BTC_SGD,BTC_JPY,BTC_GBP,BTC_NZD,LTC_BTC,DOG_EBTC,STR_BTC,XRP_BTC"})
|
||||
log.Warn("WARNING: Enabled pairs for ANX reset due to config upgrade, please enable the ones you would like again.")
|
||||
log.Warn(log.ExchangeSys,
|
||||
"Enabled pairs for ANX reset due to config upgrade, please enable the ones you would like again.")
|
||||
|
||||
forceUpdate = true
|
||||
err := a.UpdatePairs(enabledPairs, asset.Spot, true, true)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update currencies.\n", a.GetName())
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update currencies.\n", a.GetName())
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -146,7 +147,7 @@ func (a *ANX) Run() {
|
||||
|
||||
err := a.UpdateTradablePairs(forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", a.GetName(), err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", a.GetName(), err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -499,7 +499,7 @@ func (b *Binance) SendAuthHTTPRequest(method, path string, params url.Values, re
|
||||
headers["X-MBX-APIKEY"] = b.API.Credentials.Key
|
||||
|
||||
if b.Verbose {
|
||||
log.Debugf("sent path: %s", path)
|
||||
log.Debugf(log.ExchangeSys, "sent path: %s", path)
|
||||
}
|
||||
|
||||
path = common.EncodeURLValues(path, params)
|
||||
|
||||
@@ -131,7 +131,8 @@ func (b *Binance) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the Binance wrapper
|
||||
func (b *Binance) Run() {
|
||||
if b.Verbose {
|
||||
log.Debugf("%s Websocket: %s. (url: %s).\n", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()), b.Websocket.GetWebsocketURL())
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s Websocket: %s. (url: %s).\n", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()), b.Websocket.GetWebsocketURL())
|
||||
b.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
@@ -139,12 +140,13 @@ func (b *Binance) Run() {
|
||||
if !common.StringDataContains(b.GetEnabledPairs(asset.Spot).Strings(), "-") ||
|
||||
!common.StringDataContains(b.GetAvailablePairs(asset.Spot).Strings(), "-") {
|
||||
enabledPairs := currency.NewPairsFromStrings([]string{"BTC-USDT"})
|
||||
log.Warn("WARNING: Available pairs for Binance reset due to config upgrade, please enable the ones you would like again")
|
||||
log.Warn(log.ExchangeSys,
|
||||
"Available pairs for Binance reset due to config upgrade, please enable the ones you would like again")
|
||||
forceUpdate = true
|
||||
|
||||
err := b.UpdatePairs(enabledPairs, asset.Spot, true, true)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update currencies. Err: %s\n", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update currencies. Err: %s\n", b.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +156,7 @@ func (b *Binance) Run() {
|
||||
|
||||
err := b.UpdateTradablePairs(forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -951,7 +951,7 @@ func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[
|
||||
}
|
||||
|
||||
if b.Verbose {
|
||||
log.Debugf("Request JSON: %s\n", PayloadJSON)
|
||||
log.Debugf(log.ExchangeSys, "Request JSON: %s\n", PayloadJSON)
|
||||
}
|
||||
|
||||
PayloadBase64 := crypto.Base64Encode(PayloadJSON)
|
||||
|
||||
@@ -73,7 +73,7 @@ func (b *Bitfinex) wsSend(data interface{}) error {
|
||||
return err
|
||||
}
|
||||
if b.Verbose {
|
||||
log.Debugf("%v sending message to websocket %v", b.Name, data)
|
||||
log.Debugf(log.ExchangeSys, "%v sending message to websocket %v", b.Name, data)
|
||||
}
|
||||
return b.WebsocketConn.WriteMessage(websocket.TextMessage, json)
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func (b *Bitfinex) WsAddSubscriptionChannel(chanID int, channel, pair string) {
|
||||
b.WebsocketSubdChannels[chanID] = chanInfo
|
||||
|
||||
if b.Verbose {
|
||||
log.Debugf("%s Subscribed to Channel: %s Pair: %s ChannelID: %d\n",
|
||||
log.Debugf(log.ExchangeSys, "%s Subscribed to Channel: %s Pair: %s ChannelID: %d\n",
|
||||
b.GetName(),
|
||||
channel,
|
||||
pair,
|
||||
@@ -163,13 +163,13 @@ func (b *Bitfinex) WsConnect() error {
|
||||
|
||||
err = b.WsSendAuth()
|
||||
if err != nil {
|
||||
log.Errorf("%v - authentication failed: %v", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%v - authentication failed: %v\n", b.Name, err)
|
||||
}
|
||||
|
||||
b.GenerateDefaultSubscriptions()
|
||||
if hs.Event == "info" {
|
||||
if b.Verbose {
|
||||
log.Debugf("%s Connected to Websocket.\n", b.GetName())
|
||||
log.Debugf(log.ExchangeSys, "%s Connected to Websocket.\n", b.GetName())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ func (b *Bitfinex) WsDataHandler() {
|
||||
eventData := result.(map[string]interface{})
|
||||
event := eventData["event"]
|
||||
if b.Verbose {
|
||||
log.Debugf("%v Received message. Type '%v' Message: %v", b.Name, event, eventData)
|
||||
log.Debugf(log.ExchangeSys, "%v Received message. Type '%v' Message: %v", b.Name, event, eventData)
|
||||
}
|
||||
switch event {
|
||||
case "subscribed":
|
||||
|
||||
@@ -131,7 +131,8 @@ func (b *Bitfinex) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the Bitfinex wrapper
|
||||
func (b *Bitfinex) Run() {
|
||||
if b.Verbose {
|
||||
log.Debugf("%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
||||
b.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
@@ -141,7 +142,8 @@ func (b *Bitfinex) Run() {
|
||||
|
||||
err := b.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,7 +464,7 @@ func (b *Bitfinex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest)
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(resp[i].Side))
|
||||
timestamp, err := strconv.ParseInt(resp[i].Timestamp, 10, 64)
|
||||
if err != nil {
|
||||
log.Warnf("Unable to convert timestamp '%v', leaving blank", resp[i].Timestamp)
|
||||
log.Warnf(log.ExchangeSys, "Unable to convert timestamp '%v', leaving blank", resp[i].Timestamp)
|
||||
}
|
||||
orderDate := time.Unix(timestamp, 0)
|
||||
|
||||
@@ -521,7 +523,7 @@ func (b *Bitfinex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest)
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(resp[i].Side))
|
||||
timestamp, err := strconv.ParseInt(resp[i].Timestamp, 10, 64)
|
||||
if err != nil {
|
||||
log.Warnf("Unable to convert timestamp '%v', leaving blank", resp[i].Timestamp)
|
||||
log.Warnf(log.ExchangeSys, "Unable to convert timestamp '%v', leaving blank", resp[i].Timestamp)
|
||||
}
|
||||
orderDate := time.Unix(timestamp, 0)
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ func TestGetAddressInfoCA(t *testing.T) {
|
||||
t.Error("test failed - Bitflyer - GetAddressInfoCA() error:", err)
|
||||
}
|
||||
if v.UnconfirmedBalance == 0 || v.ConfirmedBalance == 0 {
|
||||
log.Warn("Donation wallet is empty :( - please consider donating")
|
||||
log.Warn(log.ExchangeSys, "Donation wallet is empty :( - please consider donating")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ func (b *Bitflyer) Run() {
|
||||
|
||||
err := b.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ func (b *Bithumb) Run() {
|
||||
|
||||
err := b.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ func (b *Bitmex) WsConnector() error {
|
||||
}
|
||||
|
||||
if b.Verbose {
|
||||
log.Debugf("Successfully connected to Bitmex %s at time: %s Limit: %d",
|
||||
log.Debugf(log.ExchangeSys, "Successfully connected to Bitmex %s at time: %s Limit: %d",
|
||||
welcomeResp.Info,
|
||||
welcomeResp.Timestamp,
|
||||
welcomeResp.Limit.Remaining)
|
||||
@@ -112,7 +112,7 @@ func (b *Bitmex) WsConnector() error {
|
||||
|
||||
err = b.websocketSendAuth()
|
||||
if err != nil {
|
||||
log.Errorf("%v - authentication failed: %v", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%v - authentication failed: %v\n", b.Name, err)
|
||||
}
|
||||
b.GenerateAuthenticatedSubscriptions()
|
||||
return nil
|
||||
@@ -195,13 +195,13 @@ func (b *Bitmex) wsHandleIncomingData() {
|
||||
b.Websocket.DataHandler <- decodedResp
|
||||
if len(quickCapture) == 3 {
|
||||
if b.Verbose {
|
||||
log.Debugf("%s websocket: Successfully subscribed to %s",
|
||||
log.Debugf(log.ExchangeSys, "%s websocket: Successfully subscribed to %s",
|
||||
b.Name, decodedResp.Subscribe)
|
||||
}
|
||||
} else {
|
||||
b.Websocket.SetCanUseAuthenticatedEndpoints(true)
|
||||
if b.Verbose {
|
||||
log.Debugf("%s websocket: Successfully authenticated websocket connection",
|
||||
log.Debugf(log.ExchangeSys, "%s websocket: Successfully authenticated websocket connection",
|
||||
b.Name)
|
||||
}
|
||||
}
|
||||
@@ -561,7 +561,7 @@ func (b *Bitmex) wsSend(data interface{}) error {
|
||||
b.wsRequestMtx.Lock()
|
||||
defer b.wsRequestMtx.Unlock()
|
||||
if b.Verbose {
|
||||
log.Debugf("%v sending message to websocket %v", b.Name, data)
|
||||
log.Debugf(log.ExchangeSys, "%v sending message to websocket %v", b.Name, data)
|
||||
}
|
||||
return b.WebsocketConn.WriteJSON(data)
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ func (b *Bitmex) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the Bitmex wrapper
|
||||
func (b *Bitmex) Run() {
|
||||
if b.Verbose {
|
||||
log.Debugf("%s Websocket: %s. (url: %s).\n", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()), b.API.Endpoints.WebsocketURL)
|
||||
log.Debugf(log.ExchangeSys, "%s Websocket: %s. (url: %s).\n", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()), b.API.Endpoints.WebsocketURL)
|
||||
b.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ func (b *Bitmex) Run() {
|
||||
|
||||
err := b.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ func (b *Bitmex) UpdateTradablePairs(forceUpdate bool) error {
|
||||
|
||||
err = b.UpdatePairs(currency.NewPairsFromStrings(assetPairs), b.CurrencyPairs.AssetTypes[x], false, false)
|
||||
if err != nil {
|
||||
log.Warnf("%s failed to update available pairs. Err: %v", b.Name, err)
|
||||
log.Warnf(log.ExchangeSys, "%s failed to update available pairs. Err: %v", b.Name, err)
|
||||
}
|
||||
assetPairs = nil
|
||||
}
|
||||
|
||||
@@ -192,12 +192,12 @@ func (b *Bitstamp) GetOrderbook(currency string) (Orderbook, error) {
|
||||
for _, x := range resp.Bids {
|
||||
price, err := strconv.ParseFloat(x[0], 64)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
amount, err := strconv.ParseFloat(x[1], 64)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
orderbook.Bids = append(orderbook.Bids, OrderbookBase{price, amount})
|
||||
@@ -206,12 +206,12 @@ func (b *Bitstamp) GetOrderbook(currency string) (Orderbook, error) {
|
||||
for _, x := range resp.Asks {
|
||||
price, err := strconv.ParseFloat(x[0], 64)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
amount, err := strconv.ParseFloat(x[1], 64)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
orderbook.Asks = append(orderbook.Asks, OrderbookBase{price, amount})
|
||||
@@ -598,7 +598,7 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, v2 bool, values url
|
||||
}
|
||||
|
||||
if b.Verbose {
|
||||
log.Debugf("Sending POST request to " + path)
|
||||
log.Debugf(log.ExchangeSys, "Sending POST request to "+path)
|
||||
}
|
||||
|
||||
headers := make(map[string]string)
|
||||
|
||||
@@ -46,7 +46,7 @@ func (b *Bitstamp) WsConnect() error {
|
||||
}
|
||||
|
||||
if b.Verbose {
|
||||
log.Debugf("%s Connected to Websocket.\n", b.GetName())
|
||||
log.Debugf(log.ExchangeSys, "%s Connected to Websocket.\n", b.GetName())
|
||||
}
|
||||
|
||||
err = b.seedOrderBook()
|
||||
@@ -69,7 +69,7 @@ func (b *Bitstamp) WsReadData() (exchange.WebsocketResponse, error) {
|
||||
}
|
||||
|
||||
if b.Verbose {
|
||||
log.Debugf("%s websocket raw response: %s", b.GetName(), resp)
|
||||
log.Debugf(log.ExchangeSys, "%s websocket raw response: %s", b.GetName(), resp)
|
||||
}
|
||||
|
||||
b.Websocket.TrafficAlert <- struct{}{}
|
||||
@@ -106,7 +106,7 @@ func (b *Bitstamp) WsHandleData() {
|
||||
switch wsResponse.Event {
|
||||
case "bts:request_reconnect":
|
||||
if b.Verbose {
|
||||
log.Debugf("%v - Websocket reconnection request received", b.GetName())
|
||||
log.Debugf(log.ExchangeSys, "%v - Websocket reconnection request received", b.GetName())
|
||||
}
|
||||
go b.Websocket.WebsocketReset()
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ func (b *Bitstamp) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the Bitstamp wrapper
|
||||
func (b *Bitstamp) Run() {
|
||||
if b.Verbose {
|
||||
log.Debugf("%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
||||
log.Debugf(log.ExchangeSys, "%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
||||
b.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ func (b *Bitstamp) Run() {
|
||||
|
||||
err := b.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,7 +489,7 @@ func (b *Bitstamp) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest)
|
||||
case order.XRP > 0:
|
||||
baseCurrency = currency.XRP
|
||||
default:
|
||||
log.Warnf("no base currency found for OrderID '%v'", order.OrderID)
|
||||
log.Warnf(log.ExchangeSys, "no base currency found for OrderID '%v'", order.OrderID)
|
||||
}
|
||||
|
||||
switch {
|
||||
@@ -498,7 +498,7 @@ func (b *Bitstamp) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest)
|
||||
case order.EUR > 0:
|
||||
quoteCurrency = currency.EUR
|
||||
default:
|
||||
log.Warnf("no quote currency found for orderID '%v'", order.OrderID)
|
||||
log.Warnf(log.ExchangeSys, "no quote currency found for orderID '%v'", order.OrderID)
|
||||
}
|
||||
|
||||
var currPair currency.Pair
|
||||
|
||||
@@ -119,11 +119,11 @@ func (b *Bittrex) Run() {
|
||||
!common.StringDataContains(b.GetAvailablePairs(asset.Spot).Strings(), "-") {
|
||||
forceUpdate = true
|
||||
enabledPairs := []string{"USDT-BTC"}
|
||||
log.Warn("WARNING: Available pairs for Bittrex reset due to config upgrade, please enable the ones you would like again")
|
||||
log.Warn(log.ExchangeSys, "Available pairs for Bittrex reset due to config upgrade, please enable the ones you would like again")
|
||||
|
||||
err := b.UpdatePairs(currency.NewPairsFromStrings(enabledPairs), asset.Spot, true, true)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update currencies. Err: %s\n", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update currencies. Err: %s\n", b.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ func (b *Bittrex) Run() {
|
||||
|
||||
err := b.UpdateTradablePairs(forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ func (b *Bittrex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
for i := range resp.Result {
|
||||
orderDate, err := time.Parse(time.RFC3339, resp.Result[i].Opened)
|
||||
if err != nil {
|
||||
log.Warnf("Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
b.Name, "GetActiveOrders", resp.Result[i].OrderUUID, resp.Result[i].Opened)
|
||||
}
|
||||
|
||||
@@ -468,7 +468,7 @@ func (b *Bittrex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
for i := range resp.Result {
|
||||
orderDate, err := time.Parse(time.RFC3339, resp.Result[i].TimeStamp)
|
||||
if err != nil {
|
||||
log.Warnf("Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
b.Name, "GetActiveOrders", resp.Result[i].OrderUUID, resp.Result[i].Opened)
|
||||
}
|
||||
|
||||
|
||||
@@ -393,7 +393,7 @@ func (b *BTCMarkets) SendAuthenticatedRequest(reqType, path string, data, result
|
||||
[]byte(req), []byte(b.API.Credentials.Secret))
|
||||
|
||||
if b.Verbose {
|
||||
log.Debugf("Sending %s request to URL %s with params %s\n",
|
||||
log.Debugf(log.ExchangeSys, "Sending %s request to URL %s with params %s\n",
|
||||
reqType,
|
||||
b.API.Endpoints.URL+path,
|
||||
req)
|
||||
|
||||
@@ -118,12 +118,12 @@ func (b *BTCMarkets) Run() {
|
||||
if !common.StringDataContains(b.GetEnabledPairs(asset.Spot).Strings(), "-") ||
|
||||
!common.StringDataContains(b.GetAvailablePairs(asset.Spot).Strings(), "-") {
|
||||
enabledPairs := []string{"BTC-AUD"}
|
||||
log.Println("WARNING: Available pairs for BTC Makrets reset due to config upgrade, please enable the pairs you would like again.")
|
||||
log.Warnln(log.ExchangeSys, "Available pairs for BTC Markets reset due to config upgrade, please enable the pairs you would like again.")
|
||||
forceUpdate = true
|
||||
|
||||
err := b.UpdatePairs(currency.NewPairsFromStrings(enabledPairs), asset.Spot, true, true)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update currencies. Err: %s", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update currencies. Err: %s", b.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ func (b *BTCMarkets) Run() {
|
||||
|
||||
err := b.UpdateTradablePairs(forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -203,7 +203,7 @@ func (b *BTSE) SendAuthenticatedHTTPRequest(method, endpoint string, req map[str
|
||||
|
||||
p := fmt.Sprintf("%s/%s", b.API.Endpoints.URL, endpoint)
|
||||
if b.Verbose {
|
||||
log.Debugf("Sending %s request to URL %s with params %s\n", method, p, string(payload))
|
||||
log.Debugf(log.ExchangeSys, "Sending %s request to URL %s with params %s\n", method, p, string(payload))
|
||||
}
|
||||
return b.SendPayload(method, p, headers, strings.NewReader(string(payload)),
|
||||
&result, true, false, b.Verbose, b.HTTPDebugging)
|
||||
|
||||
@@ -93,7 +93,7 @@ func (b *BTSE) WsHandleData() {
|
||||
|
||||
if strings.Contains(string(resp.Raw), "Welcome to BTSE") {
|
||||
if b.Verbose {
|
||||
log.Debugf("%s websocket client successfully connected to %s",
|
||||
log.Debugf(log.ExchangeSys, "%s websocket client successfully connected to %s",
|
||||
b.Name, b.Websocket.GetWebsocketURL())
|
||||
}
|
||||
continue
|
||||
@@ -252,7 +252,7 @@ func (b *BTSE) wsSend(data interface{}) error {
|
||||
b.wsRequestMtx.Lock()
|
||||
defer b.wsRequestMtx.Unlock()
|
||||
if b.Verbose {
|
||||
log.Debugf("%v sending message to websocket %v", b.Name, data)
|
||||
log.Debugf(log.ExchangeSys, "%v sending message to websocket %v", b.Name, data)
|
||||
}
|
||||
json, err := common.JSONEncode(data)
|
||||
if err != nil {
|
||||
|
||||
@@ -135,7 +135,7 @@ func (b *BTSE) Run() {
|
||||
|
||||
err := b.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,7 +445,7 @@ func (b *BTSE) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]e
|
||||
|
||||
fills, err := b.GetFills(order.ID, "", "", "", "")
|
||||
if err != nil {
|
||||
log.Errorf("unable to get order fills for orderID %s", order.ID)
|
||||
log.Errorf(log.ExchangeSys, "unable to get order fills for orderID %s", order.ID)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -731,7 +731,7 @@ func (c *CoinbasePro) SendAuthenticatedHTTPRequest(method, path string, params m
|
||||
}
|
||||
|
||||
if c.Verbose {
|
||||
log.Debugf("Request JSON: %s\n", payload)
|
||||
log.Debugf(log.ExchangeSys, "Request JSON: %s\n", payload)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -354,7 +354,7 @@ func (c *CoinbasePro) wsSend(data interface{}) error {
|
||||
c.wsRequestMtx.Lock()
|
||||
defer c.wsRequestMtx.Unlock()
|
||||
if c.Verbose {
|
||||
log.Debugf("%v sending message to websocket %v", c.Name, data)
|
||||
log.Debugf(log.ExchangeSys, "%v sending message to websocket %v", c.Name, data)
|
||||
}
|
||||
json, err := common.JSONEncode(data)
|
||||
if err != nil {
|
||||
|
||||
@@ -130,7 +130,7 @@ func (c *CoinbasePro) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the coinbasepro wrapper
|
||||
func (c *CoinbasePro) Run() {
|
||||
if c.Verbose {
|
||||
log.Debugf("%s Websocket: %s. (url: %s).\n", c.GetName(), common.IsEnabled(c.Websocket.IsEnabled()), coinbaseproWebsocketURL)
|
||||
log.Debugf(log.ExchangeSys, "%s Websocket: %s. (url: %s).\n", c.GetName(), common.IsEnabled(c.Websocket.IsEnabled()), coinbaseproWebsocketURL)
|
||||
c.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ func (c *CoinbasePro) Run() {
|
||||
|
||||
err := c.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", c.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", c.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,7 +434,7 @@ func (c *CoinbasePro) GetActiveOrders(getOrdersRequest *exchange.GetOrdersReques
|
||||
orderType := exchange.OrderType(strings.ToUpper(respOrders[i].Type))
|
||||
orderDate, err := time.Parse(time.RFC3339, respOrders[i].CreatedAt)
|
||||
if err != nil {
|
||||
log.Warnf("Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
c.Name, "GetActiveOrders", respOrders[i].ID, respOrders[i].CreatedAt)
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ func (c *CoinbasePro) GetOrderHistory(getOrdersRequest *exchange.GetOrdersReques
|
||||
orderType := exchange.OrderType(strings.ToUpper(respOrders[i].Type))
|
||||
orderDate, err := time.Parse(time.RFC3339, respOrders[i].CreatedAt)
|
||||
if err != nil {
|
||||
log.Warnf("Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
c.Name, "GetActiveOrders", respOrders[i].ID, respOrders[i].CreatedAt)
|
||||
}
|
||||
|
||||
|
||||
@@ -276,7 +276,7 @@ func (c *COINUT) SendHTTPRequest(apiRequest string, params map[string]interface{
|
||||
}
|
||||
|
||||
if c.Verbose {
|
||||
log.Debugf("Request JSON: %s", payload)
|
||||
log.Debugf(log.ExchangeSys, "Request JSON: %s", payload)
|
||||
}
|
||||
|
||||
headers := make(map[string]string)
|
||||
|
||||
@@ -459,7 +459,7 @@ func (c *COINUT) wsSend(data interface{}) error {
|
||||
return err
|
||||
}
|
||||
if c.Verbose {
|
||||
log.Debugf("%v sending message to websocket %v", c.Name, string(json))
|
||||
log.Debugf(log.ExchangeSys, "%v sending message to websocket %v", c.Name, string(json))
|
||||
}
|
||||
// Basic rate limiter
|
||||
time.Sleep(coinutWebsocketRateLimit)
|
||||
|
||||
@@ -128,7 +128,7 @@ func (c *COINUT) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the COINUT wrapper
|
||||
func (c *COINUT) Run() {
|
||||
if c.Verbose {
|
||||
log.Debugf("%s Websocket: %s. (url: %s).\n", c.GetName(), common.IsEnabled(c.Websocket.IsEnabled()), coinutWebsocketURL)
|
||||
log.Debugf(log.ExchangeSys, "%s Websocket: %s. (url: %s).\n", c.GetName(), common.IsEnabled(c.Websocket.IsEnabled()), coinutWebsocketURL)
|
||||
c.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ func (c *COINUT) Run() {
|
||||
|
||||
err := c.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", c.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", c.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -395,7 +395,7 @@ func (e *Base) SetAPIKeys(apiKey, apiSecret, clientID string) {
|
||||
if err != nil {
|
||||
e.API.AuthenticatedSupport = false
|
||||
e.API.AuthenticatedWebsocketSupport = false
|
||||
log.Warnf(warningBase64DecryptSecretKeyFailed, e.Name)
|
||||
log.Warnf(log.ExchangeSys, warningBase64DecryptSecretKeyFailed, e.Name)
|
||||
}
|
||||
e.API.Credentials.Secret = string(result)
|
||||
} else {
|
||||
@@ -482,7 +482,8 @@ func (e *Base) ValidateAPICredentials() bool {
|
||||
if e.API.CredentialsValidator.RequiresKey {
|
||||
if e.API.Credentials.Key == "" ||
|
||||
e.API.Credentials.Key == config.DefaultAPIKey {
|
||||
log.Warnf("exchange %s requires API key but default/empty one set",
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"exchange %s requires API key but default/empty one set",
|
||||
e.Name)
|
||||
return false
|
||||
}
|
||||
@@ -491,7 +492,8 @@ func (e *Base) ValidateAPICredentials() bool {
|
||||
if e.API.CredentialsValidator.RequiresSecret {
|
||||
if e.API.Credentials.Secret == "" ||
|
||||
e.API.Credentials.Secret == config.DefaultAPISecret {
|
||||
log.Warnf("exchange %s requires API secret but default/empty one set",
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"exchange %s requires API secret but default/empty one set",
|
||||
e.Name)
|
||||
return false
|
||||
}
|
||||
@@ -500,7 +502,8 @@ func (e *Base) ValidateAPICredentials() bool {
|
||||
if e.API.CredentialsValidator.RequiresPEM {
|
||||
if e.API.Credentials.PEMKey == "" ||
|
||||
strings.Contains(e.API.Credentials.PEMKey, "JUSTADUMMY") {
|
||||
log.Warnf("exchange %s requires API PEM key but default/empty one set",
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"exchange %s requires API PEM key but default/empty one set",
|
||||
e.Name)
|
||||
return false
|
||||
}
|
||||
@@ -509,7 +512,8 @@ func (e *Base) ValidateAPICredentials() bool {
|
||||
if e.API.CredentialsValidator.RequiresClientID {
|
||||
if e.API.Credentials.ClientID == "" ||
|
||||
e.API.Credentials.ClientID == config.DefaultAPIClientID {
|
||||
log.Warnf("exchange %s requires API ClientID but default/empty one set",
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"exchange %s requires API ClientID but default/empty one set",
|
||||
e.Name)
|
||||
return false
|
||||
}
|
||||
@@ -518,7 +522,8 @@ func (e *Base) ValidateAPICredentials() bool {
|
||||
if e.API.CredentialsValidator.RequiresBase64DecodeSecret && !e.LoadedByConfig {
|
||||
_, err := crypto.Base64Decode(e.API.Credentials.Secret)
|
||||
if err != nil {
|
||||
log.Warnf("exchange %s API secret base64 decode failed: %s",
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"exchange %s API secret base64 decode failed: %s",
|
||||
e.Name, err)
|
||||
return false
|
||||
}
|
||||
@@ -575,15 +580,18 @@ func (e *Base) UpdatePairs(exchangeProducts currency.Pairs, assetType asset.Item
|
||||
|
||||
if force || len(newPairs) > 0 || len(removedPairs) > 0 {
|
||||
if force {
|
||||
log.Debugf("%s forced update of %s [%v] pairs.", e.Name, updateType,
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s forced update of %s [%v] pairs.", e.Name, updateType,
|
||||
strings.ToUpper(assetType.String()))
|
||||
} else {
|
||||
if len(newPairs) > 0 {
|
||||
log.Debugf("%s Updating pairs [%v] - New: %s.\n", e.Name,
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s Updating pairs [%v] - New: %s.\n", e.Name,
|
||||
strings.ToUpper(assetType.String()), newPairs)
|
||||
}
|
||||
if len(removedPairs) > 0 {
|
||||
log.Debugf("%s Updating pairs [%v] - Removed: %s.\n", e.Name,
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s Updating pairs [%v] - Removed: %s.\n", e.Name,
|
||||
strings.ToUpper(assetType.String()), removedPairs)
|
||||
}
|
||||
}
|
||||
@@ -725,7 +733,7 @@ func (e *Base) IsAssetTypeSupported(asset asset.Item) bool {
|
||||
// PrintEnabledPairs prints the exchanges enabled asset pairs
|
||||
func (e *Base) PrintEnabledPairs() {
|
||||
for k, v := range e.CurrencyPairs.Pairs {
|
||||
log.Infof("%s Asset type %v:\n\t Enabled pairs: %v",
|
||||
log.Infof(log.ExchangeSys, "%s Asset type %v:\n\t Enabled pairs: %v",
|
||||
e.Name, strings.ToUpper(k.String()), v.Enabled)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ func (e *EXMO) SendAuthenticatedHTTPRequest(method, endpoint string, vals url.Va
|
||||
[]byte(e.API.Credentials.Secret))
|
||||
|
||||
if e.Verbose {
|
||||
log.Debugf("Sending %s request to %s with params %s\n",
|
||||
log.Debugf(log.ExchangeSys, "Sending %s request to %s with params %s\n",
|
||||
method,
|
||||
endpoint,
|
||||
payload)
|
||||
|
||||
@@ -122,7 +122,7 @@ func (e *EXMO) Run() {
|
||||
|
||||
err := e.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", e.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", e.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ func (g *Gateio) WsConnect() error {
|
||||
|
||||
err = g.wsServerSignIn()
|
||||
if err != nil {
|
||||
log.Errorf("%v - authentication failed: %v", g.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%v - authentication failed: %v\n", g.Name, err)
|
||||
}
|
||||
g.GenerateAuthenticatedSubscriptions()
|
||||
g.GenerateDefaultSubscriptions()
|
||||
@@ -456,7 +456,7 @@ func (g *Gateio) wsSend(data interface{}) error {
|
||||
g.wsRequestMtx.Lock()
|
||||
defer g.wsRequestMtx.Unlock()
|
||||
if g.Verbose {
|
||||
log.Debugf("%v sending message to websocket %v", g.Name, data)
|
||||
log.Debugf(log.ExchangeSys, "%v sending message to websocket %v", g.Name, data)
|
||||
}
|
||||
// Basic rate limiter
|
||||
time.Sleep(gateioWebsocketRateLimit)
|
||||
|
||||
@@ -142,7 +142,7 @@ func (g *Gateio) Run() {
|
||||
|
||||
err := g.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", g.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", g.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -433,7 +433,7 @@ func (g *Gemini) SendAuthenticatedHTTPRequest(method, path string, params map[st
|
||||
}
|
||||
|
||||
if g.Verbose {
|
||||
log.Debugf("Request JSON: %s", PayloadJSON)
|
||||
log.Debugf(log.ExchangeSys, "Request JSON: %s", PayloadJSON)
|
||||
}
|
||||
|
||||
PayloadBase64 := crypto.Base64Encode(PayloadJSON)
|
||||
|
||||
@@ -48,7 +48,7 @@ func (g *Gemini) WsConnect() error {
|
||||
go g.WsHandleData()
|
||||
err := g.WsSecureSubscribe(&dialer, geminiWsOrderEvents)
|
||||
if err != nil {
|
||||
log.Errorf("%v - authentication failed: %v", g.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%v - authentication failed: %v\n", g.Name, err)
|
||||
}
|
||||
return g.WsSubscribe(&dialer)
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ func (g *Gemini) Run() {
|
||||
|
||||
err := g.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", g.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", g.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ func (h *HitBTC) WsConnect() error {
|
||||
go h.WsHandleData()
|
||||
err = h.wsLogin()
|
||||
if err != nil {
|
||||
log.Errorf("%v - authentication failed: %v", h.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%v - authentication failed: %v\n", h.Name, err)
|
||||
}
|
||||
|
||||
h.GenerateDefaultSubscriptions()
|
||||
@@ -391,7 +391,7 @@ func (h *HitBTC) wsSend(data interface{}) error {
|
||||
return err
|
||||
}
|
||||
if h.Verbose {
|
||||
log.Debugf("%v sending message to websocket %v", h.Name, string(json))
|
||||
log.Debugf(log.ExchangeSys, "%v sending message to websocket %v", h.Name, string(json))
|
||||
}
|
||||
return h.WebsocketConn.WriteMessage(websocket.TextMessage, json)
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func (h *HitBTC) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the HitBTC wrapper
|
||||
func (h *HitBTC) Run() {
|
||||
if h.Verbose {
|
||||
log.Debugf("%s Websocket: %s (url: %s).\n", h.GetName(), common.IsEnabled(h.Websocket.IsEnabled()), hitbtcWebsocketAddress)
|
||||
log.Debugf(log.ExchangeSys, "%s Websocket: %s (url: %s).\n", h.GetName(), common.IsEnabled(h.Websocket.IsEnabled()), hitbtcWebsocketAddress)
|
||||
h.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
@@ -135,12 +135,12 @@ func (h *HitBTC) Run() {
|
||||
if !common.StringDataContains(h.GetEnabledPairs(asset.Spot).Strings(), "-") ||
|
||||
!common.StringDataContains(h.GetAvailablePairs(asset.Spot).Strings(), "-") {
|
||||
enabledPairs := []string{"BTC-USD"}
|
||||
log.Warn("WARNING: Available pairs for HitBTC reset due to config upgrade, please enable the ones you would like again.")
|
||||
log.Warn(log.ExchangeSys, "Available pairs for HitBTC reset due to config upgrade, please enable the ones you would like again.")
|
||||
forceUpdate = true
|
||||
|
||||
err := h.UpdatePairs(currency.NewPairsFromStrings(enabledPairs), asset.Spot, true, true)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update enabled currencies.\n", h.GetName())
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update enabled currencies.\n", h.GetName())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ func (h *HitBTC) Run() {
|
||||
|
||||
err := h.UpdateTradablePairs(forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", h.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", h.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,11 +72,11 @@ func (h *HUOBI) WsConnect() error {
|
||||
}
|
||||
err = h.wsAuthenticatedDial(&dialer)
|
||||
if err != nil {
|
||||
log.Errorf("%v - authenticated dial failed: %v", h.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%v - authenticated dial failed: %v\n", h.Name, err)
|
||||
}
|
||||
err = h.wsLogin()
|
||||
if err != nil {
|
||||
log.Errorf("%v - authentication failed: %v", h.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%v - authentication failed: %v\n", h.Name, err)
|
||||
}
|
||||
|
||||
go h.WsHandleData()
|
||||
@@ -156,7 +156,7 @@ func (h *HUOBI) WsHandleData() {
|
||||
return
|
||||
case resp := <-comms:
|
||||
if h.Verbose {
|
||||
log.Debugf("%v: %v: %v", h.Name, resp.URL, string(resp.Raw))
|
||||
log.Debugf(log.ExchangeSys, "%v: %v: %v", h.Name, resp.URL, string(resp.Raw))
|
||||
}
|
||||
switch resp.URL {
|
||||
case wsMarketURL:
|
||||
@@ -189,14 +189,14 @@ func (h *HUOBI) wsHandleAuthenticatedData(resp WsMessage) {
|
||||
if init.Ping != 0 {
|
||||
err = h.WebsocketConn.WriteJSON(`{"pong":1337}`)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if init.Op == "sub" {
|
||||
if h.Verbose {
|
||||
log.Debugf("%v: %v: Successfully subscribed to %v", h.Name, resp.URL, init.Topic)
|
||||
log.Debugf(log.ExchangeSys, "%v: %v: Successfully subscribed to %v", h.Name, resp.URL, init.Topic)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -277,7 +277,7 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
|
||||
if init.Ping != 0 {
|
||||
err = h.WebsocketConn.WriteJSON(`{"pong":1337}`)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -420,7 +420,7 @@ func (h *HUOBI) wsSend(data []byte) error {
|
||||
h.wsRequestMtx.Lock()
|
||||
defer h.wsRequestMtx.Unlock()
|
||||
if h.Verbose {
|
||||
log.Debugf("%v sending message to websocket %s", h.Name, string(data))
|
||||
log.Debugf(log.ExchangeSys, "%v sending message to websocket %s", h.Name, string(data))
|
||||
}
|
||||
return h.WebsocketConn.WriteMessage(websocket.TextMessage, data)
|
||||
}
|
||||
@@ -456,7 +456,7 @@ func (h *HUOBI) wsAuthenticatedSend(request interface{}) error {
|
||||
return err
|
||||
}
|
||||
if h.Verbose {
|
||||
log.Debugf("%v sending Authenticated message to websocket %s", h.Name, string(encodedRequest))
|
||||
log.Debugf(log.ExchangeSys, "%v sending Authenticated message to websocket %s", h.Name, string(encodedRequest))
|
||||
}
|
||||
return h.AuthenticatedWebsocketConn.WriteMessage(websocket.TextMessage, encodedRequest)
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ func (h *HUOBI) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the HUOBI wrapper
|
||||
func (h *HUOBI) Run() {
|
||||
if h.Verbose {
|
||||
log.Debugf("%s Websocket: %s (url: %s).\n", h.GetName(), common.IsEnabled(h.Websocket.IsEnabled()), wsMarketURL)
|
||||
log.Debugf(log.ExchangeSys, "%s Websocket: %s (url: %s).\n", h.GetName(), common.IsEnabled(h.Websocket.IsEnabled()), wsMarketURL)
|
||||
h.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ func (h *HUOBI) Run() {
|
||||
cfg := config.GetConfig()
|
||||
exchCfg, err := cfg.GetExchangeConfig(h.Name)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to get exchange config. %s\n", h.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to get exchange config. %s\n", h.Name, err)
|
||||
return
|
||||
}
|
||||
exchCfg.BaseCurrencies = currency.Currencies{currency.USD}
|
||||
@@ -162,11 +162,11 @@ func (h *HUOBI) Run() {
|
||||
Delimiter: "-",
|
||||
},
|
||||
}
|
||||
log.Warn("WARNING: Available and enabled pairs for Huobi reset due to config upgrade, please enable the ones you would like again")
|
||||
log.Warn(log.ExchangeSys, "Available and enabled pairs for Huobi reset due to config upgrade, please enable the ones you would like again")
|
||||
|
||||
err := h.UpdatePairs(enabledPairs, asset.Spot, true, true)
|
||||
if err != nil {
|
||||
log.Errorf("%s Failed to update enabled currencies.\n", h.GetName())
|
||||
log.Errorf(log.ExchangeSys, "%s Failed to update enabled currencies.\n", h.GetName())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ func (h *HUOBI) Run() {
|
||||
|
||||
err := h.UpdateTradablePairs(forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", h.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", h.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/common/crypto"
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||
log "github.com/thrasher-/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -330,7 +331,7 @@ func (h *HUOBIHADAX) SpotNewOrder(arg SpotNewOrderRequestParams) (int64, error)
|
||||
bytesParams, _ := json.Marshal(vals)
|
||||
postBodyParams := string(bytesParams)
|
||||
if h.Verbose {
|
||||
fmt.Println("Post params:", postBodyParams)
|
||||
log.Debugf(log.ExchangeSys, "Post params: %v", postBodyParams)
|
||||
}
|
||||
|
||||
var result response
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package huobihadax
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -276,7 +275,7 @@ func TestSpotNewOrder(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Test failed - Huobi SpotNewOrder: %s", err)
|
||||
} else {
|
||||
fmt.Println(newOrderID)
|
||||
t.Log(newOrderID)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,11 +72,11 @@ func (h *HUOBIHADAX) WsConnect() error {
|
||||
}
|
||||
err = h.wsAuthenticatedDial(&dialer)
|
||||
if err != nil {
|
||||
log.Errorf("%v - authenticated dial failed: %v", h.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%v - authenticated dial failed: %v\n", h.Name, err)
|
||||
}
|
||||
err = h.wsLogin()
|
||||
if err != nil {
|
||||
log.Errorf("%v - authentication failed: %v", h.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%v - authentication failed: %v\n", h.Name, err)
|
||||
}
|
||||
|
||||
go h.WsHandleData()
|
||||
@@ -156,7 +156,7 @@ func (h *HUOBIHADAX) WsHandleData() {
|
||||
return
|
||||
case resp := <-comms:
|
||||
if h.Verbose {
|
||||
log.Debugf("%v: %v: %v", h.Name, resp.URL, string(resp.Raw))
|
||||
log.Debugf(log.ExchangeSys, "%v: %v: %v", h.Name, resp.URL, string(resp.Raw))
|
||||
}
|
||||
switch resp.URL {
|
||||
case HuobiHadaxSocketIOAddress:
|
||||
@@ -189,14 +189,14 @@ func (h *HUOBIHADAX) wsHandleAuthenticatedData(resp WsMessage) {
|
||||
if init.Ping != 0 {
|
||||
err = h.WebsocketConn.WriteJSON(`{"pong":1337}`)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if init.Op == "sub" {
|
||||
if h.Verbose {
|
||||
log.Debugf("%v: %v: Successfully subscribed to %v", h.Name, resp.URL, init.Topic)
|
||||
log.Debugf(log.ExchangeSys, "%v: %v: Successfully subscribed to %v", h.Name, resp.URL, init.Topic)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -277,7 +277,7 @@ func (h *HUOBIHADAX) wsHandleMarketData(resp WsMessage) {
|
||||
if init.Ping != 0 {
|
||||
err = h.WebsocketConn.WriteJSON(`{"pong":1337}`)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -420,7 +420,7 @@ func (h *HUOBIHADAX) wsSend(data []byte) error {
|
||||
h.wsRequestMtx.Lock()
|
||||
defer h.wsRequestMtx.Unlock()
|
||||
if h.Verbose {
|
||||
log.Debugf("%v sending message to websocket %s", h.Name, string(data))
|
||||
log.Debugf(log.ExchangeSys, "%v sending message to websocket %s", h.Name, string(data))
|
||||
}
|
||||
return h.WebsocketConn.WriteMessage(websocket.TextMessage, data)
|
||||
}
|
||||
@@ -456,7 +456,7 @@ func (h *HUOBIHADAX) wsAuthenticatedSend(request interface{}) error {
|
||||
return err
|
||||
}
|
||||
if h.Verbose {
|
||||
log.Debugf("%v sending Authenticated message to websocket %s", h.Name, string(encodedRequest))
|
||||
log.Debugf(log.ExchangeSys, "%v sending Authenticated message to websocket %s", h.Name, string(encodedRequest))
|
||||
}
|
||||
return h.AuthenticatedWebsocketConn.WriteMessage(websocket.TextMessage, encodedRequest)
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ func (h *HUOBIHADAX) Run() {
|
||||
|
||||
err := h.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", h.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", h.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -302,7 +302,7 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method, path string, params map[str
|
||||
}
|
||||
|
||||
if i.Verbose {
|
||||
log.Debugf("Request JSON: %s\n", PayloadJSON)
|
||||
log.Debugf(log.ExchangeSys, "Request JSON: %s\n", PayloadJSON)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -424,7 +424,7 @@ func (i *ItBit) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]
|
||||
side := exchange.OrderSide(strings.ToUpper(allOrders[j].Side))
|
||||
orderDate, err := time.Parse(time.RFC3339, allOrders[j].CreatedTime)
|
||||
if err != nil {
|
||||
log.Warnf("Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
i.Name, "GetActiveOrders", allOrders[j].ID, allOrders[j].CreatedTime)
|
||||
}
|
||||
|
||||
@@ -475,7 +475,7 @@ func (i *ItBit) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]
|
||||
side := exchange.OrderSide(strings.ToUpper(allOrders[j].Side))
|
||||
orderDate, err := time.Parse(time.RFC3339, allOrders[j].CreatedTime)
|
||||
if err != nil {
|
||||
log.Warnf("Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
i.Name, "GetActiveOrders", allOrders[j].ID, allOrders[j].CreatedTime)
|
||||
}
|
||||
|
||||
|
||||
@@ -835,7 +835,7 @@ func GetError(apiErrors []string) error {
|
||||
for _, e := range apiErrors {
|
||||
switch e[0] {
|
||||
case 'W':
|
||||
log.Warnf("%s API warning: %v\n", exchangeName, e[1:])
|
||||
log.Warnf(log.ExchangeSys, "%s API warning: %v\n", exchangeName, e[1:])
|
||||
default:
|
||||
return fmt.Errorf("%s API error: %v", exchangeName, e[1:])
|
||||
}
|
||||
@@ -865,7 +865,7 @@ func (k *Kraken) SendAuthenticatedHTTPRequest(method string, params url.Values,
|
||||
append([]byte(path), shasum...), []byte(k.API.Credentials.Secret)))
|
||||
|
||||
if k.Verbose {
|
||||
log.Debugf("Sending POST request to %s, path: %s, params: %s",
|
||||
log.Debugf(log.ExchangeSys, "Sending POST request to %s, path: %s, params: %s",
|
||||
k.API.Endpoints.URL,
|
||||
path,
|
||||
encoded)
|
||||
|
||||
@@ -72,7 +72,7 @@ func (k *Kraken) writeToWebsocket(message []byte) error {
|
||||
k.wsRequestMtx.Lock()
|
||||
defer k.wsRequestMtx.Unlock()
|
||||
if k.Verbose {
|
||||
log.Debugf("Sending message to WS: %v",
|
||||
log.Debugf(log.ExchangeSys, "Sending message to WS: %v",
|
||||
string(message))
|
||||
}
|
||||
// Really basic WS rate limit
|
||||
@@ -98,7 +98,7 @@ func (k *Kraken) WsConnect() error {
|
||||
|
||||
var err error
|
||||
if k.Verbose {
|
||||
log.Debugf("Attempting to connect to %v",
|
||||
log.Debugf(log.ExchangeSys, "Attempting to connect to %v",
|
||||
k.Websocket.GetWebsocketURL())
|
||||
}
|
||||
k.WebsocketConn, _, err = dialer.Dial(k.Websocket.GetWebsocketURL(),
|
||||
@@ -109,7 +109,7 @@ func (k *Kraken) WsConnect() error {
|
||||
err)
|
||||
}
|
||||
if k.Verbose {
|
||||
log.Debugf("Successful connection to %v",
|
||||
log.Debugf(log.ExchangeSys, "Successful connection to %v",
|
||||
k.Websocket.GetWebsocketURL())
|
||||
}
|
||||
go k.WsHandleData()
|
||||
@@ -142,7 +142,7 @@ func (k *Kraken) WsReadData() (exchange.WebsocketResponse, error) {
|
||||
}
|
||||
}
|
||||
if k.Verbose {
|
||||
log.Debugf("%v Websocket message received: %v",
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket message received: %v",
|
||||
k.Name,
|
||||
string(standardMessage))
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func (k *Kraken) wsPingHandler() {
|
||||
case <-ticker.C:
|
||||
pingEvent := fmt.Sprintf("{\"event\":\"%v\"}", krakenWsPing)
|
||||
if k.Verbose {
|
||||
log.Debugf("%v sending ping",
|
||||
log.Debugf(log.ExchangeSys, "%v sending ping",
|
||||
k.GetName())
|
||||
}
|
||||
err := k.writeToWebsocket([]byte(pingEvent))
|
||||
@@ -221,36 +221,36 @@ func (k *Kraken) WsHandleDataResponse(response WebsocketDataResponse) {
|
||||
switch channelData.Subscription {
|
||||
case krakenWsTicker:
|
||||
if k.Verbose {
|
||||
log.Debugf("%v Websocket ticker data received",
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket ticker data received",
|
||||
k.GetName())
|
||||
}
|
||||
k.wsProcessTickers(&channelData, response[1])
|
||||
case krakenWsOHLC:
|
||||
if k.Verbose {
|
||||
log.Debugf("%v Websocket OHLC data received",
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket OHLC data received",
|
||||
k.GetName())
|
||||
}
|
||||
k.wsProcessCandles(&channelData, response[1])
|
||||
case krakenWsOrderbook:
|
||||
if k.Verbose {
|
||||
log.Debugf("%v Websocket Orderbook data received",
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket Orderbook data received",
|
||||
k.GetName())
|
||||
}
|
||||
k.wsProcessOrderBook(&channelData, response[1])
|
||||
case krakenWsSpread:
|
||||
if k.Verbose {
|
||||
log.Debugf("%v Websocket Spread data received",
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket Spread data received",
|
||||
k.GetName())
|
||||
}
|
||||
k.wsProcessSpread(&channelData, response[1])
|
||||
case krakenWsTrade:
|
||||
if k.Verbose {
|
||||
log.Debugf("%v Websocket Trade data received",
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket Trade data received",
|
||||
k.GetName())
|
||||
}
|
||||
k.wsProcessTrades(&channelData, response[1])
|
||||
default:
|
||||
log.Errorf("%v Unidentified websocket data received: %v",
|
||||
log.Errorf(log.ExchangeSys, "%v Unidentified websocket data received: %v",
|
||||
k.GetName(), response)
|
||||
}
|
||||
}
|
||||
@@ -260,17 +260,17 @@ func (k *Kraken) WsHandleEventResponse(response *WebsocketEventResponse) {
|
||||
switch response.Event {
|
||||
case krakenWsHeartbeat:
|
||||
if k.Verbose {
|
||||
log.Debugf("%v Websocket heartbeat data received",
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket heartbeat data received",
|
||||
k.GetName())
|
||||
}
|
||||
case krakenWsPong:
|
||||
if k.Verbose {
|
||||
log.Debugf("%v Websocket pong data received",
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket pong data received",
|
||||
k.GetName())
|
||||
}
|
||||
case krakenWsSystemStatus:
|
||||
if k.Verbose {
|
||||
log.Debugf("%v Websocket status data received",
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket status data received",
|
||||
k.GetName())
|
||||
}
|
||||
if response.Status != "online" {
|
||||
@@ -278,12 +278,12 @@ func (k *Kraken) WsHandleEventResponse(response *WebsocketEventResponse) {
|
||||
k.GetName(), response.Status)
|
||||
}
|
||||
if response.WebsocketStatusResponse.Version != krakenWSSupportedVersion {
|
||||
log.Warnf("%v New version of Websocket API released. Was %v Now %v",
|
||||
log.Warnf(log.ExchangeSys, "%v New version of Websocket API released. Was %v Now %v",
|
||||
k.GetName(), krakenWSSupportedVersion, response.WebsocketStatusResponse.Version)
|
||||
}
|
||||
case krakenWsSubscriptionStatus:
|
||||
if k.Verbose {
|
||||
log.Debugf("%v Websocket subscription status data received",
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket subscription status data received",
|
||||
k.GetName())
|
||||
}
|
||||
if response.Status != "subscribed" {
|
||||
@@ -296,7 +296,7 @@ func (k *Kraken) WsHandleEventResponse(response *WebsocketEventResponse) {
|
||||
}
|
||||
addNewSubscriptionChannelData(response)
|
||||
default:
|
||||
log.Errorf("%v Unidentified websocket data received: %v", k.GetName(), response)
|
||||
log.Errorf(log.ExchangeSys, "%v Unidentified websocket data received: %v", k.GetName(), response)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ func (k *Kraken) wsProcessSpread(channelData *WebsocketChannelData, data interfa
|
||||
sec, dec := math.Modf(timeData)
|
||||
spreadTimestamp := time.Unix(int64(sec), int64(dec*(1e9)))
|
||||
if k.Verbose {
|
||||
log.Debugf("Spread data for '%v' received. Best bid: '%v' Best ask: '%v' Time: '%v'",
|
||||
log.Debugf(log.ExchangeSys, "Spread data for '%v' received. Best bid: '%v' Best ask: '%v' Time: '%v'",
|
||||
channelData.Pair,
|
||||
bestBid,
|
||||
bestAsk,
|
||||
@@ -550,7 +550,7 @@ func (k *Kraken) wsProcessOrderBookBuffer(channelData *WebsocketChannelData, obD
|
||||
}
|
||||
orderbookBuffer[channelData.ChannelID] = append(orderbookBuffer[channelData.ChannelID], ob)
|
||||
if k.Verbose {
|
||||
log.Debugf("Adding orderbook to buffer for channel %v. Lastupdated: %v. %v / %v",
|
||||
log.Debugf(log.ExchangeSys, "Adding orderbook to buffer for channel %v. Lastupdated: %v. %v / %v",
|
||||
channelData.ChannelID,
|
||||
ob.LastUpdated,
|
||||
len(orderbookBuffer[channelData.ChannelID]),
|
||||
@@ -561,12 +561,12 @@ func (k *Kraken) wsProcessOrderBookBuffer(channelData *WebsocketChannelData, obD
|
||||
// wsProcessOrderBookUpdate updates an orderbook entry for a given currency pair
|
||||
func (k *Kraken) wsProcessOrderBookUpdate(channelData *WebsocketChannelData) error {
|
||||
if k.Verbose {
|
||||
log.Debugf("Current orderbook 'LastUpdated': %v",
|
||||
log.Debugf(log.ExchangeSys, "Current orderbook 'LastUpdated': %v",
|
||||
krakenOrderBooks[channelData.ChannelID].LastUpdated)
|
||||
}
|
||||
lowestLastUpdated := orderbookBuffer[channelData.ChannelID][0].LastUpdated
|
||||
if k.Verbose {
|
||||
log.Debugf("Sorting orderbook. Earliest 'LastUpdated' entry: %v",
|
||||
log.Debugf(log.ExchangeSys, "Sorting orderbook. Earliest 'LastUpdated' entry: %v",
|
||||
lowestLastUpdated)
|
||||
}
|
||||
sort.Slice(orderbookBuffer[channelData.ChannelID], func(i, j int) bool {
|
||||
@@ -575,7 +575,7 @@ func (k *Kraken) wsProcessOrderBookUpdate(channelData *WebsocketChannelData) err
|
||||
|
||||
lowestLastUpdated = orderbookBuffer[channelData.ChannelID][0].LastUpdated
|
||||
if k.Verbose {
|
||||
log.Debugf("Sorted orderbook. Earliest 'LastUpdated' entry: %v",
|
||||
log.Debugf(log.ExchangeSys, "Sorted orderbook. Earliest 'LastUpdated' entry: %v",
|
||||
lowestLastUpdated)
|
||||
}
|
||||
// The earliest update has to be after the previously stored orderbook
|
||||
@@ -590,7 +590,7 @@ func (k *Kraken) wsProcessOrderBookUpdate(channelData *WebsocketChannelData) err
|
||||
k.updateChannelOrderbookEntries(channelData)
|
||||
highestLastUpdate := orderbookBuffer[channelData.ChannelID][len(orderbookBuffer[channelData.ChannelID])-1].LastUpdated
|
||||
if k.Verbose {
|
||||
log.Debugf("Saving orderbook. Lastupdated: %v",
|
||||
log.Debugf(log.ExchangeSys, "Saving orderbook. Lastupdated: %v",
|
||||
highestLastUpdate)
|
||||
}
|
||||
|
||||
@@ -627,7 +627,7 @@ func (k *Kraken) updateChannelOrderbookAsks(i, j int, channelData *WebsocketChan
|
||||
askFound := k.updateChannelOrderbookAsk(i, j, channelData)
|
||||
if !askFound {
|
||||
if k.Verbose {
|
||||
log.Debugf("Adding Ask for channel %v. Price %v. Amount %v",
|
||||
log.Debugf(log.ExchangeSys, "Adding Ask for channel %v. Price %v. Amount %v",
|
||||
channelData.ChannelID,
|
||||
orderbookBuffer[channelData.ChannelID][i].Asks[j].Price,
|
||||
orderbookBuffer[channelData.ChannelID][i].Asks[j].Amount)
|
||||
@@ -646,7 +646,7 @@ func (k *Kraken) updateChannelOrderbookAsk(i, j int, channelData *WebsocketChann
|
||||
if orderbookBuffer[channelData.ChannelID][i].Asks[j].Amount == 0 {
|
||||
// Remove existing entry
|
||||
if k.Verbose {
|
||||
log.Debugf("Removing Ask for channel %v. Price %v. Old amount %v. Buffer %v",
|
||||
log.Debugf(log.ExchangeSys, "Removing Ask for channel %v. Price %v. Old amount %v. Buffer %v",
|
||||
channelData.ChannelID,
|
||||
orderbookBuffer[channelData.ChannelID][i].Asks[j].Price,
|
||||
krakenOrderBooks[channelData.ChannelID].Asks[l].Amount, i)
|
||||
@@ -657,7 +657,7 @@ func (k *Kraken) updateChannelOrderbookAsk(i, j int, channelData *WebsocketChann
|
||||
l--
|
||||
} else if krakenOrderBooks[channelData.ChannelID].Asks[l].Amount != orderbookBuffer[channelData.ChannelID][i].Asks[j].Amount {
|
||||
if k.Verbose {
|
||||
log.Debugf("Updating Ask for channel %v. Price %v. Old amount %v, New Amount %v",
|
||||
log.Debugf(log.ExchangeSys, "Updating Ask for channel %v. Price %v. Old amount %v, New Amount %v",
|
||||
channelData.ChannelID,
|
||||
orderbookBuffer[channelData.ChannelID][i].Asks[j].Price,
|
||||
krakenOrderBooks[channelData.ChannelID].Asks[l].Amount,
|
||||
@@ -675,7 +675,7 @@ func (k *Kraken) updateChannelOrderbookBids(i, j int, channelData *WebsocketChan
|
||||
bidFound := k.updateChannelOrderbookBid(i, j, channelData)
|
||||
if !bidFound {
|
||||
if k.Verbose {
|
||||
log.Debugf("Adding Bid for channel %v. Price %v. Amount %v",
|
||||
log.Debugf(log.ExchangeSys, "Adding Bid for channel %v. Price %v. Amount %v",
|
||||
channelData.ChannelID,
|
||||
orderbookBuffer[channelData.ChannelID][i].Bids[j].Price,
|
||||
orderbookBuffer[channelData.ChannelID][i].Bids[j].Amount)
|
||||
@@ -694,7 +694,7 @@ func (k *Kraken) updateChannelOrderbookBid(i, j int, channelData *WebsocketChann
|
||||
if orderbookBuffer[channelData.ChannelID][i].Bids[j].Amount == 0 {
|
||||
// Remove existing entry
|
||||
if k.Verbose {
|
||||
log.Debugf("Removing Bid for channel %v. Price %v. Old amount %v. Buffer %v",
|
||||
log.Debugf(log.ExchangeSys, "Removing Bid for channel %v. Price %v. Old amount %v. Buffer %v",
|
||||
channelData.ChannelID,
|
||||
orderbookBuffer[channelData.ChannelID][i].Bids[j].Price,
|
||||
krakenOrderBooks[channelData.ChannelID].Bids[l].Amount, i)
|
||||
@@ -705,7 +705,7 @@ func (k *Kraken) updateChannelOrderbookBid(i, j int, channelData *WebsocketChann
|
||||
l--
|
||||
} else if krakenOrderBooks[channelData.ChannelID].Bids[l].Amount != orderbookBuffer[channelData.ChannelID][i].Bids[j].Amount {
|
||||
if k.Verbose {
|
||||
log.Debugf("Updating Bid for channel %v. Price %v. Old amount %v, New Amount %v",
|
||||
log.Debugf(log.ExchangeSys, "Updating Bid for channel %v. Price %v. Old amount %v, New Amount %v",
|
||||
channelData.ChannelID,
|
||||
orderbookBuffer[channelData.ChannelID][i].Bids[j].Price,
|
||||
krakenOrderBooks[channelData.ChannelID].Bids[l].Amount,
|
||||
@@ -777,7 +777,7 @@ func (k *Kraken) Subscribe(channelToSubscribe exchange.WebsocketChannelSubscript
|
||||
json, err := common.JSONEncode(resp)
|
||||
if err != nil {
|
||||
if k.Verbose {
|
||||
log.Debugf("%v subscribe error: %v", k.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%v subscribe error: %v", k.Name, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -796,7 +796,7 @@ func (k *Kraken) Unsubscribe(channelToSubscribe exchange.WebsocketChannelSubscri
|
||||
json, err := common.JSONEncode(resp)
|
||||
if err != nil {
|
||||
if k.Verbose {
|
||||
log.Debugf("%v unsubscribe error: %v", k.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%v unsubscribe error: %v", k.Name, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -143,12 +143,12 @@ func (k *Kraken) Run() {
|
||||
if !common.StringDataContains(k.GetEnabledPairs(asset.Spot).Strings(), "-") ||
|
||||
!common.StringDataContains(k.GetAvailablePairs(asset.Spot).Strings(), "-") {
|
||||
enabledPairs := currency.NewPairsFromStrings([]string{"XBT-USD"})
|
||||
log.Warn("WARNING: Available pairs for Kraken reset due to config upgrade, please enable the ones you would like again")
|
||||
log.Warn(log.ExchangeSys, "Available pairs for Kraken reset due to config upgrade, please enable the ones you would like again")
|
||||
forceUpdate = true
|
||||
|
||||
err := k.UpdatePairs(enabledPairs, asset.Spot, true, true)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update currencies. Err: %s\n", k.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update currencies. Err: %s\n", k.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ func (k *Kraken) Run() {
|
||||
|
||||
err := k.UpdateTradablePairs(forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", k.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", k.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,12 +93,12 @@ func (l *LakeBTC) GetOrderBook(currency string) (Orderbook, error) {
|
||||
for _, x := range resp.Bids {
|
||||
price, err := strconv.ParseFloat(x[0], 64)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
amount, err := strconv.ParseFloat(x[1], 64)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
orderbook.Bids = append(orderbook.Bids, OrderbookStructure{price, amount})
|
||||
@@ -107,12 +107,12 @@ func (l *LakeBTC) GetOrderBook(currency string) (Orderbook, error) {
|
||||
for _, x := range resp.Asks {
|
||||
price, err := strconv.ParseFloat(x[0], 64)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
amount, err := strconv.ParseFloat(x[1], 64)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
orderbook.Asks = append(orderbook.Asks, OrderbookStructure{price, amount})
|
||||
@@ -265,7 +265,7 @@ func (l *LakeBTC) SendAuthenticatedHTTPRequest(method, params string, result int
|
||||
hmac := crypto.GetHMAC(crypto.HashSHA1, []byte(req), []byte(l.API.Credentials.Secret))
|
||||
|
||||
if l.Verbose {
|
||||
log.Debugf("Sending POST request to %s calling method %s with params %s\n", l.API.Endpoints.URL, method, req)
|
||||
log.Debugf(log.ExchangeSys, "Sending POST request to %s calling method %s with params %s\n", l.API.Endpoints.URL, method, req)
|
||||
}
|
||||
|
||||
postData := make(map[string]interface{})
|
||||
|
||||
@@ -120,7 +120,7 @@ func (l *LakeBTC) Run() {
|
||||
|
||||
err := l.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", l.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", l.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -635,12 +635,12 @@ func (l *LocalBitcoins) GetOrderbook(currency string) (Orderbook, error) {
|
||||
for _, x := range resp.Bids {
|
||||
price, err := strconv.ParseFloat(x[0], 64)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
amount, err := strconv.ParseFloat(x[1], 64)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
orderbook.Bids = append(orderbook.Bids, Price{price, amount})
|
||||
@@ -649,12 +649,12 @@ func (l *LocalBitcoins) GetOrderbook(currency string) (Orderbook, error) {
|
||||
for _, x := range resp.Asks {
|
||||
price, err := strconv.ParseFloat(x[0], 64)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
amount, err := strconv.ParseFloat(x[1], 64)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
orderbook.Asks = append(orderbook.Asks, Price{price, amount})
|
||||
@@ -688,7 +688,7 @@ func (l *LocalBitcoins) SendAuthenticatedHTTPRequest(method, path string, params
|
||||
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||
|
||||
if l.Verbose {
|
||||
log.Debugf("Sending POST request to `%s`, path: `%s`, params: `%s`.", l.API.Endpoints.URL, path, encoded)
|
||||
log.Debugf(log.ExchangeSys, "Sending POST request to `%s`, path: `%s`, params: `%s`.", l.API.Endpoints.URL, path, encoded)
|
||||
}
|
||||
|
||||
if method == http.MethodGet && len(encoded) > 0 {
|
||||
|
||||
@@ -121,7 +121,7 @@ func (l *LocalBitcoins) Run() {
|
||||
|
||||
err := l.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", l.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", l.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,7 +420,7 @@ func (l *LocalBitcoins) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequ
|
||||
for i := range resp {
|
||||
orderDate, err := time.Parse(time.RFC3339, resp[i].Data.CreatedAt)
|
||||
if err != nil {
|
||||
log.Warnf("Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
l.Name,
|
||||
"GetActiveOrders",
|
||||
resp[i].Data.Advertisement.ID,
|
||||
@@ -481,7 +481,7 @@ func (l *LocalBitcoins) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequ
|
||||
for i := range allTrades {
|
||||
orderDate, err := time.Parse(time.RFC3339, allTrades[i].Data.CreatedAt)
|
||||
if err != nil {
|
||||
log.Warnf("Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
l.Name,
|
||||
"GetActiveOrders",
|
||||
allTrades[i].Data.Advertisement.ID,
|
||||
|
||||
@@ -113,7 +113,7 @@ func (o *OKCoin) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the OKEX wrapper
|
||||
func (o *OKCoin) Run() {
|
||||
if o.Verbose {
|
||||
log.Debugf("%s Websocket: %s. (url: %s).\n", o.GetName(), common.IsEnabled(o.Websocket.IsEnabled()), o.WebsocketURL)
|
||||
log.Debugf(log.ExchangeSys, "%s Websocket: %s. (url: %s).\n", o.GetName(), common.IsEnabled(o.Websocket.IsEnabled()), o.WebsocketURL)
|
||||
}
|
||||
|
||||
if !o.GetEnabledFeatures().AutoPairUpdates {
|
||||
@@ -122,7 +122,7 @@ func (o *OKCoin) Run() {
|
||||
|
||||
err := o.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", o.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", o.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ func (o *OKEX) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the OKEX wrapper
|
||||
func (o *OKEX) Run() {
|
||||
if o.Verbose {
|
||||
log.Debugf("%s Websocket: %s. (url: %s).\n", o.GetName(), common.IsEnabled(o.Websocket.IsEnabled()), o.API.Endpoints.WebsocketURL)
|
||||
log.Debugf(log.ExchangeSys, "%s Websocket: %s. (url: %s).\n", o.GetName(), common.IsEnabled(o.Websocket.IsEnabled()), o.API.Endpoints.WebsocketURL)
|
||||
}
|
||||
|
||||
if !o.GetEnabledFeatures().AutoPairUpdates {
|
||||
@@ -122,7 +122,7 @@ func (o *OKEX) Run() {
|
||||
|
||||
err := o.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", o.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", o.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -495,7 +495,7 @@ func (o *OKGroup) GetMarginTransactionDetails(request GetSpotTransactionDetailsR
|
||||
func FormatParameters(request interface{}) (parameters string) {
|
||||
v, err := query.Values(request)
|
||||
if err != nil {
|
||||
log.Errorf("Could not parse %v to URL values. Check that the type has url fields", reflect.TypeOf(request).Name())
|
||||
log.Errorf(log.ExchangeSys, "Could not parse %v to URL values. Check that the type has url fields", reflect.TypeOf(request).Name())
|
||||
return
|
||||
}
|
||||
urlEncodedValues := v.Encode()
|
||||
@@ -546,13 +546,13 @@ func (o *OKGroup) SendHTTPRequest(httpMethod, requestType, requestPath string, d
|
||||
}
|
||||
|
||||
if o.Verbose {
|
||||
log.Debugf("Request JSON: %s\n", payload)
|
||||
log.Debugf(log.ExchangeSys, "Request JSON: %s\n", payload)
|
||||
}
|
||||
}
|
||||
|
||||
path := o.API.Endpoints.URL + requestType + o.APIVersion + requestPath
|
||||
if o.Verbose {
|
||||
log.Debugf("Sending %v request to %s \n", requestType, path)
|
||||
log.Debugf(log.ExchangeSys, "Sending %v request to %s \n", requestType, path)
|
||||
}
|
||||
|
||||
headers := make(map[string]string)
|
||||
|
||||
@@ -159,7 +159,7 @@ func (o *OKGroup) writeToWebsocket(message string) error {
|
||||
o.wsRequestMtx.Lock()
|
||||
defer o.wsRequestMtx.Unlock()
|
||||
if o.Verbose {
|
||||
log.Debugf("%v sending message to WS: %v", o.Name, message)
|
||||
log.Debugf(log.ExchangeSys, "%v sending message to WS: %v", o.Name, message)
|
||||
}
|
||||
// Really basic WS rate limit
|
||||
time.Sleep(okGroupWsRateLimit)
|
||||
@@ -183,7 +183,7 @@ func (o *OKGroup) WsConnect() error {
|
||||
|
||||
var err error
|
||||
if o.Verbose {
|
||||
log.Debugf("Attempting to connect to %v", o.Websocket.GetWebsocketURL())
|
||||
log.Debugf(log.ExchangeSys, "Attempting to connect to %v", o.Websocket.GetWebsocketURL())
|
||||
}
|
||||
o.WebsocketConn, _, err = dialer.Dial(o.Websocket.GetWebsocketURL(),
|
||||
http.Header{})
|
||||
@@ -193,7 +193,7 @@ func (o *OKGroup) WsConnect() error {
|
||||
err)
|
||||
}
|
||||
if o.Verbose {
|
||||
log.Debugf("Successful connection to %v",
|
||||
log.Debugf(log.ExchangeSys, "Successful connection to %v\n",
|
||||
o.Websocket.GetWebsocketURL())
|
||||
}
|
||||
wg := sync.WaitGroup{}
|
||||
@@ -203,7 +203,7 @@ func (o *OKGroup) WsConnect() error {
|
||||
if o.GetAuthenticatedAPISupport(exchange.WebsocketAuthentication) {
|
||||
err = o.WsLogin()
|
||||
if err != nil {
|
||||
log.Errorf("%v - authentication failed: %v", o.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%v - authentication failed: %v\n", o.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ func (o *OKGroup) WsReadData() (exchange.WebsocketResponse, error) {
|
||||
}
|
||||
}
|
||||
if o.Verbose {
|
||||
log.Debugf("%v Websocket message received: %v", o.Name, string(standardMessage))
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket message received: %v", o.Name, string(standardMessage))
|
||||
}
|
||||
|
||||
return exchange.WebsocketResponse{Raw: standardMessage}, nil
|
||||
@@ -259,7 +259,7 @@ func (o *OKGroup) wsPingHandler(wg *sync.WaitGroup) {
|
||||
case <-ticker.C:
|
||||
err := o.writeToWebsocket("ping")
|
||||
if o.Verbose {
|
||||
log.Debugf("%v sending ping", o.GetName())
|
||||
log.Debugf(log.ExchangeSys, "%v sending ping", o.GetName())
|
||||
}
|
||||
if err != nil {
|
||||
o.Websocket.DataHandler <- err
|
||||
@@ -300,7 +300,7 @@ func (o *OKGroup) WsHandleData(wg *sync.WaitGroup) {
|
||||
err = common.JSONDecode(resp.Raw, &errorResponse)
|
||||
if err == nil && errorResponse.ErrorCode > 0 {
|
||||
if o.Verbose {
|
||||
log.Debugf("WS Error Event: %v Message: %v", errorResponse.Event, errorResponse.Message)
|
||||
log.Debugf(log.ExchangeSys, "WS Error Event: %v Message: %v", errorResponse.Event, errorResponse.Message)
|
||||
}
|
||||
o.WsHandleErrorResponse(errorResponse)
|
||||
continue
|
||||
@@ -312,7 +312,7 @@ func (o *OKGroup) WsHandleData(wg *sync.WaitGroup) {
|
||||
o.Websocket.SetCanUseAuthenticatedEndpoints(eventResponse.Success)
|
||||
}
|
||||
if o.Verbose {
|
||||
log.Debugf("WS Event: %v on Channel: %v", eventResponse.Event, eventResponse.Channel)
|
||||
log.Debugf(log.ExchangeSys, "WS Event: %v on Channel: %v", eventResponse.Event, eventResponse.Channel)
|
||||
}
|
||||
o.Websocket.DataHandler <- eventResponse
|
||||
continue
|
||||
@@ -352,7 +352,7 @@ func (o *OKGroup) WsHandleErrorResponse(event WebsocketErrorResponse) {
|
||||
errorMessage := fmt.Sprintf("%v error - %v message: %s ",
|
||||
o.GetName(), event.ErrorCode, event.Message)
|
||||
if o.Verbose {
|
||||
log.Error(errorMessage)
|
||||
log.Error(log.ExchangeSys, errorMessage)
|
||||
}
|
||||
o.Websocket.DataHandler <- fmt.Errorf(errorMessage)
|
||||
}
|
||||
@@ -389,12 +389,12 @@ func (o *OKGroup) WsHandleDataResponse(response *WebsocketDataResponse) {
|
||||
okGroupWsCandle1800s, okGroupWsCandle3600s, okGroupWsCandle7200s, okGroupWsCandle14400s,
|
||||
okGroupWsCandle21600s, okGroupWsCandle43200s, okGroupWsCandle86400s, okGroupWsCandle604900s:
|
||||
if o.Verbose {
|
||||
log.Debugf("%v Websocket candle data received", o.GetName())
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket candle data received", o.GetName())
|
||||
}
|
||||
o.wsProcessCandles(response)
|
||||
case okGroupWsDepth, okGroupWsDepth5:
|
||||
if o.Verbose {
|
||||
log.Debugf("%v Websocket orderbook data received", o.GetName())
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket orderbook data received", o.GetName())
|
||||
}
|
||||
// Locking, orderbooks cannot be processed out of order
|
||||
orderbookMutex.Lock()
|
||||
@@ -410,12 +410,12 @@ func (o *OKGroup) WsHandleDataResponse(response *WebsocketDataResponse) {
|
||||
orderbookMutex.Unlock()
|
||||
case okGroupWsTicker:
|
||||
if o.Verbose {
|
||||
log.Debugf("%v Websocket ticker data received", o.GetName())
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket ticker data received", o.GetName())
|
||||
}
|
||||
o.wsProcessTickers(response)
|
||||
case okGroupWsTrade:
|
||||
if o.Verbose {
|
||||
log.Debugf("%v Websocket trade data received", o.GetName())
|
||||
log.Debugf(log.ExchangeSys, "%v Websocket trade data received", o.GetName())
|
||||
}
|
||||
o.wsProcessTrades(response)
|
||||
default:
|
||||
@@ -427,7 +427,7 @@ func (o *OKGroup) WsHandleDataResponse(response *WebsocketDataResponse) {
|
||||
// where there is no websocket datahandler for it
|
||||
func logDataResponse(response *WebsocketDataResponse) {
|
||||
for i := range response.Data {
|
||||
log.Errorf("Unhandled channel: '%v'. Instrument '%v' Timestamp '%v', Data '%v",
|
||||
log.Errorf(log.ExchangeSys, "Unhandled channel: '%v'. Instrument '%v' Timestamp '%v', Data '%v",
|
||||
response.Table,
|
||||
response.Data[i].InstrumentID,
|
||||
response.Data[i].Timestamp,
|
||||
@@ -474,7 +474,7 @@ func (o *OKGroup) wsProcessCandles(response *WebsocketDataResponse) {
|
||||
instrument := currency.NewPairDelimiter(response.Data[i].InstrumentID, "-")
|
||||
timeData, err := time.Parse(time.RFC3339Nano, response.Data[i].WebsocketCandleResponse.Candle[0])
|
||||
if err != nil {
|
||||
log.Warnf("%v Time data could not be parsed: %v", o.GetName(), response.Data[i].Candle[0])
|
||||
log.Warnf(log.ExchangeSys, "%v Time data could not be parsed: %v", o.GetName(), response.Data[i].Candle[0])
|
||||
}
|
||||
|
||||
candleIndex := strings.LastIndex(response.Table, okGroupWsCandle)
|
||||
@@ -535,7 +535,7 @@ func (o *OKGroup) WsProcessPartialOrderBook(wsEventData *WebsocketDataWrapper, i
|
||||
return fmt.Errorf("channel: %v. Orderbook partial for %v checksum invalid", tableName, instrument)
|
||||
}
|
||||
if o.Verbose {
|
||||
log.Debug("Passed checksum!")
|
||||
log.Debug(log.ExchangeSys, "Passed checksum!")
|
||||
}
|
||||
asks := o.AppendWsOrderbookItems(wsEventData.Asks)
|
||||
bids := o.AppendWsOrderbookItems(wsEventData.Bids)
|
||||
@@ -569,7 +569,7 @@ func (o *OKGroup) WsProcessUpdateOrderbook(wsEventData *WebsocketDataWrapper, in
|
||||
}
|
||||
if internalOrderbook.LastUpdated.After(wsEventData.Timestamp) {
|
||||
if o.Verbose {
|
||||
log.Errorf("Orderbook update out of order. Existing: %v, Attempted: %v", internalOrderbook.LastUpdated.Unix(), wsEventData.Timestamp.Unix())
|
||||
log.Errorf(log.ExchangeSys, "Orderbook update out of order. Existing: %v, Attempted: %v", internalOrderbook.LastUpdated.Unix(), wsEventData.Timestamp.Unix())
|
||||
}
|
||||
return errors.New("updated orderbook is older than existing")
|
||||
}
|
||||
@@ -584,16 +584,16 @@ func (o *OKGroup) WsProcessUpdateOrderbook(wsEventData *WebsocketDataWrapper, in
|
||||
checksum := o.CalculateUpdateOrderbookChecksum(&internalOrderbook)
|
||||
if checksum == wsEventData.Checksum {
|
||||
if o.Verbose {
|
||||
log.Debug("Orderbook valid")
|
||||
log.Debug(log.ExchangeSys, "Orderbook valid")
|
||||
}
|
||||
internalOrderbook.LastUpdated = wsEventData.Timestamp
|
||||
if o.Verbose {
|
||||
log.Debug("Internalising orderbook")
|
||||
log.Debug(log.ExchangeSys, "Internalising orderbook")
|
||||
}
|
||||
|
||||
err := o.Websocket.Orderbook.LoadSnapshot(&internalOrderbook, o.GetName(), true)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
}
|
||||
o.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
|
||||
Exchange: o.GetName(),
|
||||
@@ -602,7 +602,7 @@ func (o *OKGroup) WsProcessUpdateOrderbook(wsEventData *WebsocketDataWrapper, in
|
||||
}
|
||||
} else {
|
||||
if o.Verbose {
|
||||
log.Debug("Orderbook invalid")
|
||||
log.Warnln(log.ExchangeSys, "Orderbook invalid")
|
||||
}
|
||||
return fmt.Errorf("channel: %v. Orderbook update for %v checksum invalid. Received %v Calculated %v", tableName, instrument, wsEventData.Checksum, checksum)
|
||||
}
|
||||
@@ -727,7 +727,7 @@ func (o *OKGroup) Subscribe(channelToSubscribe exchange.WebsocketChannelSubscrip
|
||||
json, err := common.JSONEncode(resp)
|
||||
if err != nil {
|
||||
if o.Verbose {
|
||||
log.Debugf("%v subscribe error: %v", o.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%v subscribe error: %v", o.Name, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -743,7 +743,7 @@ func (o *OKGroup) Unsubscribe(channelToSubscribe exchange.WebsocketChannelSubscr
|
||||
json, err := common.JSONEncode(resp)
|
||||
if err != nil {
|
||||
if o.Verbose {
|
||||
log.Debugf("%v unsubscribe error: %v", o.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%v unsubscribe error: %v", o.Name, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -92,11 +92,11 @@ func (o *OKGroup) UpdateOrderbook(p currency.Pair, assetType asset.Item) (resp o
|
||||
for x := range orderbookNew.Bids {
|
||||
amount, convErr := strconv.ParseFloat(orderbookNew.Bids[x][1], 64)
|
||||
if convErr != nil {
|
||||
log.Errorf("Could not convert %v to float64", orderbookNew.Bids[x][1])
|
||||
log.Errorf(log.ExchangeSys, "Could not convert %v to float64", orderbookNew.Bids[x][1])
|
||||
}
|
||||
price, convErr := strconv.ParseFloat(orderbookNew.Bids[x][0], 64)
|
||||
if convErr != nil {
|
||||
log.Errorf("Could not convert %v to float64", orderbookNew.Bids[x][0])
|
||||
log.Errorf(log.ExchangeSys, "Could not convert %v to float64", orderbookNew.Bids[x][0])
|
||||
}
|
||||
resp.Bids = append(resp.Bids, orderbook.Item{
|
||||
Amount: amount,
|
||||
@@ -107,11 +107,11 @@ func (o *OKGroup) UpdateOrderbook(p currency.Pair, assetType asset.Item) (resp o
|
||||
for x := range orderbookNew.Asks {
|
||||
amount, convErr := strconv.ParseFloat(orderbookNew.Asks[x][1], 64)
|
||||
if convErr != nil {
|
||||
log.Errorf("Could not convert %v to float64", orderbookNew.Asks[x][1])
|
||||
log.Errorf(log.ExchangeSys, "Could not convert %v to float64", orderbookNew.Asks[x][1])
|
||||
}
|
||||
price, convErr := strconv.ParseFloat(orderbookNew.Asks[x][0], 64)
|
||||
if convErr != nil {
|
||||
log.Errorf("Could not convert %v to float64", orderbookNew.Asks[x][0])
|
||||
log.Errorf(log.ExchangeSys, "Could not convert %v to float64", orderbookNew.Asks[x][0])
|
||||
}
|
||||
resp.Asks = append(resp.Asks, orderbook.Item{
|
||||
Amount: amount,
|
||||
@@ -140,11 +140,11 @@ func (o *OKGroup) GetAccountInfo() (resp exchange.AccountInfo, err error) {
|
||||
for _, curr := range currencies {
|
||||
hold, err := strconv.ParseFloat(curr.Hold, 64)
|
||||
if err != nil {
|
||||
log.Errorf("Could not convert %v to float64", curr.Hold)
|
||||
log.Errorf(log.ExchangeSys, "Could not convert %v to float64", curr.Hold)
|
||||
}
|
||||
totalValue, err := strconv.ParseFloat(curr.Balance, 64)
|
||||
if err != nil {
|
||||
log.Errorf("Could not convert %v to float64", curr.Balance)
|
||||
log.Errorf(log.ExchangeSys, "Could not convert %v to float64", curr.Balance)
|
||||
}
|
||||
currencyAccount.Currencies = append(currencyAccount.Currencies, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(curr.Currency),
|
||||
|
||||
@@ -1,227 +1,227 @@
|
||||
package orderbook
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
math "github.com/thrasher-/gocryptotrader/common/math"
|
||||
log "github.com/thrasher-/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
// WhaleBombResult returns the whale bomb result
|
||||
type WhaleBombResult struct {
|
||||
Amount float64
|
||||
MinimumPrice float64
|
||||
MaximumPrice float64
|
||||
PercentageGainOrLoss float64
|
||||
Orders orderSummary
|
||||
Status string
|
||||
}
|
||||
|
||||
// WhaleBomb finds the amount required to target a price
|
||||
func (o *Base) WhaleBomb(priceTarget float64, buy bool) (*WhaleBombResult, error) {
|
||||
if priceTarget < 0 {
|
||||
return nil, errors.New("price target is invalid")
|
||||
}
|
||||
if buy {
|
||||
a, orders := o.findAmount(priceTarget, true)
|
||||
min, max := orders.MinimumPrice(false), orders.MaximumPrice(true)
|
||||
var err error
|
||||
if max < priceTarget {
|
||||
err = errors.New("unable to hit price target due to insufficient orderbook items")
|
||||
}
|
||||
status := fmt.Sprintf("Buying %.2f %v worth of %v will send the price from %v to %v [%.2f%%] and take %v orders.",
|
||||
a, o.Pair.Quote.String(), o.Pair.Base.String(), min, max,
|
||||
math.CalculatePercentageGainOrLoss(max, min), len(orders))
|
||||
return &WhaleBombResult{
|
||||
Amount: a,
|
||||
Orders: orders,
|
||||
MinimumPrice: min,
|
||||
MaximumPrice: max,
|
||||
Status: status,
|
||||
}, err
|
||||
}
|
||||
|
||||
a, orders := o.findAmount(priceTarget, false)
|
||||
min, max := orders.MinimumPrice(false), orders.MaximumPrice(true)
|
||||
var err error
|
||||
if min > priceTarget {
|
||||
err = errors.New("unable to hit price target due to insufficient orderbook items")
|
||||
}
|
||||
status := fmt.Sprintf("Selling %.2f %v worth of %v will send the price from %v to %v [%.2f%%] and take %v orders.",
|
||||
a, o.Pair.Base.String(), o.Pair.Quote.String(), max, min,
|
||||
math.CalculatePercentageGainOrLoss(min, max), len(orders))
|
||||
return &WhaleBombResult{
|
||||
Amount: a,
|
||||
Orders: orders,
|
||||
MinimumPrice: min,
|
||||
MaximumPrice: max,
|
||||
Status: status,
|
||||
}, err
|
||||
}
|
||||
|
||||
// OrderSimulationResult returns the order simulation result
|
||||
type OrderSimulationResult WhaleBombResult
|
||||
|
||||
// SimulateOrder simulates an order
|
||||
func (o *Base) SimulateOrder(amount float64, buy bool) *OrderSimulationResult {
|
||||
if buy {
|
||||
orders, amt := o.buy(amount)
|
||||
min, max := orders.MinimumPrice(false), orders.MaximumPrice(true)
|
||||
pct := math.CalculatePercentageGainOrLoss(max, min)
|
||||
status := fmt.Sprintf("Buying %.2f %v worth of %v will send the price from %v to %v [%.2f%%] and take %v orders.",
|
||||
amount, o.Pair.Quote.String(), o.Pair.Base.String(), min, max,
|
||||
pct, len(orders))
|
||||
return &OrderSimulationResult{
|
||||
Orders: orders,
|
||||
Amount: amt,
|
||||
MinimumPrice: min,
|
||||
MaximumPrice: max,
|
||||
PercentageGainOrLoss: pct,
|
||||
Status: status,
|
||||
}
|
||||
}
|
||||
orders, amt := o.sell(amount)
|
||||
min, max := orders.MinimumPrice(false), orders.MaximumPrice(true)
|
||||
pct := math.CalculatePercentageGainOrLoss(min, max)
|
||||
status := fmt.Sprintf("Selling %f %v worth of %v will send the price from %v to %v [%.2f%%] and take %v orders.",
|
||||
amount, o.Pair.Base.String(), o.Pair.Quote.String(), max, min,
|
||||
pct, len(orders))
|
||||
return &OrderSimulationResult{
|
||||
Orders: orders,
|
||||
Amount: amt,
|
||||
MinimumPrice: min,
|
||||
MaximumPrice: max,
|
||||
PercentageGainOrLoss: pct,
|
||||
Status: status,
|
||||
}
|
||||
}
|
||||
|
||||
type orderSummary []Item
|
||||
|
||||
func (o orderSummary) Print() {
|
||||
for x := range o {
|
||||
log.Debugf("Order: Price: %f Amount: %f", o[x].Price, o[x].Amount)
|
||||
}
|
||||
}
|
||||
|
||||
func (o orderSummary) MinimumPrice(reverse bool) float64 {
|
||||
if len(o) != 0 {
|
||||
sortOrdersByPrice(&o, reverse)
|
||||
return o[0].Price
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (o orderSummary) MaximumPrice(reverse bool) float64 {
|
||||
if len(o) != 0 {
|
||||
sortOrdersByPrice(&o, reverse)
|
||||
return o[0].Price
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// ByPrice used for sorting orders by order date
|
||||
type ByPrice orderSummary
|
||||
|
||||
func (b ByPrice) Len() int { return len(b) }
|
||||
func (b ByPrice) Less(i, j int) bool { return b[i].Price < b[j].Price }
|
||||
func (b ByPrice) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||
|
||||
// sortOrdersByPrice the caller function to sort orders
|
||||
func sortOrdersByPrice(o *orderSummary, reverse bool) {
|
||||
if reverse {
|
||||
sort.Sort(sort.Reverse(ByPrice(*o)))
|
||||
} else {
|
||||
sort.Sort(ByPrice(*o))
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Base) findAmount(price float64, buy bool) (float64, orderSummary) {
|
||||
var orders orderSummary
|
||||
var amt float64
|
||||
|
||||
if buy {
|
||||
asks := o.Asks
|
||||
for x := range asks {
|
||||
if asks[x].Price >= price {
|
||||
amt += asks[x].Price * asks[x].Amount
|
||||
orders = append(orders, Item{
|
||||
Price: asks[x].Price,
|
||||
Amount: asks[x].Amount,
|
||||
})
|
||||
return amt, orders
|
||||
}
|
||||
orders = append(orders, Item{
|
||||
Price: asks[x].Price,
|
||||
Amount: asks[x].Amount,
|
||||
})
|
||||
amt += asks[x].Price * asks[x].Amount
|
||||
}
|
||||
return amt, orders
|
||||
}
|
||||
|
||||
for x := range o.Bids {
|
||||
if o.Bids[x].Price <= price {
|
||||
amt += o.Bids[x].Amount
|
||||
orders = append(orders, Item{
|
||||
Price: o.Bids[x].Price,
|
||||
Amount: o.Bids[x].Amount,
|
||||
})
|
||||
break
|
||||
}
|
||||
orders = append(orders, Item{
|
||||
Price: o.Bids[x].Price,
|
||||
Amount: o.Bids[x].Amount,
|
||||
})
|
||||
amt += o.Bids[x].Amount
|
||||
}
|
||||
return amt, orders
|
||||
}
|
||||
|
||||
func (o *Base) buy(amount float64) (orders orderSummary, baseAmount float64) {
|
||||
var processedAmt float64
|
||||
for x := range o.Asks {
|
||||
subtotal := o.Asks[x].Price * o.Asks[x].Amount
|
||||
if processedAmt+subtotal >= amount {
|
||||
diff := amount - processedAmt
|
||||
subAmt := diff / o.Asks[x].Price
|
||||
orders = append(orders, Item{
|
||||
Price: o.Asks[x].Price,
|
||||
Amount: subAmt,
|
||||
})
|
||||
baseAmount += subAmt
|
||||
break
|
||||
}
|
||||
processedAmt += subtotal
|
||||
baseAmount += o.Asks[x].Amount
|
||||
orders = append(orders, Item{
|
||||
Price: o.Asks[x].Price,
|
||||
Amount: o.Asks[x].Amount,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (o *Base) sell(amount float64) (orders orderSummary, quoteAmount float64) {
|
||||
var processedAmt float64
|
||||
for x := range o.Bids {
|
||||
if processedAmt+o.Bids[x].Amount >= amount {
|
||||
diff := amount - processedAmt
|
||||
orders = append(orders, Item{
|
||||
Price: o.Bids[x].Price,
|
||||
Amount: diff,
|
||||
})
|
||||
quoteAmount += diff * o.Bids[x].Price
|
||||
break
|
||||
}
|
||||
processedAmt += o.Bids[x].Amount
|
||||
quoteAmount += o.Bids[x].Amount * o.Bids[x].Price
|
||||
orders = append(orders, Item{
|
||||
Price: o.Bids[x].Price,
|
||||
Amount: o.Bids[x].Amount,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
package orderbook
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
math "github.com/thrasher-/gocryptotrader/common/math"
|
||||
log "github.com/thrasher-/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
// WhaleBombResult returns the whale bomb result
|
||||
type WhaleBombResult struct {
|
||||
Amount float64
|
||||
MinimumPrice float64
|
||||
MaximumPrice float64
|
||||
PercentageGainOrLoss float64
|
||||
Orders orderSummary
|
||||
Status string
|
||||
}
|
||||
|
||||
// WhaleBomb finds the amount required to target a price
|
||||
func (o *Base) WhaleBomb(priceTarget float64, buy bool) (*WhaleBombResult, error) {
|
||||
if priceTarget < 0 {
|
||||
return nil, errors.New("price target is invalid")
|
||||
}
|
||||
if buy {
|
||||
a, orders := o.findAmount(priceTarget, true)
|
||||
min, max := orders.MinimumPrice(false), orders.MaximumPrice(true)
|
||||
var err error
|
||||
if max < priceTarget {
|
||||
err = errors.New("unable to hit price target due to insufficient orderbook items")
|
||||
}
|
||||
status := fmt.Sprintf("Buying %.2f %v worth of %v will send the price from %v to %v [%.2f%%] and take %v orders.",
|
||||
a, o.Pair.Quote.String(), o.Pair.Base.String(), min, max,
|
||||
math.CalculatePercentageGainOrLoss(max, min), len(orders))
|
||||
return &WhaleBombResult{
|
||||
Amount: a,
|
||||
Orders: orders,
|
||||
MinimumPrice: min,
|
||||
MaximumPrice: max,
|
||||
Status: status,
|
||||
}, err
|
||||
}
|
||||
|
||||
a, orders := o.findAmount(priceTarget, false)
|
||||
min, max := orders.MinimumPrice(false), orders.MaximumPrice(true)
|
||||
var err error
|
||||
if min > priceTarget {
|
||||
err = errors.New("unable to hit price target due to insufficient orderbook items")
|
||||
}
|
||||
status := fmt.Sprintf("Selling %.2f %v worth of %v will send the price from %v to %v [%.2f%%] and take %v orders.",
|
||||
a, o.Pair.Base.String(), o.Pair.Quote.String(), max, min,
|
||||
math.CalculatePercentageGainOrLoss(min, max), len(orders))
|
||||
return &WhaleBombResult{
|
||||
Amount: a,
|
||||
Orders: orders,
|
||||
MinimumPrice: min,
|
||||
MaximumPrice: max,
|
||||
Status: status,
|
||||
}, err
|
||||
}
|
||||
|
||||
// OrderSimulationResult returns the order simulation result
|
||||
type OrderSimulationResult WhaleBombResult
|
||||
|
||||
// SimulateOrder simulates an order
|
||||
func (o *Base) SimulateOrder(amount float64, buy bool) *OrderSimulationResult {
|
||||
if buy {
|
||||
orders, amt := o.buy(amount)
|
||||
min, max := orders.MinimumPrice(false), orders.MaximumPrice(true)
|
||||
pct := math.CalculatePercentageGainOrLoss(max, min)
|
||||
status := fmt.Sprintf("Buying %.2f %v worth of %v will send the price from %v to %v [%.2f%%] and take %v orders.",
|
||||
amount, o.Pair.Quote.String(), o.Pair.Base.String(), min, max,
|
||||
pct, len(orders))
|
||||
return &OrderSimulationResult{
|
||||
Orders: orders,
|
||||
Amount: amt,
|
||||
MinimumPrice: min,
|
||||
MaximumPrice: max,
|
||||
PercentageGainOrLoss: pct,
|
||||
Status: status,
|
||||
}
|
||||
}
|
||||
orders, amt := o.sell(amount)
|
||||
min, max := orders.MinimumPrice(false), orders.MaximumPrice(true)
|
||||
pct := math.CalculatePercentageGainOrLoss(min, max)
|
||||
status := fmt.Sprintf("Selling %f %v worth of %v will send the price from %v to %v [%.2f%%] and take %v orders.",
|
||||
amount, o.Pair.Base.String(), o.Pair.Quote.String(), max, min,
|
||||
pct, len(orders))
|
||||
return &OrderSimulationResult{
|
||||
Orders: orders,
|
||||
Amount: amt,
|
||||
MinimumPrice: min,
|
||||
MaximumPrice: max,
|
||||
PercentageGainOrLoss: pct,
|
||||
Status: status,
|
||||
}
|
||||
}
|
||||
|
||||
type orderSummary []Item
|
||||
|
||||
func (o orderSummary) Print() {
|
||||
for x := range o {
|
||||
log.Debugf(log.OrderBook, "Order: Price: %f Amount: %f", o[x].Price, o[x].Amount)
|
||||
}
|
||||
}
|
||||
|
||||
func (o orderSummary) MinimumPrice(reverse bool) float64 {
|
||||
if len(o) != 0 {
|
||||
sortOrdersByPrice(&o, reverse)
|
||||
return o[0].Price
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (o orderSummary) MaximumPrice(reverse bool) float64 {
|
||||
if len(o) != 0 {
|
||||
sortOrdersByPrice(&o, reverse)
|
||||
return o[0].Price
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// ByPrice used for sorting orders by order date
|
||||
type ByPrice orderSummary
|
||||
|
||||
func (b ByPrice) Len() int { return len(b) }
|
||||
func (b ByPrice) Less(i, j int) bool { return b[i].Price < b[j].Price }
|
||||
func (b ByPrice) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||
|
||||
// sortOrdersByPrice the caller function to sort orders
|
||||
func sortOrdersByPrice(o *orderSummary, reverse bool) {
|
||||
if reverse {
|
||||
sort.Sort(sort.Reverse(ByPrice(*o)))
|
||||
} else {
|
||||
sort.Sort(ByPrice(*o))
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Base) findAmount(price float64, buy bool) (float64, orderSummary) {
|
||||
var orders orderSummary
|
||||
var amt float64
|
||||
|
||||
if buy {
|
||||
asks := o.Asks
|
||||
for x := range asks {
|
||||
if asks[x].Price >= price {
|
||||
amt += asks[x].Price * asks[x].Amount
|
||||
orders = append(orders, Item{
|
||||
Price: asks[x].Price,
|
||||
Amount: asks[x].Amount,
|
||||
})
|
||||
return amt, orders
|
||||
}
|
||||
orders = append(orders, Item{
|
||||
Price: asks[x].Price,
|
||||
Amount: asks[x].Amount,
|
||||
})
|
||||
amt += asks[x].Price * asks[x].Amount
|
||||
}
|
||||
return amt, orders
|
||||
}
|
||||
|
||||
for x := range o.Bids {
|
||||
if o.Bids[x].Price <= price {
|
||||
amt += o.Bids[x].Amount
|
||||
orders = append(orders, Item{
|
||||
Price: o.Bids[x].Price,
|
||||
Amount: o.Bids[x].Amount,
|
||||
})
|
||||
break
|
||||
}
|
||||
orders = append(orders, Item{
|
||||
Price: o.Bids[x].Price,
|
||||
Amount: o.Bids[x].Amount,
|
||||
})
|
||||
amt += o.Bids[x].Amount
|
||||
}
|
||||
return amt, orders
|
||||
}
|
||||
|
||||
func (o *Base) buy(amount float64) (orders orderSummary, baseAmount float64) {
|
||||
var processedAmt float64
|
||||
for x := range o.Asks {
|
||||
subtotal := o.Asks[x].Price * o.Asks[x].Amount
|
||||
if processedAmt+subtotal >= amount {
|
||||
diff := amount - processedAmt
|
||||
subAmt := diff / o.Asks[x].Price
|
||||
orders = append(orders, Item{
|
||||
Price: o.Asks[x].Price,
|
||||
Amount: subAmt,
|
||||
})
|
||||
baseAmount += subAmt
|
||||
break
|
||||
}
|
||||
processedAmt += subtotal
|
||||
baseAmount += o.Asks[x].Amount
|
||||
orders = append(orders, Item{
|
||||
Price: o.Asks[x].Price,
|
||||
Amount: o.Asks[x].Amount,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (o *Base) sell(amount float64) (orders orderSummary, quoteAmount float64) {
|
||||
var processedAmt float64
|
||||
for x := range o.Bids {
|
||||
if processedAmt+o.Bids[x].Amount >= amount {
|
||||
diff := amount - processedAmt
|
||||
orders = append(orders, Item{
|
||||
Price: o.Bids[x].Price,
|
||||
Amount: diff,
|
||||
})
|
||||
quoteAmount += diff * o.Bids[x].Price
|
||||
break
|
||||
}
|
||||
processedAmt += o.Bids[x].Amount
|
||||
quoteAmount += o.Bids[x].Amount * o.Bids[x].Price
|
||||
orders = append(orders, Item{
|
||||
Price: o.Bids[x].Price,
|
||||
Amount: o.Bids[x].Amount,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,79 +1,79 @@
|
||||
package orderbook
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
)
|
||||
|
||||
func testSetup() Base {
|
||||
return Base{
|
||||
ExchangeName: "a",
|
||||
Pair: currency.NewPair(currency.BTC, currency.USD),
|
||||
Asks: []Item{
|
||||
{Price: 7000, Amount: 1},
|
||||
{Price: 7001, Amount: 2},
|
||||
},
|
||||
Bids: []Item{
|
||||
{Price: 6999, Amount: 1},
|
||||
{Price: 6998, Amount: 2},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestWhaleBomb(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := testSetup()
|
||||
|
||||
// invalid price amout
|
||||
_, err := b.WhaleBomb(-1, true)
|
||||
if err == nil {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
|
||||
// valid
|
||||
b.WhaleBomb(7001, true)
|
||||
// invalid
|
||||
b.WhaleBomb(7002, true)
|
||||
|
||||
// valid
|
||||
b.WhaleBomb(6998, false)
|
||||
// invalid
|
||||
b.WhaleBomb(6997, false)
|
||||
}
|
||||
|
||||
func TestSimulateOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := testSetup()
|
||||
b.SimulateOrder(8000, true)
|
||||
b.SimulateOrder(1.5, false)
|
||||
}
|
||||
|
||||
func TestOrderSummary(t *testing.T) {
|
||||
var o orderSummary
|
||||
if p := o.MaximumPrice(false); p != 0 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
if p := o.MinimumPrice(false); p != 0 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
|
||||
o = orderSummary{
|
||||
{Price: 1337, Amount: 1},
|
||||
{Price: 9001, Amount: 1},
|
||||
}
|
||||
if p := o.MaximumPrice(false); p != 1337 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
if p := o.MaximumPrice(true); p != 9001 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
if p := o.MinimumPrice(false); p != 1337 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
if p := o.MinimumPrice(true); p != 9001 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
|
||||
o.Print()
|
||||
}
|
||||
package orderbook
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
)
|
||||
|
||||
func testSetup() Base {
|
||||
return Base{
|
||||
ExchangeName: "a",
|
||||
Pair: currency.NewPair(currency.BTC, currency.USD),
|
||||
Asks: []Item{
|
||||
{Price: 7000, Amount: 1},
|
||||
{Price: 7001, Amount: 2},
|
||||
},
|
||||
Bids: []Item{
|
||||
{Price: 6999, Amount: 1},
|
||||
{Price: 6998, Amount: 2},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestWhaleBomb(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := testSetup()
|
||||
|
||||
// invalid price amout
|
||||
_, err := b.WhaleBomb(-1, true)
|
||||
if err == nil {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
|
||||
// valid
|
||||
b.WhaleBomb(7001, true)
|
||||
// invalid
|
||||
b.WhaleBomb(7002, true)
|
||||
|
||||
// valid
|
||||
b.WhaleBomb(6998, false)
|
||||
// invalid
|
||||
b.WhaleBomb(6997, false)
|
||||
}
|
||||
|
||||
func TestSimulateOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := testSetup()
|
||||
b.SimulateOrder(8000, true)
|
||||
b.SimulateOrder(1.5, false)
|
||||
}
|
||||
|
||||
func TestOrderSummary(t *testing.T) {
|
||||
var o orderSummary
|
||||
if p := o.MaximumPrice(false); p != 0 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
if p := o.MinimumPrice(false); p != 0 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
|
||||
o = orderSummary{
|
||||
{Price: 1337, Amount: 1},
|
||||
{Price: 9001, Amount: 1},
|
||||
}
|
||||
if p := o.MaximumPrice(false); p != 1337 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
if p := o.MaximumPrice(true); p != 9001 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
if p := o.MinimumPrice(false); p != 1337 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
if p := o.MinimumPrice(true); p != 9001 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
|
||||
o.Print()
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/asset"
|
||||
log "github.com/thrasher-/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
func TestVerify(t *testing.T) {
|
||||
@@ -364,7 +363,7 @@ func TestProcessOrderbook(t *testing.T) {
|
||||
m.Lock()
|
||||
err = base.Process()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
t.Error(err)
|
||||
catastrophicFailure = true
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
package simulator
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/bitstamp"
|
||||
)
|
||||
|
||||
func TestSimulate(t *testing.T) {
|
||||
b := bitstamp.Bitstamp{}
|
||||
b.SetDefaults()
|
||||
b.Verbose = false
|
||||
o, err := b.FetchOrderbook(currency.NewPair(currency.BTC, currency.USD), asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
r := o.SimulateOrder(10000000, true)
|
||||
t.Log(r.Status)
|
||||
r = o.SimulateOrder(2171, false)
|
||||
t.Log(r.Status)
|
||||
}
|
||||
package simulator
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/bitstamp"
|
||||
)
|
||||
|
||||
func TestSimulate(t *testing.T) {
|
||||
b := bitstamp.Bitstamp{}
|
||||
b.SetDefaults()
|
||||
b.Verbose = false
|
||||
o, err := b.FetchOrderbook(currency.NewPair(currency.BTC, currency.USD), asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
r := o.SimulateOrder(10000000, true)
|
||||
t.Log(r.Status)
|
||||
r = o.SimulateOrder(2171, false)
|
||||
t.Log(r.Status)
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ func (p *Poloniex) WsHandleData() {
|
||||
if len(data) == 2 && chanID != wsHeartbeat {
|
||||
if checkSubscriptionSuccess(data) {
|
||||
if p.Verbose {
|
||||
log.Debugf("poloniex websocket subscribed to channel successfully. %d", chanID)
|
||||
log.Debugf(log.ExchangeSys, "poloniex websocket subscribed to channel successfully. %d", chanID)
|
||||
}
|
||||
} else {
|
||||
p.Websocket.DataHandler <- fmt.Errorf("poloniex websocket subscription to channel failed. %d", chanID)
|
||||
@@ -456,7 +456,7 @@ func (p *Poloniex) wsSend(data interface{}) error {
|
||||
return err
|
||||
}
|
||||
if p.Verbose {
|
||||
log.Debugf("%v sending message to websocket %v", p.Name, data)
|
||||
log.Debugf(log.ExchangeSys, "%v sending message to websocket %v", p.Name, data)
|
||||
}
|
||||
return p.WebsocketConn.WriteMessage(websocket.TextMessage, json)
|
||||
}
|
||||
|
||||
@@ -130,13 +130,13 @@ func (p *Poloniex) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the Poloniex wrapper
|
||||
func (p *Poloniex) Run() {
|
||||
if p.Verbose {
|
||||
log.Debugf("%s Websocket: %s (url: %s).\n", p.GetName(), common.IsEnabled(p.Websocket.IsEnabled()), poloniexWebsocketAddress)
|
||||
log.Debugf(log.ExchangeSys, "%s Websocket: %s (url: %s).\n", p.GetName(), common.IsEnabled(p.Websocket.IsEnabled()), poloniexWebsocketAddress)
|
||||
p.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
forceUpdate := false
|
||||
if common.StringDataCompare(p.GetAvailablePairs(asset.Spot).Strings(), "BTC_USDT") {
|
||||
log.Warnf("%s contains invalid pair, forcing upgrade of available currencies.\n",
|
||||
log.Warnf(log.ExchangeSys, "%s contains invalid pair, forcing upgrade of available currencies.\n",
|
||||
p.Name)
|
||||
forceUpdate = true
|
||||
}
|
||||
@@ -147,7 +147,7 @@ func (p *Poloniex) Run() {
|
||||
|
||||
err := p.UpdateTradablePairs(forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", p.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", p.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,7 +453,7 @@ func (p *Poloniex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest)
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(order.Type))
|
||||
orderDate, err := time.Parse(poloniexDateLayout, order.Date)
|
||||
if err != nil {
|
||||
log.Warnf("Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
p.Name, "GetActiveOrders", order.OrderNumber, order.Date)
|
||||
}
|
||||
|
||||
@@ -495,7 +495,7 @@ func (p *Poloniex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest)
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(order.Type))
|
||||
orderDate, err := time.Parse(poloniexDateLayout, order.Date)
|
||||
if err != nil {
|
||||
log.Warnf("Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
p.Name, "GetActiveOrders", order.OrderNumber, order.Date)
|
||||
}
|
||||
|
||||
|
||||
@@ -281,11 +281,12 @@ func (r *Requester) checkRequest(method, path string, body io.Reader, headers ma
|
||||
// DoRequest performs a HTTP/HTTPS request with the supplied params
|
||||
func (r *Requester) DoRequest(req *http.Request, path string, body io.Reader, result interface{}, authRequest, verbose, httpDebug bool) error {
|
||||
if verbose {
|
||||
log.Debugf("%s exchange request path: %s requires rate limiter: %v", r.Name, path, r.RequiresRateLimiter())
|
||||
log.Debugf(log.Global,
|
||||
"%s exchange request path: %s requires rate limiter: %v", r.Name, path, r.RequiresRateLimiter())
|
||||
for k, d := range req.Header {
|
||||
log.Debugf("%s exchange request header [%s]: %s", r.Name, k, d)
|
||||
log.Debugf(log.Global, "%s exchange request header [%s]: %s", r.Name, k, d)
|
||||
}
|
||||
log.Debug(body)
|
||||
log.Debugln(log.Global, body)
|
||||
}
|
||||
|
||||
var timeoutError error
|
||||
@@ -294,7 +295,7 @@ func (r *Requester) DoRequest(req *http.Request, path string, body io.Reader, re
|
||||
if err != nil {
|
||||
if timeoutErr, ok := err.(net.Error); ok && timeoutErr.Timeout() {
|
||||
if verbose {
|
||||
log.Errorf("%s request has timed-out retrying request, count %d",
|
||||
log.Errorf(log.ExchangeSys, "%s request has timed-out retrying request, count %d",
|
||||
r.Name,
|
||||
i)
|
||||
}
|
||||
@@ -332,7 +333,7 @@ func (r *Requester) DoRequest(req *http.Request, path string, body io.Reader, re
|
||||
reader = resp.Body
|
||||
|
||||
default:
|
||||
log.Warnf("%s request response content type differs from JSON; received %v [path: %s]",
|
||||
log.Warnf(log.ExchangeSys, "%s request response content type differs from JSON; received %v [path: %s]\n",
|
||||
r.Name, resp.Header.Get("Content-Type"), path)
|
||||
reader = resp.Body
|
||||
}
|
||||
@@ -356,17 +357,17 @@ func (r *Requester) DoRequest(req *http.Request, path string, body io.Reader, re
|
||||
if httpDebug {
|
||||
dump, err := httputil.DumpResponse(resp, false)
|
||||
if err != nil {
|
||||
log.Errorf("DumpResponse invalid response: %v:", err)
|
||||
log.Errorf(log.Global, "DumpResponse invalid response: %v:", err)
|
||||
}
|
||||
log.Debugf("DumpResponse Headers (%v):\n%s", path, dump)
|
||||
log.Debugf("DumpResponse Body (%v):\n %s", path, string(contents))
|
||||
log.Debugf(log.Global, "DumpResponse Headers (%v):\n%s", path, dump)
|
||||
log.Debugf(log.Global, "DumpResponse Body (%v):\n %s", path, string(contents))
|
||||
}
|
||||
|
||||
resp.Body.Close()
|
||||
if verbose {
|
||||
log.Debugf("HTTP status: %s, Code: %v", resp.Status, resp.StatusCode)
|
||||
log.Debugf(log.ExchangeSys, "HTTP status: %s, Code: %v", resp.Status, resp.StatusCode)
|
||||
if !httpDebug {
|
||||
log.Debugf("%s exchange raw response: %s", r.Name, string(contents))
|
||||
log.Debugf(log.ExchangeSys, "%s exchange raw response: %s", r.Name, string(contents))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,7 +396,7 @@ func (r *Requester) worker() {
|
||||
limit := r.GetRateLimit(x.AuthRequest)
|
||||
diff := limit.GetDuration() - time.Since(r.Cycle)
|
||||
if x.Verbose {
|
||||
log.Debugf("%s request. Rate limited! Sleeping for %v", r.Name, diff)
|
||||
log.Debugf(log.ExchangeSys, "%s request. Rate limited! Sleeping for %v", r.Name, diff)
|
||||
}
|
||||
time.Sleep(diff)
|
||||
|
||||
@@ -407,7 +408,7 @@ func (r *Requester) worker() {
|
||||
r.IncrementRequests(x.AuthRequest)
|
||||
|
||||
if x.Verbose {
|
||||
log.Debugf("%s request. No longer rate limited! Doing request", r.Name)
|
||||
log.Debugf(log.ExchangeSys, "%s request. No longer rate limited! Doing request", r.Name)
|
||||
}
|
||||
|
||||
err := r.DoRequest(x.Request, x.Path, x.Body, x.Result, x.AuthRequest, x.Verbose, x.HTTPDebugging)
|
||||
@@ -452,9 +453,11 @@ func (r *Requester) SendPayload(method, path string, headers map[string]string,
|
||||
if httpDebugging {
|
||||
dump, err := httputil.DumpRequestOut(req, true)
|
||||
if err != nil {
|
||||
log.Errorf("DumpRequest invalid response %v:", err)
|
||||
log.Errorf(log.Global,
|
||||
"DumpRequest invalid response %v:", err)
|
||||
}
|
||||
log.Debugf("DumpRequest:\n%s", dump)
|
||||
log.Debugf(log.Global,
|
||||
"DumpRequest:\n%s", dump)
|
||||
}
|
||||
|
||||
if !r.RequiresRateLimiter() {
|
||||
@@ -491,18 +494,18 @@ func (r *Requester) SendPayload(method, path string, headers map[string]string,
|
||||
}
|
||||
|
||||
if verbose {
|
||||
log.Debugf("%s request. Attaching new job.", r.Name)
|
||||
log.Debugf(log.ExchangeSys, "%s request. Attaching new job.", r.Name)
|
||||
}
|
||||
r.Jobs <- newJob
|
||||
r.unlock()
|
||||
|
||||
if verbose {
|
||||
log.Debugf("%s request. Waiting for job to complete.", r.Name)
|
||||
log.Debugf(log.ExchangeSys, "%s request. Waiting for job to complete.", r.Name)
|
||||
}
|
||||
resp := <-newJob.JobResult
|
||||
|
||||
if verbose {
|
||||
log.Debugf("%s request. Job complete.", r.Name)
|
||||
log.Debugf(log.ExchangeSys, "%s request. Job complete.", r.Name)
|
||||
}
|
||||
|
||||
return resp.Error
|
||||
@@ -563,7 +566,7 @@ func (r *Requester) lock() {
|
||||
wg.Done()
|
||||
select {
|
||||
case <-timer.C:
|
||||
log.Errorf("Unlocking due to possible error for %s", r.Name)
|
||||
log.Errorf(log.ExchangeSys, "Unlocking due to possible error for %s", r.Name)
|
||||
r.fifoLock.Unlock()
|
||||
|
||||
case <-r.disengage:
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/asset"
|
||||
log "github.com/thrasher-/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
func TestPriceToString(t *testing.T) {
|
||||
@@ -351,7 +350,7 @@ func TestProcessTicker(t *testing.T) { // non-appending function to tickers
|
||||
sm.Lock()
|
||||
err = ProcessTicker(newName, &tp, asset.Spot)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
t.Error(err)
|
||||
catastrophicFailure = true
|
||||
return
|
||||
}
|
||||
|
||||
@@ -119,17 +119,17 @@ func (w *Websocket) wsConnectionMonitor() {
|
||||
w.DataHandler <- fmt.Errorf("%v WsConnectionMonitor: websocket disabled, shutting down", w.exchangeName)
|
||||
err := w.Shutdown()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.WebsocketMgr, err)
|
||||
}
|
||||
if w.verbose {
|
||||
log.Debugf("%v WsConnectionMonitor exiting", w.exchangeName)
|
||||
log.Debugf(log.WebsocketMgr, "%v WsConnectionMonitor exiting", w.exchangeName)
|
||||
}
|
||||
return
|
||||
}
|
||||
w.m.Unlock()
|
||||
err := w.checkConnection()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.WebsocketMgr, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,18 +138,18 @@ func (w *Websocket) wsConnectionMonitor() {
|
||||
// Will reconnect on disconnect
|
||||
func (w *Websocket) checkConnection() error {
|
||||
if w.verbose {
|
||||
log.Debugf("%v checking connection", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v checking connection", w.exchangeName)
|
||||
}
|
||||
switch {
|
||||
case !w.IsConnected() && !w.IsConnecting():
|
||||
w.m.Lock()
|
||||
defer w.m.Unlock()
|
||||
if w.verbose {
|
||||
log.Debugf("%v no connection. Attempt %v/%v", w.exchangeName, w.noConnectionChecks, w.noConnectionCheckLimit)
|
||||
log.Debugf(log.ExchangeSys, "%v no connection. Attempt %v/%v", w.exchangeName, w.noConnectionChecks, w.noConnectionCheckLimit)
|
||||
}
|
||||
if w.noConnectionChecks >= w.noConnectionCheckLimit {
|
||||
if w.verbose {
|
||||
log.Debugf("%v resetting connection", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v resetting connection", w.exchangeName)
|
||||
}
|
||||
w.connecting = true
|
||||
go w.WebsocketReset()
|
||||
@@ -163,7 +163,7 @@ func (w *Websocket) checkConnection() error {
|
||||
w.reconnectionLimit*int(connectionMonitorDelay.Seconds()))
|
||||
}
|
||||
if w.verbose {
|
||||
log.Debugf("%v Busy reconnecting", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v Busy reconnecting", w.exchangeName)
|
||||
}
|
||||
w.reconnectionChecks++
|
||||
default:
|
||||
@@ -200,7 +200,7 @@ func (w *Websocket) Shutdown() error {
|
||||
}
|
||||
|
||||
if w.verbose {
|
||||
log.Debugf("%v shutting down websocket channels", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v shutting down websocket channels", w.exchangeName)
|
||||
}
|
||||
timer := time.NewTimer(15 * time.Second)
|
||||
c := make(chan struct{}, 1)
|
||||
@@ -209,7 +209,7 @@ func (w *Websocket) Shutdown() error {
|
||||
close(w.ShutdownC)
|
||||
w.Wg.Wait()
|
||||
if w.verbose {
|
||||
log.Debugf("%v completed websocket channel shutdown", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v completed websocket channel shutdown", w.exchangeName)
|
||||
}
|
||||
c <- struct{}{}
|
||||
}(c)
|
||||
@@ -229,15 +229,15 @@ func (w *Websocket) WebsocketReset() error {
|
||||
err := w.Shutdown()
|
||||
if err != nil {
|
||||
// does not return here to allow connection to be made if already shut down
|
||||
log.Errorf("%v shutdown error: %v", w.exchangeName, err)
|
||||
log.Errorf(log.ExchangeSys, "%v shutdown error: %v", w.exchangeName, err)
|
||||
}
|
||||
log.Infof("%v reconnecting to websocket", w.exchangeName)
|
||||
log.Infof(log.WebsocketMgr, "%v reconnecting to websocket", w.exchangeName)
|
||||
w.m.Lock()
|
||||
w.init = true
|
||||
w.m.Unlock()
|
||||
err = w.Connect()
|
||||
if err != nil {
|
||||
log.Errorf("%v connection error: %v", w.exchangeName, err)
|
||||
log.Errorf(log.ExchangeSys, "%v connection error: %v", w.exchangeName, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -260,7 +260,7 @@ func (w *Websocket) trafficMonitor(wg *sync.WaitGroup) {
|
||||
select {
|
||||
case <-w.ShutdownC: // Returns on shutdown channel close
|
||||
if w.verbose {
|
||||
log.Debugf("%v trafficMonitor shutdown message received", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v trafficMonitor shutdown message received", w.exchangeName)
|
||||
}
|
||||
return
|
||||
case <-w.TrafficAlert: // Resets timer on traffic
|
||||
@@ -271,13 +271,13 @@ func (w *Websocket) trafficMonitor(wg *sync.WaitGroup) {
|
||||
}
|
||||
w.m.Unlock()
|
||||
if w.verbose {
|
||||
log.Debugf("%v received a traffic alert", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v received a traffic alert", w.exchangeName)
|
||||
}
|
||||
trafficTimer.Reset(WebsocketTrafficLimitTime)
|
||||
case <-trafficTimer.C: // Falls through when timer runs out
|
||||
newtimer := time.NewTimer(10 * time.Second) // New secondary timer set
|
||||
if w.verbose {
|
||||
log.Debugf("%v has not received a traffic alert in 5 seconds.", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v has not received a traffic alert in 5 seconds.", w.exchangeName)
|
||||
}
|
||||
w.m.Lock()
|
||||
if w.connected {
|
||||
@@ -296,7 +296,7 @@ func (w *Websocket) trafficMonitor(wg *sync.WaitGroup) {
|
||||
|
||||
case <-newtimer.C: // If secondary timer runs state timeout is sent to the data handler
|
||||
if w.verbose {
|
||||
log.Debugf("%v has not received a traffic alert in 15 seconds, exiting", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v has not received a traffic alert in 15 seconds, exiting", w.exchangeName)
|
||||
}
|
||||
w.DataHandler <- fmt.Errorf("trafficMonitor %v", WebsocketStateTimeout)
|
||||
return
|
||||
@@ -308,7 +308,7 @@ func (w *Websocket) trafficMonitor(wg *sync.WaitGroup) {
|
||||
// If not connected dive rt traffic from REST to websocket
|
||||
w.Connected <- struct{}{}
|
||||
if w.verbose {
|
||||
log.Debugf("%v has received a traffic alert. Setting status to connected", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v has received a traffic alert. Setting status to connected", w.exchangeName)
|
||||
}
|
||||
w.connected = true
|
||||
}
|
||||
@@ -722,7 +722,7 @@ func (w *Websocket) manageSubscriptions() error {
|
||||
w.Wg.Add(1)
|
||||
defer func() {
|
||||
if w.verbose {
|
||||
log.Debugf("%v ManageSubscriptions exiting", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v ManageSubscriptions exiting", w.exchangeName)
|
||||
}
|
||||
w.Wg.Done()
|
||||
}()
|
||||
@@ -731,13 +731,13 @@ func (w *Websocket) manageSubscriptions() error {
|
||||
case <-w.ShutdownC:
|
||||
w.subscribedChannels = []WebsocketChannelSubscription{}
|
||||
if w.verbose {
|
||||
log.Debugf("%v shutdown manageSubscriptions", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v shutdown manageSubscriptions", w.exchangeName)
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
time.Sleep(manageSubscriptionsDelay)
|
||||
if w.verbose {
|
||||
log.Debugf("%v checking subscriptions", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v checking subscriptions", w.exchangeName)
|
||||
}
|
||||
// Subscribe to channels Pending a subscription
|
||||
if w.SupportsFunctionality(WebsocketSubscribeSupported) {
|
||||
@@ -771,7 +771,7 @@ func (w *Websocket) subscribeToChannels() error {
|
||||
}
|
||||
if !channelIsSubscribed {
|
||||
if w.verbose {
|
||||
log.Debugf("%v Subscribing to %v %v", w.exchangeName, w.channelsToSubscribe[i].Channel, w.channelsToSubscribe[i].Currency.String())
|
||||
log.Debugf(log.ExchangeSys, "%v Subscribing to %v %v", w.exchangeName, w.channelsToSubscribe[i].Channel, w.channelsToSubscribe[i].Currency.String())
|
||||
}
|
||||
err := w.channelSubscriber(w.channelsToSubscribe[i])
|
||||
if err != nil {
|
||||
|
||||
@@ -286,7 +286,7 @@ func (y *Yobit) SendAuthenticatedHTTPRequest(path string, params url.Values, res
|
||||
hmac := crypto.GetHMAC(crypto.HashSHA512, []byte(encoded), []byte(y.API.Credentials.Secret))
|
||||
|
||||
if y.Verbose {
|
||||
log.Debugf("Sending POST request to %s calling path %s with params %s\n",
|
||||
log.Debugf(log.ExchangeSys, "Sending POST request to %s calling path %s with params %s\n",
|
||||
apiPrivateURL,
|
||||
path,
|
||||
encoded)
|
||||
|
||||
@@ -125,7 +125,7 @@ func (y *Yobit) Run() {
|
||||
|
||||
err := y.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", y.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", y.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ func TestSpotNewOrder(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Test failed - ZB SpotNewOrder: %s", err)
|
||||
} else {
|
||||
fmt.Println(orderid)
|
||||
t.Log(orderid)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -364,7 +364,7 @@ func (z *ZB) wsSend(data interface{}) error {
|
||||
return err
|
||||
}
|
||||
if z.Verbose {
|
||||
log.Debugf("%v sending message to websocket %v", z.Name, string(json))
|
||||
log.Debugf(log.ExchangeSys, "%v sending message to websocket %v", z.Name, string(json))
|
||||
}
|
||||
return z.WebsocketConn.WriteMessage(websocket.TextMessage, json)
|
||||
}
|
||||
@@ -442,7 +442,7 @@ func (z *ZB) wsCreateSubUserKey(assetPerm, entrustPerm, leverPerm, moneyPerm boo
|
||||
func (z *ZB) wsGenerateSignature(request interface{}) string {
|
||||
jsonResponse, err := common.JSONEncode(request)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.ExchangeSys, err)
|
||||
}
|
||||
hmac := crypto.GetHMAC(crypto.HashMD5,
|
||||
jsonResponse,
|
||||
|
||||
@@ -141,7 +141,7 @@ func (z *ZB) Run() {
|
||||
|
||||
err := z.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf("%s failed to update tradable pairs. Err: %s", z.Name, err)
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", z.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user