Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions trader.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,27 @@ class Trader
logger.info message
warn: (message)->
logger.info message
buy: (instrument,amount,cb)=>
buy: (instrument,amount,price,time,cb)=>
@trade
at: @data.at
asset: instrument.asset()
curr: instrument.curr()
platform: instrument.platform
type: 'buy'
amount: amount
price:price
time:time
,cb
sell: (instrument,amount,cb)=>
sell: (instrument,amount,price,time,cb)=>
@trade
at: @data.at
asset: instrument.asset()
curr: instrument.curr()
platform: instrument.platform
type: 'sell'
amount: amount
price:price
time:time
,cb
plot: (series)->
# do nothing
Expand Down Expand Up @@ -94,11 +98,13 @@ class Trader
platform = order.platform
switch order.type
when 'buy'
order.price = @ticker.buy
order.price ?= @ticker.buy
order.time ?= @config.check_order_interval
order.maxAmount = order.amount or @sandbox.portfolio.positions[order.curr].amount / order.price
break
when 'sell'
order.price = @ticker.sell
order.price ?= @ticker.sell
order.time ?= @config.check_order_interval
order.maxAmount = order.amount or @sandbox.portfolio.positions[order.asset].amount
break
platform.trade order, (err,orderId)=>
Expand Down Expand Up @@ -140,7 +146,7 @@ class Trader
if err?
logger.error err
if active
logger.info "Canceling order ##{orderId} as it was inactive for #{@config.check_order_interval} seconds."
logger.info "Canceling order ##{orderId} as it was inactive for #{order.time} seconds."
platform.cancelOrder orderId, (err)=>
if err?
logger.error err
Expand All @@ -151,7 +157,7 @@ class Trader
@trade order, cb
else
orderCb()
,@config.check_order_interval*1000
,order.time*1000
else
orderCb()

Expand Down