-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improving structure, added End 2 End test and unified model for output
- Loading branch information
Showing
9 changed files
with
187 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package wsgateway_test | ||
|
||
import ( | ||
wsgateway "github.com/AlnsV/go-crypto-ws-gateway" | ||
"github.com/AlnsV/go-crypto-ws-gateway/pkg/model" | ||
"github.com/caarlos0/env" | ||
"github.com/pkg/errors" | ||
logger "github.com/sirupsen/logrus" | ||
"testing" | ||
"time" | ||
) | ||
|
||
type config struct { | ||
FTXAPIKey string `env:"FTX_API_KEY"` | ||
FTXAPISecret string `env:"FTX_API_SECRET"` | ||
} | ||
|
||
func New() (*config, error) { | ||
var cfg config | ||
|
||
if err := env.Parse(&cfg); err != nil { | ||
return nil, errors.Wrap(err, "error with initializing config") | ||
} | ||
|
||
return &cfg, nil | ||
} | ||
|
||
func TestGateway(t *testing.T) { | ||
cfg, _ := New() | ||
client, err := wsgateway.BuildWSClient( | ||
"FTX", | ||
cfg.FTXAPIKey, | ||
cfg.FTXAPISecret, | ||
) | ||
if err != nil { | ||
logger.Error(err) | ||
} | ||
|
||
err = client.Connect() | ||
if err != nil { | ||
logger.Error(err) | ||
} | ||
|
||
err = client.Listen( | ||
[]string{"BTC-PERP", "SOL-PERP"}, | ||
func(trade *model.Trade) { | ||
logger.Infoln(trade) | ||
}, | ||
) | ||
if err != nil { | ||
logger.Error(err) | ||
} | ||
|
||
time.Sleep(2 * time.Second) | ||
client.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package model | ||
|
||
import "time" | ||
|
||
type Trade struct { | ||
//Price of the settled trade | ||
Price float64 | ||
|
||
// Side of trade, may be Buy or Sell | ||
Side string | ||
|
||
// Size Amount of currency traded | ||
Size float64 | ||
|
||
Timestamp time.Time | ||
|
||
// Market base-quote pair | ||
Market string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package parse | ||
|
||
import ( | ||
"strings" | ||
"time" | ||
) | ||
|
||
func ParseTimestamp(timestamp string, tz *time.Location) (time.Time, error) { | ||
date, err := time.ParseInLocation(time.RFC3339Nano, timestamp, tz) | ||
if err != nil { | ||
date, errTwo := time.ParseInLocation( | ||
time.RFC3339Nano, | ||
strings.Replace(timestamp, " ", "T", 1), | ||
tz, | ||
) | ||
if errTwo != nil { | ||
dateStr := strings.Replace(timestamp, " ", "T", 1) | ||
date, errThree := time.ParseInLocation( | ||
time.RFC3339Nano, | ||
dateStr+"+00:00", | ||
tz, | ||
) | ||
if errThree != nil { | ||
return time.Now().UTC(), errThree | ||
} | ||
return date, nil | ||
} | ||
return date, nil | ||
} | ||
return date, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package parse | ||
|
||
import ( | ||
"log" | ||
"testing" | ||
"time" | ||
) | ||
|
||
var ( | ||
timezone, _ = time.LoadLocation("UTC") | ||
) | ||
|
||
func TestParseTimestamp(t *testing.T) { | ||
date, err := ParseTimestamp("2020-03-14T12:02:05.000234", timezone) | ||
if err != nil { | ||
t.Log(err) | ||
} | ||
log.Print(date) | ||
dateTwo, errTwo := ParseTimestamp("2020-03-14 12:02:05.000234", timezone) | ||
if errTwo != nil { | ||
t.Log(errTwo) | ||
} | ||
log.Print(dateTwo) | ||
dateThree, errThree := ParseTimestamp("2020-03-14T12:02:05.000234Z", timezone) | ||
if errThree != nil { | ||
t.Log(errThree) | ||
} | ||
log.Print(dateThree) | ||
_, errFour := ParseTimestamp("2020-0314 12:005.000234Z", timezone) | ||
if errFour == nil { | ||
t.Log("timestamp should not be parsed") | ||
} | ||
} |