File tree Expand file tree Collapse file tree 1 file changed +16
-15
lines changed
Expand file tree Collapse file tree 1 file changed +16
-15
lines changed Original file line number Diff line number Diff line change @@ -53,35 +53,36 @@ fn main() {
5353 . price ( 1.0 )
5454 . amount ( 0.1 )
5555 . finalize ( ) ;
56- match api. exec ( ) {
57- Ok ( res) => {
56+ match api. exec ( )
57+ . and_then ( | res| {
5858 println ! (
5959 "received: {}, remains: {}, order_id: {}" ,
6060 res. received,
6161 res. remains,
6262 res. order_id
6363 ) ;
6464 if res. order_id == 0 {
65- println ! ( "Complete trade." ) ;
66- return ;
65+ panic ! ( "Complete trade." ) ;
6766 }
67+ Ok ( res. order_id )
68+ } )
69+ . and_then ( |order_id| {
6870 let api = CancelOrderBuilder :: new ( )
6971 . access_key ( access_key. clone ( ) )
70- . order_id ( res . order_id )
72+ . order_id ( order_id)
7173 . currency_pair ( Some ( "zaif_jpy" . to_string ( ) ) )
7274 . finalize ( ) ;
7375 let wait_time = time:: Duration :: from_secs ( 5 ) ;
7476 thread:: sleep ( wait_time) ;
75- match api. exec ( ) {
76- Ok ( res) => {
77- println ! ( "Cancel order_id: {}" , res. order_id) ;
78- }
79- Err ( _) => {
80- println ! ( "Failed cancel" ) ;
81- }
82- }
83- }
84- _ => return ,
77+ api. exec ( )
78+ } )
79+ . and_then ( |res| {
80+ println ! ( "Cancel order_id: {}" , res. order_id) ;
81+ Ok ( ( ) )
82+ } ) {
83+
84+ Ok ( _) => println ! ( "Complete trade and cancel" ) ,
85+ Err ( e) => println ! ( "Error: {}" , e) ,
8586 }
8687
8788 let api = ActiveOrdersBuilder :: new ( )
You can’t perform that action at this time.
0 commit comments