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
Conversation
There was a problem hiding this 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 | |||
|
There was a problem hiding this comment.
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.
client/cmd/testbinance/main.go
Outdated
apiKey := extractAPIKey(r) | ||
f.bookedOrdersMtx.Lock() | ||
ord, found := f.bookedOrders[tradeID] | ||
delete(f.bookedOrders, tradeID) |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
client/mm/libxc/binance.go
Outdated
b.mtx.Lock() | ||
oldCM := b.cm | ||
b.cm = cm | ||
b.mtx.Unlock() | ||
if oldCM != nil { | ||
oldCM.Disconnect() | ||
} |
There was a problem hiding this comment.
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?
client/cmd/testbinance/main.go
Outdated
// CancelledOrderID | ||
ClientOrderID: tradeID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// CancelledOrderID | |
ClientOrderID: tradeID, | |
ClientOrderID: hex.EncodeToString(encode.RandomByte(20)) | |
CancelledOrderID: tradeID, |
if closer != nil { | ||
closer.Disconnect() | ||
} | ||
|
There was a problem hiding this comment.
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?
client/mm/libxc/binance.go
Outdated
} | ||
book = newBinanceOrderBook(baseCfg.conversionFactor, quoteCfg.conversionFactor, mktID, getSnapshot, bnc.log) | ||
bnc.books[mktID] = book | ||
go book.sync(ctx) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
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? |
I'll keep an eye on that missing order error. I didn't generate one overnight and it doesn't seem critical. |
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.