@@ -22,7 +22,7 @@ const port = 80;
22
22
// Are we in test mode?
23
23
console . log ( "Test Mode: " , binance . getOption ( 'test' ) ) ;
24
24
25
- // Make the EventEmitter that will be triggered by our webhooks
25
+
26
26
var eventEmitter = new events . EventEmitter ( ) ;
27
27
28
28
eventEmitter . on ( 'error' , ( err ) => {
@@ -35,10 +35,6 @@ eventEmitter.on('error', (err) => {
35
35
* For a limit order just add a third parameter, 'price', to marketBuy
36
36
*/
37
37
eventEmitter . on ( 'buy' , ( ) => {
38
- if ( error ) {
39
- console . error ( error ) ;
40
- return ;
41
- }
42
38
binance . marketBuy ( symbol , quantity , ( error , response ) => {
43
39
if ( error ) {
44
40
console . error ( error ) ;
@@ -54,9 +50,6 @@ eventEmitter.on('buy', () => {
54
50
* For a limit order just add a third parameter, 'price', to marketSell
55
51
*/
56
52
eventEmitter . on ( 'sell' , ( ) => {
57
- if ( error ) {
58
- console . error ( error ) ;
59
- }
60
53
binance . marketSell ( symbol , quantity , ( error , response ) => {
61
54
if ( error ) {
62
55
console . error ( error ) ;
@@ -82,9 +75,12 @@ const server = http.createServer((req, res) => {
82
75
body = Buffer . concat ( body ) . toString ( ) ;
83
76
if ( body === 'buy' ) {
84
77
eventEmitter . emit ( 'buy' ) ; // <----------------------- BUY
85
- } else {
78
+ }
79
+
80
+ if ( body === 'sell' ) {
86
81
eventEmitter . emit ( 'sell' ) ; // <---------------------- SELL
87
- }
82
+ }
83
+
88
84
console . log ( body ) ;
89
85
res . statusCode = 200 ;
90
86
res . end ( ) ;
0 commit comments