You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Create advanced example to fetch orderbook via websocket #9
also we are just about to roll out v3.4 from mango side, i was planning to write a simple order book parser for that purpose. lmk if that causes a conflict on your end.
yeah, we should probably connect directly to the on-chain data rather then through mango-bowl which does a lot of intermediate processing. i'll try to make a simple example of getting the order book via json rpc.
still unclear though how to have a websocket subscription to orderbook update instead of the rpc polling. if you have any code somewhere in other projects which wss'es solana, please let me know.
accountSubscribe is the correct request to implement this, you can either open multiple websockets or subscribe to multiple account updates on the same socket
makes sense. have added two subscriber objects for bids and asks. 8760e57
will have to see how/when to log the required info since the bids and asks are separate wss messages.
do you have any specific way to calculate market depth? that is just the volume of orders at $+% right? would be cool if you already have a logic in rust code or some other mango project to look into before i try to reinvent the wheel.
do you have any specific way to calculate market depth? that is just the volume of orders at $+% right? would be cool if you already have a logic in rust code or some other mango project to look into before i try to reinvent the wheel.
here is an example in C#:
IStreamingRpcClient streamingRpcClient = ClientFactory.GetStreamingClient(Cluster.MainNet);
IMangoClient mangoClient = Solnet.Mango.ClientFactory.GetClient(rpcClient, streamingRpcClient);
AccountResultWrapper<PerpMarket> perpMarket = await mangoClient.GetPerpMarketAsync("DtEcjPLyD4YtTBB4q8xwFZ9q49W89xZCZtJyrGebi5t8"); // BTC-PERP
AccountResultWrapper<OrderBookSide> bidsRequest = await mangoClient.GetOrderBookSideAsync(perpMarket.ParsedResult.Bids, Commitment.Processed); // Bids side of the orderbook
AccountResultWrapper<OrderBookSide> asksRequest = await mangoClient.GetOrderBookSideAsync(perpMarket.ParsedResult.Asks, Commitment.Processed); // Asks side of the orderbook
List<OpenOrder> bids = bidsRequest.ParsedResult.GetOrders().OrderByDescending(o => o.RawPrice).ToList();
List<OpenOrder> asks = asksRequest.ParsedResult.GetOrders().OrderBy(o => o.RawPrice).ToList();
long midPrice = (bids[0].RawPrice + asks[0].RawPrice) / 2;
double midLessDepth = midPrice * 0.98; // 2%
long depth = bids.Where(o => o.RawPrice > midLessDepth).Sum(o => o.RawQuantity);
Activity
papadpickle commentedon Feb 21, 2022
i have started working on this one.
would be good to have a board to mark it as in progress lest someone else starts this from scratch in parallel.
mschneider commentedon Feb 21, 2022
created a board: https://github.com/mschneider/solcpp/projects/1
mschneider commentedon Feb 21, 2022
also we are just about to roll out v3.4 from mango side, i was planning to write a simple order book parser for that purpose. lmk if that causes a conflict on your end.
papadpickle commentedon Feb 21, 2022
i am using the mango bowl wss server to subscribe to the data. not sure if the rollout to newer mango version will affect that or not.
https://github.com/papadpickle/solcpp/blob/example_orderbook/examples/orderbookSubscribe/orderbookSubscribe.cpp
let me know if you had something else in the mind re this orderbook parsing example.
mschneider commentedon Feb 21, 2022
yeah, we should probably connect directly to the on-chain data rather then through mango-bowl which does a lot of intermediate processing. i'll try to make a simple example of getting the order book via json rpc.
mschneider commentedon Feb 22, 2022
9deb4c9
here's a rough sketch of the code to parse the order book
papadpickle commentedon Feb 22, 2022
thanks for the rough idea. added lowest asks now https://github.com/papadpickle/solcpp/blob/example_orderbook_subscribe/examples/orderbookSubscribe.cpp
still unclear though how to have a websocket subscription to orderbook update instead of the rpc polling. if you have any code somewhere in other projects which wss'es solana, please let me know.
mschneider commentedon Feb 23, 2022
accountSubscribe is the correct request to implement this, you can either open multiple websockets or subscribe to multiple account updates on the same socket
papadpickle commentedon Feb 23, 2022
makes sense. have added two subscriber objects for bids and asks. 8760e57
will have to see how/when to log the required info since the bids and asks are separate wss messages.
papadpickle commentedon Feb 25, 2022
do you have any specific way to calculate market depth? that is just the volume of orders at $+% right? would be cool if you already have a logic in rust code or some other mango project to look into before i try to reinvent the wheel.
that''s the remaining part, everything else is ready at https://github.com/papadpickle/solcpp/tree/example_orderbook_subscribe_sol
mschneider commentedon Feb 25, 2022
noticed you use
getSpreadBspin your code, i think BPS is a more common abbreviation for basis pointssean-thorburn commentedon Feb 25, 2022
here is an example in C#: