Giter VIP home page Giter VIP logo

binance-oco's People

Contributors

dependabot[bot] avatar rogerwatkins avatar tony-ho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

binance-oco's Issues

What do you use this for?

Hi there! This looks interesting.

I'm wondering what for and how do you use binance-oco.

Like, are you trading, then use switch to the CLI for extra funcionality that Binance's GUI doesn't provide?

Thanks a bunch!

Scaled Orders

Just a inquiry really. How much work would it be to implement a scaled order type of feature?
i.e.

  1. Set lowest bid, highest bid, amount and order count. Perhaps Distribution as well (buy more at lower bid). SL and Target set as well.
  2. Bot Executes bids and as each one is filled creates the Stop Loss order.
  3. If target met, cancel SL and sell.

This is doing string comparisons, not numbers, for the prices

This is doing string comparisons, not numbers, for the prices.

The functions to adjust the input prices return strings. So comparing a price of 56 vs 87 would work. But comparing 100 vs 56 would think that 56 is bigger because it compares the strings and not their numeric values.

I've fixed this and done some other work on my fork. Note my fork is not well tested so use it at your own risk.

I dont have time to make a pull request at the moment Tony, but many thanks for releasing this code!

Entry, stop and take profit and go sleep

All I want is set a buy entry (above the current price) and once this order is triggered put a take profit and stop loss

Example with btc (wich is now at ~8000):

Buy when btc is at 11000 with take profit at 12000 and stop loss at 9000

This bot can do that? How can I do that?

Doesn't Consider Fee

Hi, first off nice project - thanks. Hopefully I can help contribute to it though I'm only a beginner programmer.

There's a sell error thrown after setting a limit and stop loss order.

BNBBTC BUY LIMIT ORDER #86467834 (FILLED)
..price: 0.00149770, quantity: 1.00000000
Sell error {"code":-2010,"msg":"Account has insufficient balance for requested action."}

Reason is Binance takes a fee and then we don't have enough to set that sell order.

Is this valid for Margin Trading?

Is this code valid for trading in margin account? or futures? otherwise could you add this feature using a environment variable or something ?
thanks

Scale out logic broken in recent 2.0 update

It looks like the OCO logic has broken in the 2.0 update when using the scale-out option. Instead of implementing a one-cancels-the-other trade it simply sets two orders immediately - one at the target and one at the stop loss based on the scale out amount. This logic does not protect the full trade with the stop loss anymore. It should only "scale out" once the target is reached.

For example shouldn't it do the following?

binance-oco -p BNBBTC -a 3 -b 0.002 -s 0.001 -t 0.003 -S 2

  • Set stop loss at .001 for quantity 3
  • Monitor the price
  • If target is reached (0.003):
    • Cancel the stop limit order at 0.001
    • Set a limit sell at .003 for quantity 2
    • Set a stop limit order at .001 for quantity 1

This logic protects the full trade with the initial stop loss, scales out the desired amount once the target is reached, and leaves quantity 1 in the trade while leaving that 1 protected with a stop loss.

2.1.1 Limit sell order error

When placing an order with only sell limit orders and stop limit orders the command line values do not translate to a proper exchange API call. For example, I attempted to set a sell limit order of a coin for a price at $86.2 but the exchange received a price of $8.92 instead. Fortunately the exchange rejected the order.

Is it possible that the recent logic that was added for trades that started with a buy order messed up the stop limit order logic?

how to do this ?

say I have 1 btc now the price is 15000 and set a sell order at 20000 usdt.when price hit 20000 sell it at 19500. and when price down to 14500 cancel the sell order and set a limit sell at 14000.
so it is more risk-less, can you do this?

Order does not exist

Hello Tony,
Awesome script, thank you for your crazy work!

Very often (50% of the time) I have an issue when I place a buy order followed by an OCO. I've noticed that the order is sent to Binance (appears in my orders list) but then your script is not able to find the order on Binance. I suspect your script is too fast and should wait few milliseconds/seconds before going to the next step. Here is an example :

binance-oco -p NEOUSDT -a 19 -b 23.01 -s 22.43 -t 23.70                                            
  binance-oco Validating stop order: { symbol: 'NEOUSDT', side: 'SELL', quantity: '19.000', price: '4.870', stopPrice: '22.430', type: 'STOP_LOSS_LIMIT' } +0ms
  binance-oco Stop order valid +281ms
  binance-oco Validating target order: { symbol: 'NEOUSDT', side: 'SELL', quantity: '19.000', price: '23.700', type: 'LIMIT' } +1ms
  binance-oco Target order valid +251ms
  binance-oco NEOUSDT price: 24.32000000 +258ms
  binance-oco Buy response: { symbol: 'NEOUSDT', orderId: 370401142, orderListId: -1, clientOrderId: 'keVtUj4bf7AYxnTiN4gMco', transactTime: 1611396491263, price: '23.01000000', origQty: '19.00000000', executedQty: '0.00000000', cummulativeQuoteQty: '0.00000000', status: 'NEW', timeInForce: 'GTC', type: 'LIMIT', side: 'BUY', fills: [] } +265ms
  binance-oco order id: 370401142 +0ms
