Strategy vault / Tools & templates
Binance Websocket Subscription to Perpetual Contract Market Information
Python strategy by GCC.
PythonTools & templates
The original spec has no written description. Read the source below.
Source Python
import json
def main():
LogStatus("Connecting...")
# client = Dial("wss://stream.binance.com:9443/stream?streams=btcusdt@aggTrade/ethusdt@aggTrade|reconnect=true") #Multiple trading pairs
# client = Dial("wss://stream.binance.com:9443/ws/btcusdt@aggTrade|reconnect=true") #Single trading pair
# client = Dial("wss://dstream.binance.com/ws/btcusd_perp@aggTrade|reconnect=true") #Coin-based,ticker
client = Dial("wss://fstream.binance.com/ws/btcusdt@aggTrade|reconnect=true")
if not client:
Log("Connection failed, Program exited")
return
while True:
buf = client.read(-2)
Log('tt',buf)
if buf:
obj = json.loads(buf)
# Log(obj)
# Log('Trading pair',obj['data']['s'], 'price', obj['data']['p']) #Multiple trading pairs
Log(obj['p']) #Test
Sleep(5000)
client.close()Published by GCC on the FMZ strategy square · last modified 2021-11-24. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a tested, production-ready module from strategies/Binance-Websocket-Subscription-to-Perpetual-Contract-Market-Information.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- 2 3 Python Version Drawing Class Library Compatible 2 3Python · Tools & templates
- Local StoragePython · Tools & templates
- Python Version Dual Thrust OKCoin FuturesPython · Tools & templates
- TBD Python2 3Python · Tools & templates
- FMZ Real Offer Robot Automatically Detects and Restarts Program WeChat PushPython · Tools & templates
- OkEX Websocket Realtime v3Python · Tools & templates