Order Book

When the user opens the app they should be given a choice of trading pairs. To view the order book for any trading pair they will have to “subscribe” to that pair. To do so they append their peerinfo (identity/ipaddrs) into the DHT at the key for that trading pair. They also query the DHT to get a list of other subscribers for that trading pair and pick a dozen or so to connect to. They can then query these nodes to get the current order book, which would be a list of LIMIT_OPEN messages (see below).

Limit Orders

When a node wants to place a limit order it will create a serialization of:

Timestamp Expiry Bid/Ask Quantity OrderType UTXO BitcoinPubkey BitcoinSignature Identity IdentitySignature

This LIMIT_OPEN message would then be sent to each peer and then relayed around to all subscribers of that trading pair. Upon receiving the LIMIT_OPEN message (either off the wire or in response to an initial order book download) the node should 1) validate the signatures 2) make the expiration hasn’t passed 3) validate the utxo exists 4) validate the provided bitcoin pubkey matches the pubKeyHash in the utxo output script. If all checks out the limit order can be pushed to the UI to be added to the order book.