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

mm: implement full cex api for simnet binance #2737

Merged
merged 4 commits into from Apr 30, 2024

Conversation

buck54321
Copy link
Member

@buck54321 buck54321 commented Apr 16, 2024

In order to fully test the arb bots, we need full control over the markets as well as functional deposits and withdrawals. This branch updates the testbinance program to implement the full binance API. We can add coins and markets as needed.

Market are randomized in a small range around a basis price based on current coinpap fiat rates.

Did a fair amount of refactoring and fixed a couple of bugs.

Adds trace logging for arb-mm bot. Run ./walletpair.sh --simnet --no-embed-site --log MM=trace to enable trace logging for just the mm package.

Copy link
Contributor

@martonp martonp left a comment

Choose a reason for hiding this comment

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

Something is wrong with the orderbook syncing code. If you run TestVWAP in binance_live_test.go you can see in the logs that it's getting the snapshot over and over.

The new testbinance is clutch though.

@@ -2,93 +2,3 @@
// also available online at https://blueoakcouncil.org/license/1.0.0.

package libxc

Copy link
Contributor

Choose a reason for hiding this comment

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

This file can be removed.

apiKey := extractAPIKey(r)
f.bookedOrdersMtx.Lock()
ord, found := f.bookedOrders[tradeID]
delete(f.bookedOrders, tradeID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could keep these around, and just return the order in the cancelled status. Still should log if cancelling an order that was already cancelled.


// Start a ticker to fill booked orders
go func() {
// 50% chance of filling all booked orders every 5 to 30 seconds.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should test partial fills as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think there's a bunch of little tweaks we can make. Will add as needed.

Comment on lines 139 to 145
b.mtx.Lock()
oldCM := b.cm
b.cm = cm
b.mtx.Unlock()
if oldCM != nil {
oldCM.Disconnect()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

When will there ever be a new connection master? Isn't sync only called once after the binanceOrderBook is created?

Comment on lines 931 to 932
// CancelledOrderID
ClientOrderID: tradeID,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// CancelledOrderID
ClientOrderID: tradeID,
ClientOrderID: hex.EncodeToString(encode.RandomByte(20))
CancelledOrderID: tradeID,

if closer != nil {
closer.Disconnect()
}

Copy link
Contributor

Choose a reason for hiding this comment

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

The sync goroutine was just running forever wasn't it?

}
book = newBinanceOrderBook(baseCfg.conversionFactor, quoteCfg.conversionFactor, mktID, getSnapshot, bnc.log)
bnc.books[mktID] = book
go book.sync(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't need a new goroutine anymore.

Copy link
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

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

A couple errors that popped up testing on simnet. From the binance server:

$ ./testbinance 
2024-04-26 15:38:41.438 [INF] C: Server listening on 0.0.0.0:37346
2024-04-26 15:38:41.438 [INF] C: Server listening on [::]:37346
2024-04-26 16:01:30.013 [ERR] TB: DELETE request received from user X-MBX-APIKEY for unknown order 164ea268145dafbfcb9500000001
2024-04-26 16:08:15.019 [ERR] TB: DELETE request received from user X-MBX-APIKEY for unknown order 164ea268145dafbfcb9500000002
2024-04-26 16:15:15.019 [ERR] TB: DELETE request received from user X-MBX-APIKEY for unknown order 164ea268145dafbfcb9500000003
2024-04-26 16:22:15.017 [ERR] TB: DELETE request received from user X-MBX-APIKEY for unknown order 164ea268145dafbfcb9500000004
2024-04-26 16:29:15.021 [ERR] TB: DELETE request received from user X-MBX-APIKEY for unknown order 164ea268145dafbfcb9500000005
2024-04-26 16:36:15.020 [ERR] TB: DELETE request received from user X-MBX-APIKEY for unknown order 164ea268145dafbfcb9500000006

And one for client:

2024-04-26 07:21:13.865 [ERR] MM[CEX-BinanceUS]: Error sending keep-alive request: http error (405) 405 Method Not Allowed

Also audit u.balancesMtx. I had a deadlock at
(*MarketMaker).Status -> (*unifiedExchangeAdaptor).stats
@buck54321
Copy link
Member Author

A couple errors that popped up testing on simnet. From the binance server:

$ ./testbinance 
2024-04-26 15:38:41.438 [INF] C: Server listening on 0.0.0.0:37346
2024-04-26 15:38:41.438 [INF] C: Server listening on [::]:37346
2024-04-26 16:01:30.013 [ERR] TB: DELETE request received from user X-MBX-APIKEY for unknown order 164ea268145dafbfcb9500000001
2024-04-26 16:08:15.019 [ERR] TB: DELETE request received from user X-MBX-APIKEY for unknown order 164ea268145dafbfcb9500000002
2024-04-26 16:15:15.019 [ERR] TB: DELETE request received from user X-MBX-APIKEY for unknown order 164ea268145dafbfcb9500000003
2024-04-26 16:22:15.017 [ERR] TB: DELETE request received from user X-MBX-APIKEY for unknown order 164ea268145dafbfcb9500000004
2024-04-26 16:29:15.021 [ERR] TB: DELETE request received from user X-MBX-APIKEY for unknown order 164ea268145dafbfcb9500000005
2024-04-26 16:36:15.020 [ERR] TB: DELETE request received from user X-MBX-APIKEY for unknown order 164ea268145dafbfcb9500000006

And one for client:

2024-04-26 07:21:13.865 [ERR] MM[CEX-BinanceUS]: Error sending keep-alive request: http error (405) 405 Method Not Allowed

Were you just running an arb-mm bot for a while to get the unknown order errors? I have no idea how the users api key is being parsed as "X-MBX-APIKEY".

@JoeGruffins
Copy link
Member

Were you just running an arb-mm bot for a while to get the unknown order errors? I have no idea how the users api key is being parsed as "X-MBX-APIKEY".

Yeah... I put X-MBX-APIKEY as the api key I think... Maybe you don't need to put anything for simnet?

@buck54321
Copy link
Member Author

I'll keep an eye on that missing order error. I didn't generate one overnight and it doesn't seem critical.

@buck54321 buck54321 merged commit e87b19f into decred:master Apr 30, 2024
5 checks passed
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.

None yet

3 participants