Comments (3)
@fredfortier Unfortunately, there is not. Feel free to submit a PR.
Ps.: I will be unresponsive for few days, xmas holiday.
from binance-rs.
@fredfortier I added a way to break the event_loop, not sure if it is the best solution. Basically, it allows the user breaks the event loop on application level by using a Boolean.
In the example below, it watches the Bitcoin price and if it reaches 7300, it breaks the event loop and disconnects from the websocket.
fn last_price() {
let keep_running = AtomicBool::new(true); // It is used to control the event_loop
let agg_trade: String = format!("!ticker@arr");
let mut btcusdt: f32 = "0".parse().unwrap();
let mut web_socket: WebSockets = WebSockets::new(|event: WebsocketEvent| {
match event {
WebsocketEvent::DayTicker(ticker_events) => {
for tick_event in ticker_events {
if tick_event.symbol == "BTCUSDT" {
btcusdt = tick_event.average_price.parse().unwrap();
let btcusdt_close: f32 = tick_event.current_close.parse().unwrap();
println!("{} - {}", btcusdt, btcusdt_close);
if btcusdt_close as i32 == 7300 {
// Break the event loop
keep_running.store(false, Ordering::Relaxed);
}
}
}
},
_ => (),
};
Ok(())
});
web_socket.connect(&agg_trade).unwrap(); // check error
if let Err(e) = web_socket.event_loop(&keep_running) {
match e {
err => {
println!("Error: {}", err);
}
}
}
web_socket.disconnect().unwrap();
println!("disconnected");
}
So, I changed the event_loop signature and introduced a disconnect method.
pub fn event_loop(&mut self, running: &AtomicBool) -> Result<()> {
...
}
Please let me know if it works for your case and if you have a suggestion or better solution.
from binance-rs.
@fredfortier I will close this issue, please reopen it if it did not work as expected. I will also add async support in a few days to the library.
from binance-rs.
Related Issues (20)
- receiving error code -2010 on market_buy_using_quote_quantity, it should not happen
- How to handle disconnect after 24 hour? HOT 1
- Benchmarks are out of date
- Client construction API change
- are the single-variant enums required?
- -
- Timeout Error on loop of fetching future trade data HOT 1
- Support for Multiple Streams With Config HOT 3
- Issues creating stop-limit orders
- how to subscribe binance future orders event ?
- binance future customer order request can not set newClientOrderId
- binance::errors::Error cannot be shared between threads safely
- Os { code: 24, kind: Uncategorized, message: "Too many open files"
- Batch orders implementation for Futures?
- cancelReplace function for both spot and futures?
- add support for maintaining a local order book
- Can't import library after latest FFI change HOT 1
- update USER STREAM code in Doc
- How to create a margin limit/market order?
- How to subscribe to multiple without blocking
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from binance-rs.