/usr/local/lib/node_modules/binance-oco/node_modules/binance-api-node/dist/http-client.js:59
        error = new Error(json.msg || "".concat(res.status, " ").concat(res.statusText));
                ^

Error: Order does not exist.
    at /usr/local/lib/node_modules/binance-oco/node_modules/binance-api-node/dist/http-client.js:59:17
    at processTicksAndRejections (node:internal/process/task_queues:94:5) {
  code: -2013,
  url: 'https://api.binance.com/api/v3/order?symbol=NEOUSDT&orderId=370401142&timestamp=1611396491331&signature=ce0986ef0fd12aca548861ae53fa607fe47b8024a79b76cb925a4aeb561f7e9b'
}

OCO Function

Thanks for writing this script. I was in the middle of writing my own OCO bot in python for binance when I found this.

I've done a few cheap test runs of the OCO function and the script seems to be hung up after the buy order and sell-limit orders are FILLED. The trading pair price clearly went above my targets, but the bot did nothing. No cancellation of the previous stop-limit order and no new sell-limit order placed at the target. There were no "trade update.." console messages printed. The last message printed was the sell-limit order id. Same results whether I do a buy limit order or a buy market order (price of 0).

test run example:
binance-oco -p BTCUSDT -a .002 -b 0 -t 8425 -s 8400

Version 1.2.1
Windows 10 w/ all necessarily dependencies

I'm not as familiar with javascript, but could there be a logical error in here?:

const placeSellOrder = function () { if (stopPrice) { placeStopOrder(); } else if (targetPrice) { placeTargetOrder(); } else { process.exit(); } };

If the user supplies both the stopPrice and the targetPrice, the 2nd else if will never be executed.

Thanks in advance - looking forward to using this.

put a trade bellow using the same coin

lets say i have the bot running with the parameters to buy at 10000, stop at 9000 and take profit at 11000

but i believe there is another point bellow wich can be a good entry point, for example, 7000. Can i open another instance of the bot to buy at 7000 with take profit at 8000 and stop at 6000 or one instance will afect the other?

thanks in advance

Feature Request - Safe Exit to USDT after ALT/BTC trade

I was trying to find the comment/request section but failed so I figured I'd ask here. With the frequent volatility of BTC trades can go upside down overnight even after a successful OCO trade if $ is left in BTC. What do you think of adding a feature that does something like this:

  • Enter an ALT/BTC trade with a S/L and target like normal
  • If S/L hit:
    • Sell executes automatically to BTC (current feature)
    • Execute a market sell to USDT (new feature)
  • If Target hit:
    • Cancel S/L (current feature)
    • Set Target sell (current feature)
    • After target sell is filled, Execute a market sell to USDT (new feature)

Just a thought to avoid a scenario where your ALT/BTC trade is up 5%, but BTC drops 5% within hours and you're at a loss or breaking even.

Thanks for considering!
@tony-ho

waitForSellOrderFill(...).finally is not a function

Hi,

I've been trying to play around with binance-oco but I'm receiving an error:

jorijn@x:~$ binance-oco -p BNBUSDT -a 0.5 -s 26.6 -t 26.9
  binance-oco Validating stop order: { symbol: 'BNBUSDT', side: 'SELL', quantity: '0.50', price: '20.0001', stopPrice: '26.6000', type: 'STOP_LOSS_LIMIT' } +0ms
  binance-oco Stop order valid +350ms
  binance-oco Validating target order: { symbol: 'BNBUSDT', side: 'SELL', quantity: '0.50', price: '26.9000', type: 'LIMIT' } +1ms
  binance-oco Target order valid +522ms
  binance-oco Sell response: { symbol: 'BNBUSDT', orderId: xxxxx, clientOrderId: 'xxxx', transactTime: 1564489146179, price: '20.00010000', origQty: '0.50000000', executedQty: '0.00000000', cummulativeQuoteQty: '0.00000000', status: 'NEW', timeInForce: 'GTC', type: 'STOP_LOSS_LIMIT', side: 'SELL', stopPrice: '26.60000000', fills: [] } +298ms
  binance-oco order id: 206171384 +1ms
  binance-oco waitForSellOrderFill(...).finally is not a function +0ms

Am I doing something wrong?

The order remained active on the exchange after the process crashed.

Also, I've read that it keeps the stop-loss order until the target price has been reached. I'd like to give a base price (e.g. buying price) and have the script check:

  • if current price above buy price; then set limit sell
  • if current price below buy price; then set stop-limit sell (loss)

This way the order is always placed in the order book ahead of time and will trigger in case of a quick wick.

Is this possible?

Thanks!

Information:

$ binance-oco --version
2.4.1
$ node --version
v8.9.4
$ npm --version
5.6.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.