Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor according to DDD specs #11

Merged
merged 71 commits into from
Dec 10, 2020
Merged

Conversation

louisinger
Copy link
Contributor

@louisinger louisinger commented Dec 2, 2020

This PR refactor the feeder code to follow DDD architecture, it keeps the base implementation but adds a layer of abstraction and changes the structure of the code.

Domain
Basically there is three interfaces to understand:

  • a Feed is a source of market prices information such as Kraken API for instance.
  • a Target represents the thing that will change the market price.
  • a TdexFeeder gets a slice of Feed and a slice of Target, it listens for feeds and then replicate data to targets.

See the scheme in README for a global overview

Ports
The ports package implements external interfaces. For now there is krakenWebSocket.go that implements a kraken WS feed and tdexDaemonPriceUpdater.go that implements the GRPC call of UpdateMarketPrice.

Application
Application package implements services used by the UI.

  • The FeedService handles kraken web socket feed.
  • The UpdaterService implements the domain.Target interface for the TDexDaemon.
  • The FeederService takes a FeedService, creates a Feeder and target an UpdaterService --> this is the feederd implementation.

Adapters
The adapters pacakge only handle the configService that manage serialization and deserialization of Config JSON file and create a feederService depending of data inside it.

The PR also adds some unit testing + an integration test for feederd

The problem of Kraken web socket

To be clear: the feeder seems to work but I've some problem with socket reading.
I have taken over the method of the current version : the ReadMessages method of websocket package. This method has one drawback: it does not sort the messages received by Kraken. However, KrakenWS sends several types of messages (subscribe, heartbeat, prices etc...) --> so here, It seems that I receive only one "price" message from Kraken, and then I only receive "Heartbeat". I'm not aware off web sockets so I probably miss something.

what I would do: Use go-kraken instead of websocket package. This is a go lib that manages all the Kraken web sockets stuffs. What's your opinion about it ?

Questions / TO DO

Interval: @francismars you have implemented an interval for each Market --> I do not replicate that because I don't understand why we need an interval for each market ? And why the user should modify it ? Please enlighten me on this.

Daemon macaroon: this was not used. I confess that I haven't done much research on this point but it seems to me that Macaroon is not implemented yet?

Global project structure: I'm note sure of what I did with project structure (all in internal because there is not "exported" packages for me)

DDD: First time that I try DDD alone so be indulgent and do not hesitate to criticize the architecture of what I did --> I would like progress on this.

@sekulicd @tiero @francismars @altafan please review

it closes #10

Copy link
Contributor

@tiero tiero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would Log the price and the kraken ticker everytime we push an update into the daemon

cmd/feederd/main.go Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
Dockerfile Show resolved Hide resolved
Copy link
Contributor

@tiero tiero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the feeder against a local tdex-daemon

config.json

{
    "daemon_endpoint": "127.0.0.1:9000",
    "kraken_ws_endpoint": "ws.kraken.com",
    "markets": [
        {
            "base_asset": "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225",
            "quote_asset": "6be29b1596fd3c0424f4b6eadb09d01ffdc1757ff15ea12a48a1535a01906978",
            "kraken_ticker": "XBT/USDT",
            "interval": 1000
        }
    ]
}

My MarketPrice RPC request/response

{
"market": {
        "base_asset": "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225",
        "quote_asset": "6be29b1596fd3c0424f4b6eadb09d01ffdc1757ff15ea12a48a1535a01906978"
      },
  "type": 0,
  "amount": 100,
  "asset": "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"
}
{
  "prices": [
    {
      "price": {
        "base_price": 0.0000545214643352665,
        "quote_price": 0.0000545214643352665
      },
      "fee": {
        "basis_point": "25"
      },
      "amount": "0",
      "asset": "6be29b1596fd3c0424f4b6eadb09d01ffdc1757ff15ea12a48a1535a01906978"
    }
  ]
}

@tiero
Copy link
Contributor

tiero commented Dec 9, 2020

Gracefully handle the shutdown

2020/12/09 19:55:20 waiting 1s until reconnect...
2020/12/09 19:55:21 reconnect attempt 1/5
2020/12/09 19:55:21 connecting ws to wss://ws.kraken.com
2020/12/09 19:55:21 socket disconnect
2020/12/09 19:55:21 waiting 1s until reconnect...
2020/12/09 19:55:22 reconnect attempt 1/5
2020/12/09 19:55:22 socket disconnect
2020/12/09 19:55:22 waiting 1s until reconnect...
2020/12/09 19:55:22 websocket connection closed
2020/12/09 19:55:22 reconnect failed: websocket connection closed
2020/12/09 19:55:22 socket disconnect: websocket connection closed
2020/12/09 19:55:22 Shutdown listen upstream
2020/12/09 19:55:22 connecting ws to wss://ws.kraken.com
2020/12/09 19:55:22 Shutdown listen upstream
2020/12/09 19:55:22 Shutdown listen upstream
2020/12/09 19:55:23 Shutdown control heartbeat
2020/12/09 19:55:23 Shutdown control heartbeat
2020/12/09 19:55:23 reconnect attempt 1/5
2020/12/09 19:55:23 Shutdown listen disconnect
2020/12/09 19:55:23 Shutdown listen upstream
2020/12/09 19:55:23 websocket connection closed
2020/12/09 19:55:23 reconnect failed: websocket connection closed
2020/12/09 19:55:23 Shutdown control heartbeat
panic: send on closed channel

goroutine 71 [running]:
github.com/aopoltorzhicky/go_kraken/websocket.(*Client).close(...)
	/home/tiero/go/pkg/mod/github.com/aopoltorzhicky/go_kraken/[email protected]/client.go:283
github.com/aopoltorzhicky/go_kraken/websocket.(*Client).exit(...)
	/home/tiero/go/pkg/mod/github.com/aopoltorzhicky/go_kraken/[email protected]/client.go:258
github.com/aopoltorzhicky/go_kraken/websocket.(*Client).reconnect(0xc0001d4140, 0x0, 0x0, 0x0, 0x0)
	/home/tiero/go/pkg/mod/github.com/aopoltorzhicky/go_kraken/[email protected]/client.go:245 +0x389
github.com/aopoltorzhicky/go_kraken/websocket.(*Client).listenDisconnect(0xc0001d4140)
	/home/tiero/go/pkg/mod/github.com/aopoltorzhicky/go_kraken/[email protected]/client.go:149 +0x345
created by github.com/aopoltorzhicky/go_kraken/websocket.(*Client).reset
	/home/tiero/go/pkg/mod/github.com/aopoltorzhicky/go_kraken/[email protected]/client.go:189 +0x58
make: *** [Makefile:44: run-linux] Error 2
tdex-feeder refactoring 🔒  ✏️ 1 

internal/domain/tdexFeeder.go Outdated Show resolved Hide resolved
internal/domain/tdexFeeder.go Outdated Show resolved Hide resolved
@louisinger louisinger requested a review from tiero December 10, 2020 13:01
cmd/feederd/config.test.json Outdated Show resolved Hide resolved
@louisinger louisinger requested a review from tiero December 10, 2020 13:54
@tiero tiero merged commit 488cd2b into tdex-network:master Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feeder] Refactor code to follow DDD structure
2 participants