Loading ...

JavaScript Bitmex

Author: gmgphil, Created: 2019-01-15 18:35:03, Updated:

I want to post an limit order just below the last price, but check before if there is already an pending Order at the same price.

So i came up with this, but this one doesnt send an Order as well when there is none yet.

var depth = exchange.GetDepth(); var pricex = depth.Asks[0].Price var ordersx = exchange.GetOrders var ordersprice = ordersx.Price

exchange.SetDirection(“buy”)

if (ordersprice === pricex-0.5,20) {} else {exchange.Buy(pricex-0.5,20)}

Thanks for your help.


More

gmgphil Can you please write a function, that bulk cancels all orders matching a specific price range and with an specific ordersize? Thank you

小小梦 OK , Let me code a demo for you . ``` var depth = exchange.GetDepth(); // get the order book info var pricex = depth.Asks[0].Price // get the order price of sell level 1 var orders = _C(exchange.GetOrders) // get your pending orders exchange.SetDirection("buy") // set trade direction for long // if (ordersprice === pricex-0.5,20) {} else {exchange.Buy(pricex-0.5,20)} // your code var hasNearPricePendingOrder = false // set a flag var upRange = 1 // set upRange for the old order price up float var downRange = 1 // set downRange for ... if (orders.length !== 0){ // you have some pending orders for(var i = 0 ; i < orders.length ; i++){ if(pricex < (orders[i].Price + upRange) && pricex > (orders[i].Price - downRange)){ // if now price in a range for a value (old order price - downRange) to another(old order price + upRange) hasNearPricePendingOrder = true // set the flag } } } if(!hasNearPricePendingOrder){ // is trade or not base on hasNearPricePendingOrder exchange.Buy(pricex - 0.5, 20) // send a limit order to exchange Bitmex } ```

发明者量化 https://www.fmz.com/bbs-topic/2710

gmgphil great, thank you very much! I was able to transform a marketmaker strategy based on your lines. I have no idea how to bulk them now to the exchange. Sorry, i have zero experience in JavaScript. Could you help me out again here?