Skip to content

Commit

Permalink
v0.4.6 - Add command to retrive account open orders
Browse files Browse the repository at this point in the history
  • Loading branch information
Ionut Galita committed Apr 28, 2018
1 parent 1a3ae22 commit 6b320b5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Create your strategies based on the examples.
* __exit token__ / __sell token__ - Sells token, if it's currently trading
* __exit token price__ / __sell token price__ - Sells token@price, if it's currently trading
* __cancel token__ / __ignore token__ - Cancel currently trading token
* __orders token__ - Show account open orders. If token is provided, only open orders for that pair will be returned
* __start strategyId__ - Starts strategy
* __stop strategyId__ - Stops strategy
* __list__ - Lists all strategies
Expand Down
24 changes: 22 additions & 2 deletions chat_bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ module.exports = {
for(var j = 0; j < pairs.length; ++j) {
var pair = pairs[j]
if(!pair.amountToSell) continue

var totalBought = strategy.buyTradedInfo(pair).amountMarketPrice
var totalSold = strategy.sellTradedInfo(pair).amountMarketPrice
var sellCurrentPrice = totalSold + (pair.functions.lastPrice() * pair.amountToSell)
Expand Down Expand Up @@ -219,7 +219,27 @@ module.exports = {

this.sendMessage(":grey_question: " + pairName + " - no trading pair found");
}
else if(message.startsWith("start ") || message.startsWith("stop ")) {
else if ((message.startsWith("orders")) || (message.startsWith("o"))) {
this.sendMessage(":speech_balloon:")
var pairName = false

if (message.indexOf(' ') > 0) {
message = message.split(' ')
pairName = message[1].toUpperCase()
}

exchUtils.accountOpenOrders(pairName, (error, response) => {
if(error) {
this.sendMessage(error)
return
}

this.sendMessage(response)
return
})

}
else if(message.startsWith("start ") || message.startsWith("stop ")) {
var split = message.split(" ")
if(split.length < 2) {
this.sendMessage("Name a strategy");
Expand Down
25 changes: 25 additions & 0 deletions exchange_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,31 @@ module.exports = {
});
});
},
accountOpenOrders: function(pairName, next) {
var pair = pairName? pairName : false

binance.openOrders(pair, (error, response) => {
if (error) {
console.log(error)
next(":exclamation: " + pair + " - Pair is not valid (e.g. ETHBTC)")
return
}

if (response.length < 1) {
next(':information_source: No open orders')
return
}

var orders = ":book: Orders"

for (var i=0; i < response.length; i++) {
orders+= "\n" + vars.pairs[response[i]['symbol']].chatName() + " " + response[i]['origQty'] + "@" + response[i]['price'] + "\n"
}

next(null, orders)
return
})
},
normalizeAmount: function(pair, amount, price) {
// Set minimum order amount with minQty
if ( amount < vars.pairsInfo[pair].filters.minQty ) amount = vars.pairsInfo[pair].filters.minQty;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bitprophet",
"version": "0.4.5",
"version": "0.4.6",
"description": "Crypto trading platform for Binance that uses Telegram as its interface",
"main": "bitprophet.js",
"repository": {
Expand Down

0 comments on commit 6b320b5

Please sign in to comment.