Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added go-ws web streaming SDK. * Added missing go.sum * Updated Readme for go-ws * Renamed Reconnect to ResetConnection to reflect intent! * Applied fix for Issue #110 * Updated sample code * Removed test covering volume bug * Updated code comment.
- Loading branch information
1 parent
dd87296
commit 1c5f92b
Showing
19 changed files
with
1,328 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
|
||
## Installation | ||
|
||
Install the following dependencies: | ||
|
||
```shell | ||
go mod download github.com/bitly/go-simplejson | ||
go mod download github.com/shopspring/decimal | ||
go mod download github.com/gorilla/websocket | ||
``` | ||
|
||
|
||
## Run examples: | ||
|
||
```bash | ||
cd /path/to/workspace | ||
export GOPATH=/path/to/workspace | ||
go get -u github.com/CoinAPI/coinapi-sdk/data-api/go-ws | ||
wget -v https://raw.githubusercontent.com/coinapi/coinapi-sdk/master/go-ws/main.go | ||
# update api key inside main.go | ||
go run ./main.go | ||
``` |
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,10 @@ | ||
package api | ||
|
||
import . "go-ws/api/types" | ||
|
||
func NewSDK(apiKey string) (sdk SDK) { | ||
validateApiKey(apiKey) | ||
config := getSDKConfig(apiKey) | ||
sdk = getSDK(config) | ||
return sdk | ||
} |
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,16 @@ | ||
package types | ||
|
||
type SdkConfig struct { | ||
ApiKey string | ||
ApiVersion ApiVersion | ||
EnvironmentType EnvironmentType | ||
ReconnectType ReconnectType | ||
} | ||
|
||
// WsConfig webservice configuration | ||
type WsConfig struct { | ||
ApiKey string | ||
Endpoint string | ||
WebsocketKeepalive bool | ||
WebsocketTimeout int | ||
} |
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,48 @@ | ||
package types | ||
|
||
// ApiVersion custom ENUM for SDK forward compatibility | ||
type ApiVersion int | ||
|
||
const ( | ||
ApiV1 ApiVersion = iota | ||
) | ||
|
||
// EnvironmentType | ||
// https://docs.coinapi.io/#endpoints-2 | ||
type EnvironmentType int | ||
|
||
const ( | ||
ProdEncrypted EnvironmentType = iota | ||
ProdInsecure | ||
TestEncrypted | ||
TestInsecure | ||
) | ||
|
||
// MessageType replicates the official incoming message types as (kinda) string enum. | ||
// https://docs.coinapi.io/#messages | ||
type MessageType string | ||
|
||
const ( | ||
TRADE MessageType = "trade" | ||
QUOTE MessageType = "quote" | ||
BOOK_L2_FULL MessageType = "book" // Orderbook L2 (Full) | ||
BOOK_L2_TOP_5 MessageType = "book5" // Orderbook L2 (5 best Bid / Ask) | ||
BOOK_L2_TOP_20 MessageType = "book20" // Orderbook L2 (20 best Bid / Ask) | ||
BOOK_L2_TOP_50 MessageType = "book50" // Orderbook L2 (50 best Bid / Ask) | ||
BOOK_L3_FULL MessageType = "book_l3" // Orderbook L3 (Full) https://docs.coinapi.io/#orderbook-l3-full-in | ||
OHLCV MessageType = "ohlcv" | ||
VOLUME MessageType = "volume" | ||
HEARTBEAT MessageType = "hearbeat" // DO NOT FIX! it's a typo in the official msg spec! | ||
ERROR MessageType = "error" // Otherwise processMessage(.) fails to handle heartbeat messages! | ||
EXCHANGERATE MessageType = "exrate" | ||
RECONNECT MessageType = "reconnect" | ||
) | ||
|
||
// ReconnectType defines the reconnect behavior upon receiving a reconnect message | ||
// https://docs.coinapi.io/#reconnect-in | ||
type ReconnectType int | ||
|
||
const ( | ||
OnConnectionClose ReconnectType = iota | ||
OnReconnectMessage | ||
) |
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,11 @@ | ||
package types | ||
|
||
// InvokeFunction is a unified function type for all event handlers. | ||
// https://yourbasic.org/golang/function-pointer-type-declaration/ | ||
type InvokeFunction func(message *DataMessage) (err error) | ||
|
||
// WsHandler handle raw websocket message | ||
type WsHandler func(message []byte) | ||
|
||
// WsErrHandler handles raw websocket errors | ||
type WsErrHandler func(err error) |
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,23 @@ | ||
package types | ||
|
||
type SDK interface { | ||
SendHello(hello *Hello) (err error) | ||
OpenConnection() (err error) | ||
CloseConnection() (err error) | ||
// ResetConnection hard reset: closes current connection, opens a new one, | ||
// and resends the last hello message. No message buffering! | ||
ResetConnection() (err error) | ||
|
||
// sys handlers | ||
SetErrorInvoke(function InvokeFunction) | ||
SetHeartBeatInvoke(function InvokeFunction) | ||
SetReconnectInvoke(function InvokeFunction) | ||
|
||
// Data handlers | ||
SetExRateInvoke(function InvokeFunction) | ||
SetTradesInvoke(function InvokeFunction) | ||
SetQuoteInvoke(function InvokeFunction) | ||
SetBookInvoke(function InvokeFunction) | ||
SetOHLCVInvoke(function InvokeFunction) | ||
SetVolumeInvoke(function InvokeFunction) | ||
} |
Oops, something went wrong.