Giter Site home page Giter Site logo

go-bitmex's People

Contributors

adampointer avatar adampointer-form3 avatar

Watchers

 avatar  avatar

go-bitmex's Issues

Replace event bus

Replace the current event bus library as it is having issues with message ordering guarantees. This makes creating an L2 orderbook model difficult.

Ability to make JSON-RPC requests over the WS connection

Looks like this library uses WebSockets for subscriptions etc. however all the other requests are made through the JSON-RPC via HTTP. Is this correct? If so, is there a reason beyond the functions to do so being unexported?

I am able to place orders using e.rpcRequest(req) if I patch the library and add:

func (e *Exchange) WriteReqWS(req *RPCRequest) (*RPCResponse, error) {
	return e.rpcRequest(req)
}

This seems to work. Results in lower order latency and also has the benefit of not using up your "request quota".

Am I missing something here? Why was this function not exported? Is there an easier way to actually send these messages over the already alive websocket connection?

My test involves:

func (dbit *DeribitSessionContext) createRPC(method string, args map[string]string) (*deribit.RPCRequest, error) {
	req := deribit.NewRPCRequest(method)
	if args != nil {
		for k, v := range args {
			if err := req.SetQueryParam(k, v); err != nil {
				return nil, err
			}
		}
	}
	return req, nil
}

func (dbit *DeribitSessionContext) LimitOrder(dir models.Direction, total uint64, price float64, postOnly bool, label *string) error {
	args := map[string]string{
		"instrument_name": DeribitBtcPerpInstrument,
		"type":            "limit",
		"price":           fmt.Sprintf("%.2f", price),
		"amount":          fmt.Sprintf("%d", total),
	}
	if postOnly {
		args["post_only"] = "true"
	}
	if label != nil {
		args["label"] = *label
	}

	req, err := dbit.createRPC(fmt.Sprintf("private/%s", dir), args)
	if err != nil {
		return err
	}
	resp, err := dbit.ctx.WriteReqWS(req)
	if err != nil {
		return err
	}
	if resp == nil {
		return ErrNilResponse
	}
	return nil
}

This actually has significantly lower latency than the standard way of using the client (which seems to use JSON-RPC over a new HTTP request).

Panic in func WebsocketClient.disconnectAndRetry

The library seems to panic on occasion in:

func (w *WebsocketClient) disconnectAndRetry() {
	w.log.Warn("disconnected")
	w.heartbeat.Stop()
	w.conMutex.Lock()
	w.connected = false
	w.conMutex.Unlock()
	w.log.Info("retrying websocket connection in 30s")
	time.Sleep(30 * time.Second)
	w.Restart()
}

at the line w.heartbeat.Stop(). Seems like w.heartbeat can be nil at times.

Patching so that it reads:

if w.heartbeat != nil {
  w.heartbeat.Stop()
}

fixes the panic however w.heartbeat being nil at that time likely points to some other race condition.

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.