How I Fixed My Slippage Issues: Upgrading to Real-Time Data

avatar
· Views 7,689


How I Fixed My Slippage Issues: Upgrading to Real-Time Data


Hey traders,

I've been getting a lot of DMs asking about my data setup. We all know the pain: you see a price on the chart, your bot fires an order, and you get filled 10 cents worse. Slippage is the silent killer of profitability.

The truth? It's likely your data feed. If you aren't using WebSockets, you are looking at old prices.

I recently switched my dev environment to AllTick.co. For those of us who need professional-grade data without paying Bloomberg prices, this is a game changer. It gives me real-time depth (Level 2 data), which is crucial for seeing where the big orders are hiding.

Why I like it:


  1. Speed: It's fast. No more waiting for HTTP responses.
  2. Coverage: US, Hong Kong, A-shares—all in one connection.
  3. Stability: It doesn't disconnect when the market goes crazy during CPI releases.

How to set it up: You need a Token (get it from their site) and a simple Python script. I've cleaned up the code I use so you guys can copy-paste it directly. It subscribes to AAPL and Tencent simultaneously.

Let me know if this helps your execution speeds!

import json
import websocket    # pip install websocket-client

'''
github:https://github.com/alltick/rea...
free token:https://alltick.co/register
official site:https://alltick.co
'''

class Feed(object):

    def __init__(self):
        self.url = 'wss://quote.tradeswitcher.com/quot...  # 这里输入websocket的url
        self.ws = None

    def on_open(self, ws):
        """
        Callback object which is called at opening websocket.
        1 argument:
        @ ws: the WebSocketApp object
        """
        print('A new WebSocketApp is opened!')

 
        sub_param = {
            "cmd_id": 22002, 
            "seq_id": 123,
            "trace":"3baaa938-f92c-4a74-a228-fd49d5e2f8bc-1678419657806",
            "data":{
                "symbol_list":[
                    {
                        "code": "700.HK",
                        "depth_level": 5,
                    },
                    {
                        "code": "UNH.US",
                        "depth_level": 5,
                    },
                    {
                        "code": "600416.SH",
                        "depth_level": 5,
                    }
                ]
            }
        }
        
        
        sub_str = json.dumps(sub_param)
        ws.send(sub_str)
        print("depth quote are subscribed!")

    def on_data(self, ws, string, type, continue_flag):
        """
        4 argument.
        The 1st argument is this class object.
        The 2nd argument is utf-8 string which we get from the server.
        The 3rd argument is data type. ABNF.OPCODE_TEXT or ABNF.OPCODE_BINARY will be came.
        The 4th argument is continue flag. If 0, the data continue
        """

    def on_message(self, ws, message):
        """
        Callback object which is called when received data.
        2 arguments:
        @ ws: the WebSocketApp object
        @ message: utf-8 data received from the server
        """
     
        result = eval(message)
        print(result)

    def on_error(self, ws, error):
        """
        Callback object which is called when got an error.
        2 arguments:
        @ ws: the WebSocketApp object
        @ error: exception object
        """
        print(error)

    def on_close(self, ws, close_status_code, close_msg):
        """
        Callback object which is called when the connection is closed.
        2 arguments:
        @ ws: the WebSocketApp object
        @ close_status_code
        @ close_msg
        """
        print('The connection is closed!')

    def start(self):
        self.ws = websocket.WebSocketApp(
            self.url,
            on_open=self.on_open,
            on_message=self.on_message,
            on_data=self.on_data,
            on_error=self.on_error,
            on_close=self.on_close,
        )
        self.ws.run_forever()


if __name__ == "__main__":
    feed = Feed()
    feed.start()


면책 조항: 본 게시글에 표현된 견해는 전적으로 작성자의 견해이며 Followme의 공식 입장을 대변하지 않습니다. Followme는 제공된 정보의 정확성, 완전성 또는 신뢰성에 대해 책임을 지지 않으며, 서면으로 명시적으로 언급되지 않는 한 해당 내용을 기반으로 취해진 어떠한 조치에 대해서도 책임을 지지 않습니다.

이 글이 마음에 드시나요? 작성자에게 팁을 보내 감사의 마음을 전하세요.
댓글 0

  • tradingContest