const EventEmitter = require('events');

const bindAll = require('../exchangeUtils').bindAll;
const states = require('./states');

// base order

class BaseOrder extends EventEmitter {
  constructor(api) {
    super();

    this.api = api;

    this.checkInterval = 1000;

    this.status = states.INITIALIZING;
    this.emitStatus();

    bindAll(this);
  }

  setData(data) {
    this.data = data;
  }

  emitStatus() {
    this.emit('statusChange', this.status);
  }

  filled(price) {
    this.status = states.FILLED;
    this.emitStatus();

    this.status = states.COMPLETED;
    this.emitStatus();

    this.emit('filled', {
      id: this.id,
      price,
      amount: this.amount
    });

    this.finish(true);
  }

  finish(filled) {
    this.emit('completed', {
      id: this.id,
      filled
    })
  }
}

module.exports = BaseOrder;
@@ -32,16 +32,45 @@
 vents');
+%0Aconst _ = require('lodash');
 %0A%0Aconst 
@@ -289,17 +289,17 @@
 rval = 1
-0
+5
 00;%0A%0A   
@@ -334,16 +334,17 @@
 LIZING;%0A
+%0A
     this
@@ -348,150 +348,1750 @@
 his.
-emitStatus();%0A%0A    bindAll(this);%0A  %7D%0A%0A  setData(data) %7B%0A    this.data = data;%0A  %7D%0A%0A  emitStatus() %7B%0A    this.emit('statusChange', this.status
+completed = false;%0A%0A    bindAll(this);%0A  %7D%0A%0A  submit(%7Bside, amount, price, alreadyFilled%7D) %7B%0A%0A    // Check amount%0A    if(amount %3C this.data.market.minimalOrder.amount) %7B%0A      if(alreadyFilled) %7B%0A        // partially filled, but the remainder is too%0A        // small.%0A        return this.filled();%0A      %7D%0A%0A      // We are not partially filled, meaning the%0A      // amount passed was too small to even start.%0A      throw new Error('Amount is too small');%0A    %7D%0A%0A    // Some exchanges have restrictions on prices%0A    if(%0A      _.isFunction(this.api.isValidPrice) &&%0A      !this.api.isValidPrice(price)%0A    ) %7B%0A      if(alreadyFilled) %7B%0A        // partially filled, but the remainder is too%0A        // small.%0A        return this.filled();%0A      %7D%0A%0A      // We are not partially filled, meaning the%0A      // amount passed was too small to even start.%0A      throw new Error('Price is not valid');%0A    %7D%0A%0A    // Some exchanges have restrictions on lot sizes%0A    if(%0A      _.isFunction(this.api.isValidLot) &&%0A      !this.api.isValidLot(this.price, amount)%0A    ) %7B%0A      if(alreadyFilled) %7B%0A        // partially filled, but the remainder is too%0A        // small.%0A        return this.filled();%0A      %7D%0A%0A      // We are not partially filled, meaning the%0A      // amount passed was too small to even start.%0A      throw new Error('Lot size is too small');%0A    %7D%0A%0A    this.api%5Bthis.side%5D(amount, this.price, this.handleCreate);%0A  %7D%0A%0A  setData(data) %7B%0A    this.data = data;%0A  %7D%0A%0A  emitStatus() %7B%0A    this.emit('statusChange', this.status);%0A  %7D%0A%0A  cancelled() %7B%0A    this.status = states.CANCELLED;%0A    this.completed = true;%0A    this.finish();%0A  %7D%0A%0A  rejected(reason) %7B%0A    this.rejectedReason = reason;%0A    this.status = states.REJECTED;%0A    this.finish(
 );%0A 
@@ -2182,56 +2182,24 @@
 his.
-status = states.COMPLETED;%0A    this.emitStatus()
+completed = true
 ;%0A%0A 
@@ -2333,24 +2333,51 @@
 h(filled) %7B%0A
+    this.completed = true;%0A
     this.emi
@@ -2395,35 +2395,43 @@
 d', %7B%0A      
-id
+status
 : this.
-id
+status
 ,%0A      fill

add generic submit to order