gatews - Gate.io WebSocket SDK

gatews - Gate.io WebSocket SDK

gatews provides new Gate.io WebSocket V4 implementations. It is intended to work along with gateapi-* series to provide a quick way for developers to integrate Gate.io tradings.

This repository is meant to replace WebSocket-API. The latter will not accept any new feature requirements.

Supported languages are:

Refer to corresponding directory for usage.

Owner
gate.io
Gate.io is operated by Gate Technology Inc. We are dedicated to security and your experience, offering you a secure, simple and fair Bitcoin exchange.
gate.io
Comments
  • Position WS updates vs. positions from REST

    Position WS updates vs. positions from REST

    Hello there,

    Is there any reliable way to determine whether position notification from futures.positions WS channel represents state newer than information returned from REST API (/futures/{settle}/positions)? From what I saw the timestamp (in ms) is not enough - there can be multiple WS notifications sent with the same time_ms.

    Thanks, L.

  • subscribe all user data events in one ws connection

    subscribe all user data events in one ws connection

    Thanks for your hard work! But there are two critical problems that I found in your futures API:

    1. Some connections are contract specific which is inconvenient

    For example, for User Trades API, the connection is contract specific:

    from websocket import create_connection
    ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
    ws.send('{
        "time" : 123456,
        "channel" : "futures.usertrades",
        "event": "subscribe",
        "payload" : ["20011", "BTC_USD"],
        "auth": {
                "method": "api_key",
                "KEY":"xxxx",
                "SIGN": "xxxx"
                }}')
    print(ws.recv())
    

    which means that N connections are needed if we want to receive notifications from N contracts.

    2. If all user-specific data can be integrated with one connection, it will be much better

    As far as I know, Binance provides a single Websocket endpoint User Data Stream to receive all user updates, and that's really awesome.

  • Documentation is incorrect

    Documentation is incorrect

    Please update your docs! I had to come here looking for how to auth to the websocket.

    Info here is wrong: https://www.gateio.ch/docs/apiv4/ws/index.html#spot-websocket-v4

  • local_order_book.py out of sync

    local_order_book.py out of sync

    did you try to run local_order_book.py lately?

    i see zombie levels (overlapping ask and bid price) always after the very first update.

    is the orderbook of websocket v4 ready to be used in production?

    thank you for your time''

  • Your order size 1 is too small. The minimum is 1 USDT

    Your order size 1 is too small. The minimum is 1 USDT

    Hello guys,

    I'm trying send GOLD_USDT orders through de API V.4, but some errors have been happening.

    If I send a order with amount=2 and price=0.009321, I receive the error message: 'Your order size 2 is too small. The minimum is 1 USDT' The message don't make sense. Is 2 less than 1?

    The data/body is: { "text":"", "currency_pair":"GOLD_USDT", "type":"limit", "account":"spot", "side":"buy", "amount":"2", "price":"0.0093210", "time_in_force":"gtc" }

    But, if I send an order with amount=2 and price 1.009321, this works fine. (Price > 1). This was only to test, because the price 1.009321 is very expensive.

    So, I don't understand what's happening. Probably, the validation is inverted in the API.

    Could someone help me?

    Thanks.

  • Fee fields in user trades notification

    Fee fields in user trades notification

    Hi there,

    https://www.gate.io/docs/developers/futures/ws/en/#user-trades-notification says there are fee and point_fee fields in the notification. I don't see them in notifications I receive, are these fields somehow optional (if so when are they provided) or is the documentation wrong?

    Thanks, L.

  • Order book timestamps semantics

    Order book timestamps semantics

    Hello there,

    I have a question regarding order book notifications coming from WebSocket API (https://www.gate.io/docs/developers/futures/ws/en/#legacy-order-book-notification, https://www.gate.io/docs/developers/futures/ws/en/#order-book-update-notification). There's a timestamp provided in the notification - "t", comment says it's "Order book generation timestamp in milliseconds". Does this timestamp represent the time when the change occurred "in engine" or does it represent the time when the notification was dispatched from your end? I assume the former but wanted to double-check.

    Thanks!

  • How to get 'premium index' via API?

    How to get 'premium index' via API?

    Hello there,

    I checked the documentation and samples but could not find any info on how to obtain premium index values (https://www.gate.io/futures_info_new/futures/btc/BTC_USD#indexinfo, 'premium index'). Is there any way in API to retrieve this value over time/subscribe to updates/...?

    Thanks, L.

  •  WebSocket connection can not be established giving compression error

    WebSocket connection can not be established giving compression error

    The WebSocket connection can not be established and gives error:

    failed to connect to server for the 1 time, try again later: 
    Unsupported extension: name = permessage-deflate,
    params = [('server_no_context_takeover', None), ('client_no_context_takeover', None)]
    

    Most probably this is due to the new default compression extension since is not specifically specified. Possible solution is to add "compression=None" argument in client.py (line 189) to be like below:

    conn = await websockets.connect(self.cfg.host, ssl=ctx, compression=None)

  • Websockets being closed on infrequently traded instruments

    Websockets being closed on infrequently traded instruments

    I've noticed that on some instruments, the server side closes the websocket after a while.

    This is despite:

    1. having the "infrastructure" level ping/pong enabled
    2. explicitly doing the application level ping/pong every 30 seconds.

    This mostly happens on the websocket when subscribing to trades, and only on infrequently traded instruments

    Is this expected?

    Thank you.

  • json: cannot unmarshal number into Go struct field xxx of type string

    json: cannot unmarshal number into Go struct field xxx of type string

    This is a common error and happens in many cases, for example:

    m.wsService.SetCallBack(gatews.ChannelFutureBalance, func(msg *gatews.UpdateMsg) {
    	var accounts []gatews.FuturesAccountBook
    
    	if m.conf.Debug && msg.Event == "update" {
    		log.Printf("ChannelFutureBalance: %s\n", string(msg.Result))
    	}
    
    	if msg.Error != nil {
    		errorHandler(convertWsError(msg.Error, excommon.GlobalMarketTypeFutures, excommon.Unknown))
    		return
    	}
    
    	if msg.Event != "update" {
    		return
    	}
    
    	if err := json.Unmarshal(msg.Result, &accounts); err != nil {
    		errorHandler(convertWsError(err, excommon.GlobalMarketTypeFutures, excommon.Unknown)) // ①
    	}
            // ...
    

    ① will show the error: json: cannot unmarshal number into Go struct field FuturesAccountBook.balance of type string. This kind of bug also occurs in the case of GateWsFuturesTrade and GateWsFuturesOrder et al.

    It could be a solution to refactor the structs in customized code, but it will be much better if your guys can fix this problem inside this package.

  • SpotPublicTradeChannel  responses

    SpotPublicTradeChannel responses

    Hello there!

    In **response.result** the 'id' field's order not always in order as same in 'create_time_in_ms' too. When 'create_time_in_ms' field is equal with the next response time, 'id' fields shows the wrong order of responses.

    Maybe my fail, but cant handle this strange behavior Regards, Atirra

    {'status': 'success'} {'id': 4616057627, 'create_time': 1669181021, 'create_time_ms': '1669181021177.0', 'side': 'sell', 'currency_pair': 'BTC_USDT', 'amount': '0.0135', 'price': '16490'} {'id': 4616057628, 'create_time': 1669181021, 'create_time_ms': '1669181021180.0', 'side': 'sell', 'currency_pair': 'BTC_USDT', 'amount': '0.024', 'price': '16490'} {'id': 4616057635, 'create_time': 1669181021, 'create_time_ms': '1669181021197.0', 'side': 'sell', 'currency_pair': 'BTC_USDT', 'amount': '0.0001', 'price': '16489.5'} {'id': 4616057634, 'create_time': 1669181021, 'create_time_ms': '1669181021194.0', 'side': 'sell', 'currency_pair': 'BTC_USDT', 'amount': '0.002', 'price': '16490'} {'id': 4616057633, 'create_time': 1669181021, 'create_time_ms': '1669181021194.0', 'side': 'sell', 'currency_pair': 'BTC_USDT', 'amount': '0.002', 'price': '16490'} {'id': 4616057632, 'create_time': 1669181021, 'create_time_ms': '1669181021194.0', 'side': 'sell', 'currency_pair': 'BTC_USDT', 'amount': '0.002', 'price': '16490'} {'id': 4616057630, 'create_time': 1669181021, 'create_time_ms': '1669181021191.0', 'side': 'sell', 'currency_pair': 'BTC_USDT', 'amount': '0.0262', 'price': '16490'} {'id': 4616057631, 'create_time': 1669181021, 'create_time_ms': '1669181021194.0', 'side': 'sell', 'currency_pair': 'BTC_USDT', 'amount': '0.0046', 'price': '16490'} {'id': 4616057629, 'create_time': 1669181021, 'create_time_ms': '1669181021187.0', 'side': 'sell', 'currency_pair': 'BTC_USDT', 'amount': '0.0255', 'price': '16490'} {'id': 4616057638, 'create_time': 1669181021, 'create_time_ms': '1669181021210.0', 'side': 'sell', 'currency_pair': 'BTC_USDT', 'amount': '0.0001', 'price': '16487.5'}

  • `text` field in account book REST response

    `text` field in account book REST response

    Hello there!

    There's text field in /futures/{settle}/account_book response (https://www.gate.io/docs/developers/apiv4/en/#query-account-book) which is documented as comment. Per observation the semantics of the field value depends on type of the record, e.g. for pnl records the value is contract:orderId, and for funding payments the value is just contract. Can this behavior be relied upon? That is, is it guaranteed that when the record type is fund the value in text field is contract name?

    Thanks, L.

  • 'available balance' via WS?

    'available balance' via WS?

    Hello,

    is there a way to get/compute 'available balance' based on WS notifications?

    When REST API is used to obtain account balance (https://www.gate.io/docs/developers/apiv4/en/#query-futures-account) the information includes total and available amounts (and doesn't include any sort of 'valid as of' time). WS notification (https://www.gate.io/docs/developers/futures/ws/en/#positions-notification) only provides total amount and change amount. But the available amount likely does not follow the same change. Is there a way to compute/keep track of it?

    E.g. since total = position_margin + order_margin + available and position margin is part of position updates if I had the order_margin I could compute the available amount myself. But I don't know where to get order_margin from/how to keep track of it.

    Thanks, L.

  • Can you help with provide of code to make a limit order buy on Spot and limit/market buy order on Futures?

    Can you help with provide of code to make a limit order buy on Spot and limit/market buy order on Futures?

    Hello. I'm just getting started with this library and not very familiar of how to do things with it. I didn't find any example of code of how to place orders and make buys.

    Can you provide an example of buying BTC? From start of authentification, listening channels and make fast as possible bought. Both futures and spot markets?

  • Websocket connection stability

    Websocket connection stability

    Hello everyone.

    I have noticed many frequent random disconnects from the Gate.io websocket server. Everything is stable when connecting to the websocket servers of 3 other major exchanges (and the code can run for days) but the connection to Gate.io is unstable. It disconnects with no apparent reason, it does not seem to close the connection, it seems more like just sitting idle and not sending any updates. Ping / pong protocol is respected with the connection (even though their documentation is vague about it).

    Do you have any specific advice about how to handle Gate.io websocket connections? Maybe something that is not apparent in the docs or anything else?

    Thank you in advance.

Related tags
Encrypted-websocket-chat - Encrypted websocket chat using golang

Encrypted websocket chat First version written in python This version should be

Sep 15, 2022
Websocket-chat - A simple websocket chat application
Websocket-chat - A simple websocket chat application

WebSocket Chat App This is a simple chat app based on websockets. It allows user

Jan 25, 2022
🚀 BiliBili Live WebSocket Protocol SDK in Golang
🚀 BiliBili Live WebSocket Protocol SDK in Golang

BiliGO-LIVE BiliBili Live WebSocket Protocol SDK in Golang 简介 v0版本不保证对外函数、结构的不变性,请勿大规模用于生产环境 哔哩哔哩直播 WebSocket 协议的 Golang 封装 特性 良好的设计,自定义程度高 代码、结构体注释完善

Oct 30, 2022
A fast, well-tested and widely used WebSocket implementation for Go.

Gorilla WebSocket Gorilla WebSocket is a Go implementation of the WebSocket protocol. Documentation API Reference Chat example Command example Client

Jan 2, 2023
Turn any program that uses STDIN/STDOUT into a WebSocket server. Like inetd, but for WebSockets.

websocketd websocketd is a small command-line tool that will wrap an existing command-line interface program, and allow it to be accessed via a WebSoc

Dec 31, 2022
WebSocket Command Line Client written in Go

ws-cli WebSocket Command Line Client written in Go Installation go get github.com/kseo/ws-cli Usage $ ws-cli -url ws://echo.websocket.org connected (

Nov 12, 2021
proxy your traffic through CDN using websocket

go-cdn2proxy proxy your traffic through CDN using websocket what does it do example server client thanks what does it do you can use this as a library

Dec 7, 2022
Chat bots (& more) for Zoom by figuring out their websocket protocol
Chat bots (& more) for Zoom by figuring out their websocket protocol

zoomer - Bot library for Zoom meetings Good bot support is part of what makes Discord so nice to use. Unfortunately, the official Zoom API is basicall

Dec 14, 2022
Tiny WebSocket library for Go.

RFC6455 WebSocket implementation in Go.

Dec 28, 2022
Simple example for using Turbos Streams in Go with the Gorilla WebSocket toolkit.

Go Example for TurboStreams over WebSockets Simple example for using Turbos Streams in Go with the Gorilla WebSocket toolkit.

Dec 22, 2022
Minimal and idiomatic WebSocket library for Go

websocket websocket is a minimal and idiomatic WebSocket library for Go. Install go get nhooyr.io/websocket Highlights Minimal and idiomatic API First

Dec 31, 2022
:notes: Minimalist websocket framework for Go
:notes: Minimalist websocket framework for Go

melody ?? Minimalist websocket framework for Go. Melody is websocket framework based on github.com/gorilla/websocket that abstracts away the tedious p

Dec 23, 2022
A modern, fast and scalable websocket framework with elegant API written in Go
A modern, fast and scalable websocket framework with elegant API written in Go

About neffos Neffos is a cross-platform real-time framework with expressive, elegant API written in Go. Neffos takes the pain out of development by ea

Dec 29, 2022
Terminal on browser via websocket

Terminal on browser via websocket. Supportted OS Linux Mac

Dec 27, 2022
run shell scripts by websocket with go lauguage
run shell scripts by websocket with go lauguage

go_shell_socket run shell scripts by websocket with go lauguage Usage pull project get gin and websocket with go get config config.json file build it

Mar 9, 2022
simpleChatInGo - This is a simple chat that i made for fun asnd learn more about websocket
simpleChatInGo - This is a simple chat that i made for fun asnd learn more about websocket

simpleChatInGo This is a simple chat that i made for fun asnd learn more about websocket deploy For deploy this you only need to run the command : $ d

Sep 21, 2022
WebSocket for fasthttp

websocket WebSocket library for fasthttp and net/http. Checkout examples to inspire yourself. Install go get github.com/dgrr/websocket Why another Web

Dec 28, 2022
A tiny command line websocket client written in Go

wsc A simplistic tool for sending and receiving websocket messages from a command line. Mainly useful to test websocket servers. Getting started: $ go

Jan 12, 2022
An online multiplayer, websocket based, interpretation of the Tic Tac Toe minigame from "Machinarium" :D
An online multiplayer, websocket based, interpretation of the Tic Tac Toe minigame from

Tik Tak Toe An interpretation of the tic tac toe minigame from Amanita Design's Machinarium, multiplayer, online, as a website. Here's a screenshot of

Aug 31, 2022