Skip to content

Commit

Permalink
Merge pull request #184 from Lercerss/lercerss/playback_websocket
Browse files Browse the repository at this point in the history
[#178] Playback route impl. using websocket
  • Loading branch information
Lercerss authored Mar 26, 2020
2 parents b2e200b + 6a9e897 commit 6b0fb81
Show file tree
Hide file tree
Showing 15 changed files with 844 additions and 157 deletions.
51 changes: 21 additions & 30 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"build": "NODE_ENV=production react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "eslint src --ext .js,.jsx,.ts,.tsx"
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
"sample-socket": "node src/tests/samples/socket_client.js"
},
"devDependencies": {
"eslint": "^6.1.0",
Expand All @@ -57,7 +58,8 @@
"eslint-plugin-react": "^7.16.0",
"eslint-plugin-react-hooks": "^1.7.0",
"react-test-renderer": "^16.10.2",
"redux-mock-store": "^1.5.4"
"redux-mock-store": "^1.5.4",
"ws": "^7.2.1"
},
"browserslist": {
"production": [
Expand Down
21 changes: 21 additions & 0 deletions app/src/tests/samples/socket_client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// eslint-disable-next-line
const WebSocket = require('ws');

const endpoint = `ws://localhost:5050/playback/SPY/1577892050000000000/?delay=2.0&rateMessages=5`;
// const endpoint = `ws://localhost:5050/playback/SPY/1577892050000000000/?delay=2.0&rateRealtime=0.5`;
console.log(`Connecting to ${endpoint}`);
const ws = new WebSocket(endpoint);

let count = 0;
ws.onopen = () => {
console.log('opened');
};
ws.onmessage = m => {
console.log(m.data);
if (count++ > 10) {
ws.close();
}
};
ws.onclose = () => {
console.log('closed');
};
8 changes: 8 additions & 0 deletions core/graphelier-service/api/hndlrs/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ func (se StatusError) Status() int {
return se.Code
}

type ParamError struct {
Value string
}

func (p ParamError) Error() string {
return p.Value
}

// Env : A struct that represents the database configuration
type Env struct {
Datastore db.Datastore
Expand Down
22 changes: 11 additions & 11 deletions core/graphelier-service/api/hndlrs/obhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/assert"
)

var ob_messages []*models.Message = []*models.Message{
var obMessages []*models.Message = []*models.Message{
MakeMsg(DirectionAsk, OrderID(12), SodOffset(1)),
MakeMsg(DirectionBid, OrderID(13), SodOffset(2)),
MakeMsg(DirectionAsk, OrderID(15), SodOffset(3)),
Expand All @@ -24,13 +24,13 @@ func TestFetchOrderbookDeltaSuccess(t *testing.T) {

mockedDB.EXPECT().
GetSingleMessage("test", int64(1)).
Return(ob_messages[0], nil)
Return(obMessages[0], nil)
mockedDB.EXPECT().
GetOrderbook("test", uint64(1)).
Return(&models.Orderbook{}, nil)
mockedDB.EXPECT().
GetMessagesWithPagination("test", &models.Paginator{NMessages: 3, SodOffset: 0}).
Return(ob_messages, nil)
Return(obMessages, nil)

var deltabook models.Orderbook
err := MakeRequest(
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestFetchOrderbookDeltaNegativeNMessages(t *testing.T) {
Return(&models.Orderbook{Timestamp: 0, LastSodOffset: 0, Instrument: "test"}, nil)
mockedDB.EXPECT().
GetMessagesWithPagination("test", &models.Paginator{NMessages: 5, SodOffset: 0}).
Return(ob_messages, nil)
Return(obMessages, nil)

var deltabook models.Orderbook
err := MakeRequest(
Expand Down Expand Up @@ -139,23 +139,23 @@ func TestFetchOrderbookDeltaExecuteHiddenOrder(t *testing.T) {
mockedDB := MockDb(t)
defer Ctrl.Finish()

test_messages := make([]*models.Message, len(ob_messages))
copy(test_messages, ob_messages)
test_messages = append(
ob_messages,
testMessages := make([]*models.Message, len(obMessages))
copy(testMessages, obMessages)
testMessages = append(
obMessages,
// Add an execute for hideen order
MakeMsg(OrderID(0), SodOffset(4), TypeExecute),
)

mockedDB.EXPECT().
GetSingleMessage("test", int64(1)).
Return(ob_messages[0], nil)
Return(obMessages[0], nil)
mockedDB.EXPECT().
GetOrderbook("test", uint64(1)).
Return(&models.Orderbook{}, nil)
mockedDB.EXPECT().
GetMessagesWithPagination("test", &models.Paginator{NMessages: 4, SodOffset: 0}).
Return(test_messages, nil)
Return(testMessages, nil)

var deltabook models.Orderbook
err := MakeRequest(
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestFetchOrderbookSuccess(t *testing.T) {
Return(&models.Orderbook{Instrument: "test"}, nil)
mockedDB.EXPECT().
GetMessagesByTimestamp("test", uint64(1)).
Return(ob_messages, nil)
Return(obMessages, nil)

var orderbook models.Orderbook
err := MakeRequest(
Expand Down
Loading

0 comments on commit 6b0fb81

Please sign in to comment.