luzzif / binance-api-client Goto Github PK
View Code? Open in Web Editor NEWA wrapper which can be used to interact with Binance's API. Entirely developed in TypeScript.
A wrapper which can be used to interact with Binance's API. Entirely developed in TypeScript.
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();
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...
this._tickSize = json._tickSize;
should be
this._tickSize = json.tickSize;
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.
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.
Could you add a simple project to the solution? A kind of simple windows form with a call to a method.
Thanks
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"
);
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.
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
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.
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.
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.
I have one problem is TypeError: url_1.URL is not a constructor;
How to solve this problem?
Thanks
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).
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.
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...
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.
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.-
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
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.