npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gafo-binance-oco

v0.0.1-development

Published

A command line tool for placing conditional stop-limit, limit, and OCO (One-Cancels-the-Other) sell orders on Binance

Downloads

5

Readme

Binance Auto Stop & Target OCO (One-Cancels-the-Other)

A command line tool for placing conditional stop-limit, limit, and OCO (One-Cancels-the-Other) sell orders on Binance cryptocurrency exchange.

Installation

Prerequisites: Node.js

The easiest way to get started is to install binance-oco globally. Open a terminal/command prompt and run the command below. Note: You may need to use sudo (for macOS, *nix etc), or run your command shell as Administrator (for Windows) to do this.

npm install -g binance-oco

This will add the binance-oco command to your system path, allowing it to be run from any folder.

Configuration

Create a file called .env in the folder from where you want to run binance-oco, and add your Binance API key in the following format. Replace BINANCE_API_KEY with your API key and BINANCE_API_SECRET with your API secret.

Usage

binance-oco

Market and limit buy orders

Place a market buy order for 1 BNB:

binance-oco -p BNBBTC -a 1 -b 0

For non market orders, binance-oco determines whether to place a limit or stop-limit buy order based on the current price.

eg. If the current BNBBTC price is at or above 0.002 BTC, place a limit buy order for 1 BNB @ 0.002 BTC. If the current BNBBTC price is below 0.002 BTC, place a stop-limit buy for 1 BNB with stop price @ 0.002 BTC.

binance-oco -p BNBBTC -a 1 -b 0.002

If the current BNBBTC price is below 0.002 BTC, place a stop-limit buy for 1 BNB with stop price @ 0.002 BTC, and limit price @ 0.0025 BTC.

binance-oco -p BNBBTC -a 1 -b 0.002 -B 0.0025

Limit prices for stop-limit orders

If specific buy/sell limit prices aren't specified with the -l or -B/-E options respectively, binance-oco sets the limit price for stop-limit orders to emulate a stop market order ie. buy/sell at market price once the stop price has been hit.

To achieve this, limit prices are calculated as follows:

  • Buy limit price set to maximum allowed by available balance and Binance PERCENT_PRICE trading rule
  • Sell limit price set to minimum allowed by Binance MIN_PRICE, MIN_NOTIONAL and PERCENT_PRICE trading rules

Binance will still fill orders at the best price available, but order details may show a very low sell or very high buy price.

See How to use Stop-Limit Function for information on stop-limit orders, and the Binance Trading Rules for details on Binance trading rules.

Stop-limit and limit sell orders

Place a stop-limit sell for 1 BNB @ 0.001 BTC:

binance-oco -p BNBBTC -a 1 -s 0.001

Place a stop-limit sell for 1 BNB with stop price @ 0.002 BTC, and limit price @ 0.001 BTC.

binance-oco -p BNBBTC -a 1 -s 0.002 -l 0.001

Place a limit sell for 1 BNB @ 0.003 BTC:

binance-oco -p BNBBTC -a 1 -t 0.003

Conditional sell orders

Place a buy order for 1 BNB @ 0.002 BTC. Once filled, place a stop-limit sell @ 0.001 BTC:

binance-oco -p BNBBTC -a 1 -b 0.002 -s 0.001

Place a buy order for 1 BNB @ 0.002 BTC. Once filled, place a limit sell @ 0.003 BTC:

binance-oco -p BNBBTC -a 1 -b 0.002 -t 0.003

One-Cancels-the-Other (OCO) sell orders

Place an OCO sell for 1 BNB with:

  • stop price @ 0.001 BTC
  • limit price @ 0.003 BTC
binance-oco -p BNBBTC -a 1 -s 0.001 -t 0.003

Place a buy order for 1 BNB @ 0.002 BTC. Once filled, place an OCO sell for 1 BNB with:

  • stop price @ 0.001 BTC
  • limit price @ 0.003 BTC
binance-oco -p BNBBTC -a 1 -b 0.002 -s 0.001 -t 0.003

Place a buy order for 2 BNB @ 0.002 BTC. Once filled, place:

  • an OCO sell for the scale out amount of 1 BNB with:
    • stop price @ 0.001 BTC
    • limit price @ 0.003 BTC, and
  • a stop-limit sell for the remaining 1 BNB @ 0.001 BTC

This process is referred to as 'scaling out' of a position.

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

See How to Use OCO (One-Cancels-the-Other) Order Type for information on OCO orders.