Giter Club home page Giter Club logo

binance-api-client's Introduction

Github stats

binance-api-client's People

Contributors

depfu[bot] avatar elboletaire avatar gemmell avatar vybu 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

Watchers

 avatar  avatar  avatar

binance-api-client's Issues

in my machine the type inference fails with this package, all types appears as any

Hi, something really weird happens with this package, I've installed this through yarn, I set a binanceClient property as the type BinanceApiClient, the editor doesn't show any error nor warning, but it's treating the property as any...and all the types from binance-api-client in my editor appears as any (first time that this happens to me)

import {BinanceApiClient} from 'binance-api-client';

export class Binance {
  binanceClient : BinanceApiClient;

  constructor() {
    this.binanceClient = new BinanceApiClient(....)
    this.binanceClient.getExchangeInfo();

image

I've posted a question on StackOverflow, but I think that it's something related to the package because other libraries work ok, do you know what could be happening and how to solve it?

right now I've copied the files inside my project, pretty weird but it works ok in that way

thank you so much...

STOP_LOSS orders require you to not send timeInForce

Currently buy requires a timeInForce, but actually if you you send a STOP_LOSS you'll get
{"code":-1106,"msg":"Parameter 'timeInForce' sent when not required."} because for STOP_LOSS you're not supposed to send timeInForce.

Better error handling when things go awry

The getAccountData function is failing with the error
TypeError: json.balances is not iterable at new AccountData (c:\tkbt\ML\COINVOL\bigdipper2\node_modules\binance-api-client\src\models\account\AccountData.ts:28:34)

I put a console.log in there and it's actually getting
{ code: -1021, msg: 'Timestamp for this request was 1000ms ahead of the server\'s time.' }

However there's no error handling going on and it's trying to assign internal variables anyway.

Client project Sample

Could you add a simple project to the solution? A kind of simple windows form with a call to a method.
Thanks

Possibility for cors

Hey very nice work,
could you implement a methode for people without a nginx orElse to pass cors.

let apiUrl: URL = new URL(
            Path.join( "/api", apiVersion, accessedResource ),
           --https://cors-anywhere.herokuapp.com/-- "https://api.binance.com"
        );

Filters not initialised

In ExchangeInfo.ts the switch statement doesn't include all of the available types of filter and there is no default. So if it's not either a EXCHANGE_MAX_NUM_ORDERS or EXCHANGE_MAX_ALGO_ORDERS then it gets pushed into this._filters as an undefined.

Ideally I would like a convenience function that uses the filter information to turn a quantity and price in one token into a tradeable amount in another. e.g. qtyForPrice(symOne: "ETH", qty: 1.0, symTwo: "POWER", price: 0.001) which returns a quantity of POWER that obeys the rules for trading quantity.

extra slash in makeRequest ('/api')

Found an issue in BinanceApiClient:

    private async makeRequest(
        httpMethod: HttpMethod,
        apiVersion: ApiVersion,
        accessedResource: string,
        requiredAuthentication: AuthenticationMethod,
        ...parameters: [string, any][]
    ): Promise {
        const apiUrl: URL = new URL(
            Path.join("/api", apiVersion, accessedResource),
            "https://api.binance.com"
        );

forms an url like https://api.binance.com//api/v1/klines?symbol=ETHBTC&interval=1m (with an extra slash) which breaks the functionality for me

Type woes

Unfortunately for typescript, it's type system is an afterthought of Javascript. And binance mostly reports it's numbers using strings in the JSON. So everywhere that a type has been declared as number, and then assigned using something like:

 this._openingPrice = json[ 1 ];

(for example Candlestick), what you end up with is typescript thinking it's got a number, when actually it's a string, because the type system doesn't do the conversion (at least not that I am aware of). Now any time you do something like openingPrice < lastPrice it's actually doing a string comparison. It's like the worst of both worlds.

I think you need to go through and parseFloat everywhere that you expect to be getting a number out of json when binance sends you a string.

Dubious user stream quality

I'm getting this scenario where I just seem to not get any more user stream messages after some amount of time. e.g. I'm putting in buy limit order, it's getting bought, but I don't receive any user update about it. The ws has not disconnected however.

Reading the docs it says:
A User Data Stream listenKey is valid for 60 minutes after creation.
Doing a PUT on a listenKey will extend its validity for 60 minutes.

I can't see the library doing that put, so I'm willing to bet that after 1 hour the server is simply not sending any more data on that websocket, even though it is still connected.

Suggest adding a setTimeout that does a put every 30 minutes or so.

How to use it with Angular-cli

When I'm importing lib getting errors:

ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/BinanceApiClient' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/enums/CandlestickInterval' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/enums/OrderExecutionStatus' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/enums/OrderRejectionMotive' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/enums/OrderSide' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/enums/OrderStatus' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/enums/OrderType' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/enums/RateLimitInterval' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/enums/RateLimitType' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/enums/ResponseType' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/enums/SymbolStatus' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/enums/SymbolType' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/enums/TimeInForce' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/errors/ApiError' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/errors/AuthenticationError' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/account/AccountData' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/account/Balance' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/candlestick/Candlestick' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/depth/LatestPrice' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/depth/OrderBook' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/filter/LotSizeFilter' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/filter/MaxAlgoOrdersFilter' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/filter/MaxOrdersFilter' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/filter/MinimumNotionalFilter' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/filter/PriceFilter' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/filter/RateLimit' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/misc/ExchangeInfo' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/misc/Symbol' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/order/CanceledOrderData' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/order/Order' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/order/OrderAcknowledgement' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/order/OrderFull' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/order/OrderResult' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/order/PlacedOrder' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/order/PlacedOrderFill' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/ticker/Ticker' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/ticker/TickerStatistics' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/trade/Trade' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/websocket/account/AccountUpdate' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/websocket/candlestick/CandlestickUpdate' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/websocket/depth/OrderBookUpdate' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/websocket/order/OrderUpdate' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'
ERROR in ./node_modules/binance-api-client/build/index.js
Module not found: Error: Can't resolve './src/models/websocket/trade/TradeUpdate' in '/Users/georgezagraid/Projects/exchange-navigator/node_modules/binance-api-client/build'

So index.js in build folder refers to unexisting files in build folder. It containse only index.js file.

Implicit conversion of numbers to strings results in invalid requests

If you attempt to buy something with a very low value using BTC, it will fail with a message like "Illegal characters found in parameter 'price'; legal range is '^([0-9]{1,20})(.[0-9]{1,20})?$'". This is because the placeOrder function takes a number which gets implicitly casted to a string. However javascript can represent the number like "1.1e-8" which is not in the valid set of numbers described by binance. You can probably use something like toFixed to force it to a specific representation (preferably using the information about how many decimals the particular pair uses, but I guess toFixed(20) would also adhere to the API).

Type 'undefined' cannot be used as an index type.

My setup is warning me about something in public async placeOrder

[ "newOrderRespType", ResponseType[ responseType] ] - Type 'undefined' cannot be used as an index type.

I'm assuming it defaults to ACKNOWLEDGEMENT because undefined is falsey is 0 (yay js), however it might be good to be explicit about it.

Loving the library though.

Use server time

I ran into a situation where my local clock got ahead of the servers which lead to an error response on all my requests:
{"code":-1021,"msg":"Timestamp for this request was 1000ms ahead of the server's time."}

Wondering if there's a means to say "use server time" in the library by keeping a delta to local time...

Almost certain user stream stops working

I am almost certain that the user stream stops working
My code looks like this:

const userKey: string = await binance.openUserStream();
  await binance.monitorUser(
    userKey,
    (update: AccountUpdate | OrderUpdate) => {
      if (update instanceof AccountUpdate) {
        wallet.updateBalances(update);
      } else if (update instanceof OrderUpdate) {
        for (const trader of traders) {
          trader.orderUpdate(update as OrderUpdate);
        }
      }
    },
    streamHeartbeatTimeout,
    () => {
      console.log("Reconnecting to user stream");
      subscribeToUserStream(wallet);
    },
  );
  console.log("Opened user stream " + userKey);
  setInterval(() => {
    console.log(new Date() + " Sending PUT on user stream");
    binance.keepAliveUserStream(userKey);
  }, 15 * 60 * 1000);

So it should be sending the PUT every 15 minutes. However after some unknown amount of time, it stops getting any updates. There is no reconnection going on, so its not that.

Usage example

How is this supposed to be used?

I was able to make this work by doing this in my Express project (a REST API wrapping this library):

var binance = require('binance-api-client');
new binance.BinanceApiClient(binanceKey, binanceSecret);

But is this ok? I've read that calling new without assignment is an anti-pattern since this probably means that the function called has side effects (e.g. setting globals, more on this here).

Thanks for this incredible well-done library.

Cheers.-

Leverage

Is there any way to change the leverage of transactions?
On the binance documentation, there is a way to change the initial leverage, here but I didn't find it on this api

Order Update numbers are strings

I've run into this problem a couple of times: The float values that come back from binance JSON are strings not numbers. Despite typescript being there and despite it saying that they are numbers, they still can end up strings. As such I've had various scenario's where I've done something like update.price + 0.001 and ended up with 0.00580.001.

Suggest you wrap everything in parseFloat for the OrderUpdate.ts
Also last executed quantity is missing from the structure:
"l": "0.00000000", // Last executed quantity

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.