Administrator
yesterday be6ebe0f51aacef4435ee3d81a913bf8e8b48505
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
v4.0.0 · Stable
#Gate Futures WebSocket v4.0.0
Gate 提供简单而强大的 Websocket API,将 Gate BTCUSDT 永续合约交易状态集成到您的业务或应用程序中。
 
我们在 Python 和 Golang 中有语言绑定,将来还会有更多!您可以在右侧的深色区域中查看代码示例,并且可以通过右上角的选项卡切换示例的编程语言
 
#服务地址
我们提供 BTC/USDT 结算永续合约交易服务器地址,您可以根据自己的情况选择其中之一
 
#BTC Contract
地址列表:
 
线上交易: wss://fx-ws.gateio.ws/v4/ws/btc
模拟盘交易: wss://fx-ws-testnet.gateio.ws/v4/ws/btc
#USDT Contract
地址列表:
 
线上交易: wss://fx-ws.gateio.ws/v4/ws/usdt
线上SBE: wss://fx-ws.gateio.ws/v4/ws/usdt/sbe
模拟盘交易: wss://ws-testnet.gate.com/v4/ws/futures/usdt
建议使用SBE以获取更快的行情和更小的带宽成本
 
如果你使用老的服务地址(wss://fx-ws.gateio.ws/v4/ws 或 wss://fx-ws-testnet.gateio.ws/v4/ws), 将默认是 BTC 结算的 websocket 服务.
 
#变更日志
2026-04-14
 
部分频道支持SBE数据推送: futures.trades、futures.obu、futures.book_ticker、futures.tickers、futures.candlesticks、futures.order_book、futures.order_book_update、futures.usertrades、futures.positions、futures.orders。
具体的使用查看SBE 数据推送章节
2026-03-30
 
futures.order_place 下单请求:iceberg 字段说明修正为类型 string(原文档为 int64)、可选(原文档为必填)
2026-02-09
 
模拟盘部分频道支持SBE数据推送
正式环境实装另行同步
2026-02-04
 
futures.obu 模拟盘新增立即的首次快照推送,该次快照推送将会在订阅请求的响应之前推送。此行为与之前快照在订阅请求的响应之后推送不同,请注意该行为变更。
正式环境实装另行同步
2026-01-07
 
futures.orders 新增字段 market_order_slip_ratio (市价单的预设滑点比例)
futures.order_place futures.order_batch_place 入参新增字段market_order_slip_ratio (允许自定义市价单的最大滑点)
2025-12-09
 
合约的张数支持小数,所有的推送的张数、成交量等均改为字符串(可能是小数)。
 
如何对接websocket的小数支持:
 
在请求链接websocket时,加入:"X-Gate-Size-Decimal": "1" 的header即可,推送的张数、成交量等将会是字符串(可能是小数)。
如果在链接websocket时,不加入:"X-Gate-Size-Decimal": "1" 的header,推送将保持原始的字段类型(整形)。
请尽快切换到字符串的推送支持,后续整形的推送将会下线(下线时间会另行通知)。
如果出现小数的size,用户如果还是在使用整形的推送,那么推送出来的size将会是向下取整,例如1.1、1.5、1.7的size推送出去都将会是1。
将影响到以下的推送频道,和对应的字段。
 
频道    字段
futures.trades    size
futures.tickers    total_size
futures.book_ticker    A B
futures.order_book_update    a.s、b.s
futures.order_book    a.s、b.s
futures.obu    size 会有小数
futures.candlesticks    v
futures.liquidates    left、size、 order_size
futures.public_liquidates    size
futures.contract_stats    long_liq_size、short_liq_size、open_interest
futures.orders    iceberg、left、size
futures.usertrades    size
futures.auto_deleverages    position_size、trade_size
futures.positions    size
futures.autoorders    position_size、 trade_size
将影响到以下的API请求频道,主要涉及张数,成交量等字段。
 
频道    字段
futures.order_place    size、left
futures.order_batch_place    size
futures.order_cancel    size、left
futures.order_cancel_cp    size、left
futures.order_amend    size、left
futures.order_list    size、left
futures.order_status    size、left
2025-09-25
 
新增 仓位 Adl 排名频道 文档
2025-05-22
 
新增深度频道V2文档说明
futures.order_book_update 新增字段 full
2025-04-25
 
账户交易API新增通道 futures.order_cancel_ids
futures.order_book 和 futures.order_book_update 新增深度档位字段 l
2025-04-18
 
补充文档代码示例
2025-03-24
 
修复了深度频道部分文档的错误描述
修复了订单频道部分文档的错误描述
2025-03-21
 
更新了频道 futures.orders 文档, 新增了 update_id, update_time, biz_info, stop_profit_price 和 stop_loss_price 等字段的说明
2025-03-12
 
合约统计信息频道增加 contract 字段
更新账户交易 API,新增了 x-gate-exptime 字段
修复了账户交易 API 部分文档描述性错误
2025-02-19
 
新增频道 futures.public_liquidates 用于推送合约强平订单的快照信息
2025-02-10
 
更新账户交易 API,新增了 x_in_time, x_out_time, conn_trace_id, trace_id 字段
futures.order_place, futures.order_batch_place, futures.order_cancel, futures.order_cancel_cp 和 futures.order_amend 新增了 x_gate_ratelimit_requests_remain, x_gate_ratelimit_limit 和 x_gat_ratelimit_reset_timestamp 字段
2024-11-18
 
在频道 futures.order_book_update 移除 10 档位 1000ms 推送间隔支持
2023-09-21
 
在频道futures.trades推送参数中新增is_internal字段
2023-08-18
 
添加 WebSocket API 操作
WebSocket API 允许通过 WebSocket 连接创建、取消、修改、查询订单。
2023-07-07
 
在频道futures.order_book_update中添加新的间隔“20ms”,请注意,20ms 的间隔仅支持 20 档位
2023-06-20
 
在频道 futures.positions 增加update_id 字段
2022-12-22
 
在频道 futures.autoorders 初始结构中添加新字段 auto_size,将字段详细信息添加到 http api
2022-11-22
 
在通用的返回结果中添加新字段“time_ms”,以表示创建消息的时间
2022-08-11
 
在频道futures.autoorders通知中添加新字段text
在频道futures.tickers通知中添加新字段low_24h和high_24h
2022-04-15
 
在频道futures.balances通知中添加新字段 currency
2021-03-31
 
在频道futures.book_ticker和futures.order_book推送中添加毫秒字段t
2021-03-10
 
添加新的订单簿频道 futures.book_ticker 以实时推送最佳卖价/买价
添加新的订单簿频道 futures.order_book_update 以与用户推送订单簿更改 指定更新频率
添加本地订单簿维护文档
2021-03-01
 
在通用的返回结果中添加以_ms结尾的新毫秒精度时间戳
在futures.book all通知中添加新字段id
2020-8-08
 
添加完整代码 demo(golang, python)
2020-8-07
 
添加futures.autoorders频道
2020-7-07
 
添加futures.order_book频道
2020-4-30
 
添加futures.position频道
2019-11-06
 
新增 USDT 结算永续合约的 websocket 推送
为futures.tickers添加volume_24h_base字段、volume_24h_settle字段、volume_24h_quote字段
删除旧服务器地址(wss://fx-ws.gateio.ws/v4/ws 或 wss://fx-ws-testnet.gateio.ws/v4/ws)
如果您使用旧的服务器地址(wss://fx-ws.gateio.ws/v4/ws 或 wss://fx-ws-testnet.gateio.ws/v4/ws),我们 将为您使用 BTC 结算永续合约的 websocket 推送
 
2019-10-22
 
添加应用层 ping/pong 消息
2019-04-30
 
添加index和mark futures.candlesticks 订阅
为futures.tickers添加funding_rate_indicative字段
为futures.orders添加 is_reduce_only 和状态字段
2019-02-13
 
更改 webSocket 基本 url
为futures.tickers添加volume_24h_usd字段和volume_24h_btc字段
2019-01-11
 
添加futures.position_closes 和 futures.balance 订阅
删除频道 futures.auto_deleverages 和futures.liquidates的 finish_time 字段
为频道 futures.auto_deleverages 和futures.liquidates 添加 time字段
WebSocket 应用示例
 
# !/usr/bin/env python
# coding: utf-8
 
import hashlib
import hmac
import json
import logging
import time
import threading
 
from websocket import WebSocketApp
 
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
 
event = threading.Event()
 
class GateWebSocketApp(WebSocketApp):
 
  def __init__(self, url, api_key, api_secret, **kwargs):
    super(GateWebSocketApp, self).__init__(url, **kwargs)
    self._api_key = api_key
    self._api_secret = api_secret
 
  def _send_ping(self):
    while not event.wait(10):
      self.last_ping_tm = time.time()
      if self.sock:
        try:
          self.sock.ping()
        except Exception as ex:
          logger.warning("send_ping routine terminated: {}".format(ex))
          break
        try:
          self._request("futures.ping", auth_required=False)
        except Exception as e:
          raise e
 
  def _request(self, channel, event=None, payload=None, auth_required=True):
    current_time = int(time.time())
    data = {
      "time": current_time,
      "channel": channel,
      "event": event,
      "payload": payload,
    }
    if auth_required:
      message = 'channel=%s&event=%s&time=%d' % (channel, event, current_time)
      data['auth'] = {
        "method": "api_key",
        "KEY": self._api_key,
        "SIGN": self.get_sign(message),
      }
    data = json.dumps(data)
    logger.info('request: %s', data)
    self.send(data)
 
  def get_sign(self, message):
    h = hmac.new(self._api_secret.encode("utf8"), message.encode("utf8"), hashlib.sha512)
    return h.hexdigest()
 
  def subscribe(self, channel, payload=None, auth_required=True):
    self._request(channel, "subscribe", payload, auth_required)
 
  def unsubscribe(self, channel, payload=None, auth_required=True):
    self._request(channel, "unsubscribe", payload, auth_required)
 
 
def on_message(ws, message):
  # type: (GateWebSocketApp, str) -> None
  # handle message received
  logger.info("message received from server: {}".format(message))
 
 
def on_open(ws):
  # type: (GateWebSocketApp) -> None
  # subscribe to channels interested
  logger.info('websocket connected')
  ws.subscribe("futures.tickers", ['BTC_USDT'], False)
 
# custom header
custom_headers = {
    "X-Gate-Size-Decimal": "1"
}
 
if __name__ == "__main__":
  logging.basicConfig(format="%(asctime)s - %(message)s", level=logging.DEBUG)
  app = GateWebSocketApp("wss://fx-ws.gateio.ws/v4/ws/usdt",
                         "YOUR_API_KEY",
                         "YOUR_API_SECRET",
                         on_open=on_open,
                         on_message=on_message,
                         header=custom_headers)
  app.run_forever(ping_interval=5)
Copy
#Websocket API 概述
#事件
每个通用 订阅频道/channel(例如ticker、order_book等)都支持一些不同的事件消息,它们是:
 
subscribe (推荐使用)
 
订阅,接受服务器的新数据通知。
 
unsubscribe
 
如果取消订阅,服务器将不会发送新数据通知。
 
update
 
服务器将向客户端发送新的订阅数据(增量数据)。
 
all
 
如果有新订阅的数据(所有数据)可用,服务器将向客户端发送通知。
 
#请求
每个请求都遵循通用格式,其中包含time、channel、event和payload。
 
请求
名称    类型    必选    描述
id    Integer    否    可选的请求 ID,将由服务器发回,以帮助您识别服务器响应哪个请求
time    Integer    是    请求时间
channel    String    是    请求 subscribe/unsubscribe 频道
auth    String    否    请求身份验证信息,请参阅身份验证部分了解详细信息
event    String    是    请求event (subscribe/unsubscribe/update/all/api)
payload    Array    是    请求详细参数
#响应
与请求类似,响应遵循以下通用格式,其中包含: time, channel, event , error 和 result.
 
响应
名称    类型    必选    描述
time    Integer    是    响应时间
time_ms    Integer    是    毫秒响应时间
channel    String    是    响应频道
event    String    是    响应频道事件 (update/all)
error    Object    是    响应错误
result    Any    是    返回来自服务端的新数据通知 或 对客户端请求的响应。如果有错误返回则error 不为空,没有错误则此字段为空。
注意:如果它是服务端发起的数据更新通知 那么 result 的类型是基于 channel 的,不同 channel 的 result 类型有所不同。
 
但如果是对客户端订阅请求的响应,那么 result 为固定的 {"status": "success"}。 验证订阅请求是否成功,您只需要检查 error 字段是否为空即可,不需要再解析 result 字段。
 
为了简单起见,下面的频道(channel)描述只给出对应频道的 payload 格式。
 
#错误
如果出现错误,您会收到error字段,其中包含错误代码和错误的类型。
 
错误
Code    Message
1    invalid argument struct
2    invalid argument
3    service error
4    authentication fail
#鉴权
如果频道是私有的,则请求体需要携带认证信息, 例如futures.usertrades
 
WebSocket 认证使用与 HTTP API 相同的签名计算方法,但具有 以下差异:
 
签名字符串拼接方式:channel=<channel>&event=<event>&time=<time>, 其中<channel>、<event>、<time>是对应的请求信息
身份验证信息在请求正文中的auth字段中发送。
您可以登录账户获取永续合约账户的 api_key 和 secret。
 
名称    类型    描述
method    String    验证方式:api_key
KEY    String    apiKey 的值
SIGN    String    签名结果
代码示例
 
# example WebSocket signature calculation implementation in Python
import hmac, hashlib, json, time
 
 
def gen_sign(channel, event, timestamp):
    # GateAPIv4 key pair
    api_key = 'YOUR_API_KEY'
    api_secret = 'YOUR_API_SECRET'
 
    s = 'channel=%s&event=%s&time=%d' % (channel, event, timestamp)
    sign = hmac.new(api_secret.encode('utf-8'), s.encode('utf-8'), hashlib.sha512).hexdigest()
    return {'method': 'api_key', 'KEY': api_key, 'SIGN': sign}
 
 
request = {
    'id': int(time.time() * 1e6),
    'time': int(time.time()),
    'channel': 'futures.orders',
    'event': 'subscribe',
    'payload': ["20011", "BTC_USD"]
}
request['auth'] = gen_sign(request['channel'], request['event'], request['time'])
print(json.dumps(request))
Copy
#SBE 数据推送
#对接SBE
使用地址,在现有的地址后添加/sbe:
prod: wss://fx-ws.gateio.ws/v4/ws/usdt/sbe
testnet: wss://ws-testnet.gate.com/v4/ws/futures/usdt/sbe
schema地址:
prod: gate_fex_ws_prod_latest.xml(opens new window)
testnet: gate_fex_ws_testnet_latest.xml(opens new window)
如果需要指定sbe_schema_id,则通过query的形式传入sbe_schema_id的参数,例如:wss://fx-ws.gateio.ws/v4/ws/usdt/sbe?sbe_schema_id=1
目前支持的sbe_schema_id为0和1;sbe_schema_id为0用于客户端测试sbe schema不兼容升级的逻辑
不传入sbe_schema_id则默认使用最新的schema版本
传入不合法的sbe_schema_id在连接之后会返回系统通知,并将sbe_schema_id调整为最新的schema版本
传入旧版本的sbe_schema_id在连接之后会返回系统通知,提醒更新新版本的SBE schema,依旧使用客户端指定的旧版本schema
无效的sbe_schema_id的系统通知
 
{
  "time": 1770600979,
  "time_ms": 1770600979609,
  "channel": "futures.system",
  "event": "update",
  "result": {
    "type": "invalid_sbe_schema_id",
    "msg": "Your sbe_schema_id '011' does not exist, it has been adjusted to the default sbe_schema_id '1'."
  }
}
Copy
过时的sbe_schema_id的系统通知
 
{
  "time": 1770601096,
  "time_ms": 1770601096665,
  "channel": "futures.system",
  "event": "update",
  "result": {
    "type": "outdated_sbe_schema_id",
    "msg": "Your sbe_schema_id '0' is outdated, please upgrade to the latest version '1'."
  }
}
Copy
#SBE使用说明
使用JSON进行请求和首次响应;使用SBE作为数据推送;
同一条连接上同时存在JSON和SBE的消息,请使用opcode来区分数据:opcode为1代表JSON,opcode为2代表SBE。
SBE 的解码:
MessageHeader:每条 SBE 二进制帧均为「MessageHeader + 消息体」。Header 中包含 blockLength、templateId、schemaId、version,解码时必须先读 Header,再根据 schemaId 和 templateId 选择对应 Schema 与消息类型解码消息体。
解码流程建议:
读取 MessageHeader(固定长度),得到 schemaId、templateId、blockLength、version。
根据 schemaId 选择解码器:0 → 使用旧版本进行解码;1 → 使用新版本进行解码。
根据 templateId 确定具体消息类型(如 PublicTrade、OrderBook、Bbo 等),再按该 Schema 的布局解码消息体。
使用 SBE 时,仅可订阅以下频道,其余频道不支持 SBE 推送。后续将扩展到其余频道。
订阅不支持SBE的频道时,将返回订阅失败的消息
通道名    说明
futures.trades    公共成交
futures.order_book    订单簿(深度)
futures.order_book_update    订单簿增量更新
futures.book_ticker    最优买卖(BBO)
futures.obu    订单簿增量(OBU)
futures.candlesticks    K 线
futures.tickers    行情
futures.usertrades    用户成交
futures.positions    持仓
futures.orders    订单
不支持sbe将返回订阅失败:
 
{
  "time": 1770603321,
  "time_ms": 1770603321767,
  "conn_id": "57a8765578ea837e",
  "trace_id": "3c75ba05569b3b292a2f36cfdd90d868",
  "channel": "futures.autoorders",
  "event": "subscribe",
  "payload": [
    "15760812",
    "!all"
  ],
  "error": {
    "code": 2,
    "message": "channel futures.autoorders does not support SBE"
  },
  "result": {
    "status": "fail"
  }
}
Copy
#System API
提供系统状态检查,如 ping/pong.
 
#Ping/Pong
检查服务器/客户端连接.
 
Gate websocket 使用协议层 ping/pong 消息。服务器会发起 ping 操作。如果客户端没有回复,客户端将被断开。
 
websocket rfc 协议(opens new window)
 
如果想主动检测连接状态,可以发送应用层 ping 消息,并接收 pong 消息。
 
#请求参数
频道
 
futures.ping
 
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
ws.send('{"time" : 123456, "channel" : "futures.ping"}')
print(ws.recv())
Copy
futures.ping操作返回 JSON 结构如下:
 
{
  "time": 1545404023,
  "time_ms": 1545404023123,
  "channel": "futures.pong",
  "event": "",
  "result": null
}
Copy
#服务升级通知
服务在即将关闭进行升级时,会向当前连接主动推送一条系统通知,客户端收到后应尽快重连。
 
服务端推送格式(SystemNotifyDTO):
 
字段    类型    说明
type    String    通知类型,如 upgrade
msg    String    提示文案
data    Object    可选,扩展数据
示例(服务升级):
 
{
  "type": "upgrade",
  "msg": "The connection will soon be closed for a service upgrade. Please reconnect."
}
#ticker 频道
ticker是合约状态的高级概述。它向你展示了最高的, 最低的、最后的交易价格。它还包括每日交易量和价格等信息
 
#订阅操作
订阅永续合约 24hr 价格变动情况.
 
#请求参数
channel
 
futures.tickers
 
event
 
subscribe
 
params
 
请求参数
名称    类型    必选    描述
payload    Array    是    合约列表
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
ws.send('{"time" : 123456, "channel" : "futures.tickers","event": "subscribe", "payload" : ["BTC_USD"]}')
print(ws.recv())
Copy
上面的订阅请求返回 JSON 结构如下:
 
{
  "time": 1545404023,
  "time_ms": 1545404023123,
  "channel": "futures.tickers",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#ticker 推送
永续合约 24hr 价格变动情况推送
 
#推送参数
channel
 
futures.tickers
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    Array    Array of objects
推送参数
名称    类型    描述
contract    String    合约名称
last    String    最新成交价
change_percentage    String    涨跌幅
funding_rate    String    资金费率
funding_rate_indicative    String    下一周期预测资金费率(已弃用,改用funding_rate)
mark_price    String    标记价格
index_price    String    指数价格
total_size    String    总数量
volume_24h    String    24 小时成交量
quanto_base_rate    String    双币种合约中基础货币与结算货币的汇率。不存在于其他类型的合同中
volume_24h_btc    String    近 24 小时 BTC 交易量(已弃用,请使用volume_24h_base、volume_24h_quote、volume_24h_settle代替)
volume_24h_usd    String    近 24 小时美元交易量(已弃用,请使用volume_24h_base、volume_24h_quote、volume_24h_settle 代替)
volume_24h_quote    String    近 24 小时交易量,以计价货币计
volume_24h_settle    String    近 24 小时交易量,以结算货币计
volume_24h_base    String    近 24 小时交易量,以基础货币计
low_24h    String    近 24 小时最低交易价
high_24h    String    近 24 小时最高交易价
{
  "time": 1541659086,
  "time_ms": 1541659086123,
  "channel": "futures.tickers",
  "event": "update",
  "result": [
    {
      "contract": "BTC_USD",
      "last": "118.4",
      "change_percentage": "0.77",
      "funding_rate": "-0.000114",
      "funding_rate_indicative": "0.01875",
      "mark_price": "118.35",
      "index_price": "118.36",
      "total_size": "73648",
      "volume_24h": "745487577",
      "volume_24h_btc": "117",
      "volume_24h_usd": "419950",
      "quanto_base_rate": "",
      "volume_24h_quote": "1665006",
      "volume_24h_settle": "178",
      "volume_24h_base": "5526",
      "low_24h": "99.2",
      "high_24h": "132.5"
    }
  ]
}
Copy
#取消订阅
取消订阅
 
#请求参数
channel
 
futures.tickers
 
event
 
unsubscribe
 
代码示例
 
import json
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
  "time": 123456,
  "channel": "futures.tickers",
  "event": "unsubscribe",
  "payload": ["BTC_USD"]
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545404900,
  "time_ms": 1545404900123,
  "channel": "futures.tickers",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#公有成交频道
每当 Gate 发生交易时,该频道都会发送交易消息。它包括价格、金额、时间和类型等交易信息
 
#公有成交订阅
订阅公有成交更新通知
 
#请求参数
channel
 
futures.trades
 
event
 
subscribe
 
params
 
请求参数
名称    类型    必选    描述
payload    Array    是    合约列表
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
ws.send('{"time" : 123456, "channel" : "futures.trades","event": "subscribe", "payload" : ["BTC_USD"]}')
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545405058,
  "time_ms": 1545405058123,
  "channel": "futures.trades",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#公有成交推送
通知最新交易更新
 
#推送参数
channel
 
futures.trades
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    Array    Array of objects
推送参数
名称    类型    描述
contract    string    合约名称
size    string/int    交易数量
id    int    交易 ID
create_time    int    交易消息创建时间
create_time_ms    int    交易消息创建时间(以毫秒为单位)
price    string    交易价格
is_internal    bool    是否为内部成交。内部成交是指保险资金和 ADL 用户对强平指令的接管。由于不是市场深度上的正常撮合,交易价格可能会出现偏差,不会记录在 K 线上。如果不是内部交易,则该字段不会被返回。
size 正数表示买家,负数表示卖家
 
{
  "channel": "futures.trades",
  "event": "update",
  "time": 1541503698,
  "time_ms": 1541503698123,
  "result": [
    {
      "size": "-108",
      "id": 27753479,
      "create_time": 1545136464,
      "create_time_ms": 1545136464123,
      "price": "96.4",
      "contract": "BTC_USD",
      "is_internal": true
    }
  ]
}
Copy
#取消订阅
取消订阅公有成交更新通知
 
#请求参数
channel
 
futures.trades
 
event
 
unsubscribe
 
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
ws.send(
  '{"time" : 123456, "channel" : "futures.trades", "event": "subscribe", "payload" : ["BTC_USD"]}')
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545404900,
  "time_ms": 1545404900123,
  "channel": "futures.trades",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#深度频道
order_book 频道允许您跟踪 Gate 订单簿深度的状态。它以价格聚合的方式提供,可自定义精度。
 
共有三种不同的订单簿渠道可供订阅:
 
futures.order_book
 
全量频道,定期使用all推送完整的有限级别订单簿.
 
futures.book_ticker
 
实时推送最佳买价和卖价.
 
futures.order_book_update
 
以指定的更新频率向用户订单簿推送订单簿的更新内容.
 
不建议通过futures.order_book接收订单簿更新,使用 futures.order_book_update 可以以更少的流量提供更及时的更新
 
如何维护本地订单簿:
 
订阅 futures.order_book_update 并指定级别和更新频率,例如 ["BTC_USDT", "100ms", "100"] 每 100ms 推送 BTC_USDT 订单簿前 100 个级别的更新
缓存 WebSocket 通知。每个通知都使用“U”和“u”来告诉第一个和最后一个 自上次通知以来更新 ID。
使用 REST API 检索基本订单簿,并确保记录了订单簿 ID(参考 如下面的“baseID”) 例如https://api.gateio.ws/api/v4/futures/usdt/order_book?contract=BTC_USDT&limit=10&with_id=true 获取 BTC_USDT 的 10 级基础订单簿
迭代缓存的 WebSocket 通知,找到第一个包含 baseID 的通知, 即 U <= baseId+1 和 u >= baseId+1,然后开始从中消费。请注意,size为 通知都是全量的 size,即应该使用它们覆盖替换原始的size。 如果 size 等于 0,则从订单簿中删除价格。
转储所有满足 u < baseID+1 的通知。如果 baseID+1 < 第一个通知 U,则 意味着当前的基本订单簿落后于通知。从步骤 3 开始检索更新的内容基本订单簿。
如果后续发现满足 U > baseID+1 的通知,则说明有更新 丢失的。从步骤 3 重建本地订单簿。
注意:
 
即使 WebSocket 推送中的 a, b 或者 asks, bids 为空,用户也需要更新本地订单簿的 id 和 timestamp,以确保本地订单簿与服务器保持一致。
WebSocket 订阅的 level(档位数)应与 REST 快照的 limit 一致,否则可能导致增量更新无法覆盖快照档位,造成本地订单簿错位或不完整。
#深度全量更新频道
订阅深度.
 
#请求参数
channel
 
futures.order_book
 
event
 
subscribe
 
params
 
请求参数
名称    类型    必选    描述
contract    String    是    合约名称
limit    String    是    深度层级: 100, 50, 20, 10, 5, 1
interval    String    是    价格合并精度: "0"
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
ws.send('{"time" : 123456, "channel" : "futures.order_book","event": "subscribe", "payload" : ["BTC_USD", "20", "0"]}')
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545405058,
  "time_ms": 1545405058123,
  "channel": "futures.order_book",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#全量深度推送
全量深度更新推送
 
#推送参数
channel
 
futures.order_book
 
event
 
all
 
params
 
推送参数
名称    类型    描述
result    object    深度信息
»t    Integer    深度生成时间戳(以毫秒为单位)
»contract    String    合约名称
»id    Integer    深度 ID
»asks    Array    深度卖方的档位列表
»»p    String    档位价格
»»s    String    档位的数量
»bids    Array    深度买方的档位列表
»»p    String    档位价格
»»s    String    档位的数量
»l    String    深度层级(例如 100 即代表 100 层的深度更新)
{
  "channel": "futures.order_book",
  "event": "all",
  "time": 1541500161,
  "time_ms": 1541500161123,
  "result": {
    "t": 1541500161123,
    "contract": "BTC_USD",
    "id": 93973511,
    "asks": [
      {
        "p": "97.1",
        "s": "2245"
      },
      {
        "p": "97.1",
        "s": "2245"
      }
    ],
    "bids": [
      {
        "p": "97.1",
        "s": "2245"
      },
      {
        "p": "97.1",
        "s": "2245"
      }
    ],
    "l": "20"
  }
}
Copy
#全量深度取消订阅
取消订阅指定市场的深度
 
#请求参数
channel
 
futures.order_book
 
event
 
unsubscribe
 
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
ws.send('{"time" : 123456, "channel" : "futures.order_book","event": "unsubscribe", "payload" : ["BTC_USD", "20", "0"]}')
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545445847,
  "time_ms": 1545445847123,
  "channel": "futures.order_book",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#最佳买卖价订阅
订阅深度最佳买卖价
 
#请求参数
channel
 
futures.book_ticker
 
event
 
subscribe
 
params
 
payload是一个包含合约市场的列表.
 
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws.gateio.ws/v4/ws/usdt")
ws.send('{"time" : 123456, "channel" : "futures.book_ticker","event": "subscribe", "payload" : ["BTC_USDT"]}')
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545405058,
  "time_ms": 1545405058123,
  "channel": "futures.book_ticker",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#最佳买卖价的推送
如果 a 为空字符串,则表示空买价;如果 b 为空字符串,则表示空卖价。
 
最新买卖价的推送
 
#推送参数
channel
 
futures.book_ticker
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    object    深度的最佳买卖价
»t    Integer    最佳买卖价行情生成的时间戳(以毫秒为单位)
»u    Integer    深度的 ID
»s    String    合约名称
»b    String    最佳买方的价格,如果没有买方,则为空串
»B    String/Integer    最佳买方的数量,如果没有买方,则为 0
»a    String    最佳卖方的价格,如果没有卖方,则为空串
»A    String/Integer    最佳卖方的数量,如果没有卖方,则为 0
{
  "time": 1615366379,
  "time_ms": 1615366379123,
  "channel": "futures.book_ticker",
  "event": "update",
  "result": {
    "t": 1615366379123,
    "u": 2517661076,
    "s": "BTC_USD",
    "b": "54696.6",
    "B": "37000",
    "a": "54696.7",
    "A": "47061"
  }
}
Copy
#最佳买卖价的取消订阅
取消指定合约市场的最佳买卖订阅
 
#请求
channel
 
futures.book_ticker
 
event
 
unsubscribe
 
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws.gateio.ws/v4/ws/usdt")
ws.send('{"time" : 123456, "channel" : "futures.book_ticker","event": "unsubscribe", "payload" : ["BTC_USDT"]}')
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545445847,
  "time_ms": 1545445847123,
  "channel": "futures.book_ticker",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#合约深度更新推送订阅
订阅深度更新推送
 
#请求参数
channel
 
futures.order_book_update
 
event
 
subscribe
 
params
 
请求参数
名称    类型    必选    描述
contract    String    是    合约名称
frequency    String    是    更新频率,20ms or 100ms
level    String    否    可选的深度层级。允许以下层级:100、50、20;20ms频率 只支持 20层
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws.gateio.ws/v4/ws/usdt")
ws.send('{"time" : 123456, "channel" : "futures.order_book_update","event": "subscribe", "payload" : ["BTC_USDT", "100ms", "100"]}')
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545405058,
  "time_ms": 1545405058123,
  "channel": "futures.order_book_update",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#深度更新推送
深度更新推送
 
#推送参数
channel
 
futures.order_book_update
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    Object    自上次更新以来发生变更要价和出价
»t    Integer    订单簿生成时间戳(以毫秒为单位)
»full    Boolean    true 代表全量的深度(假设订阅 level 为 100,推送出来则是 100 层的深度);用户接收到之后需要替换本地深度;false 代表增量的深度,为 false 时,不传输该字段
»s    String    合约名称
»U    Integer    本次更新开始的订单簿更新 ID
»u    Integer    本次更新结束的订单簿更新 ID
»b    Array    买方变动列表
»»p    String    变更的档位价格
»»s    String/Integer    档位的待成交数量。如果为 0,则从订单簿中删除该价格
»a    Array    卖方变动列表
»»p    String    变更的档位价格
»»s    String/Integer    档位的待成交数量。如果为 0,则从订单簿中删除该价格
»l    String    深度层级(例如 100 即代表 100 层的深度更新)
{
  "time": 1615366381,
  "time_ms": 1615366381123,
  "channel": "futures.order_book_update",
  "event": "update",
  "result": {
    "t": 1615366381417,
    "s": "BTC_USD",
    "U": 2517661101,
    "u": 2517661113,
    "b": [
      {
        "p": "54672.1",
        "s": "0"
      },
      {
        "p": "54664.5",
        "s": "58794"
      }
    ],
    "a": [
      {
        "p": "54743.6",
        "s": "0"
      },
      {
        "p": "54742",
        "s": "95"
      }
    ],
    "l": "100"
  }
}
Copy
#深度更新取消订阅
取消指定合约的市场的深度更新订阅
 
#请求参数
channel
 
futures.order_book_update
 
event
 
unsubscribe
 
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws.gateio.ws/v4/ws/usdt")
ws.send(
  '{"time" : 123456, "channel" : "futures.order_book_update", "event": "unsubscribe", "payload" : ["BTC_USDT", "100ms"]}')
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545445847,
  "time_ms": 1545445847123,
  "channel": "futures.order_book_update",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#深度频道V2
提供一种更快更新的获取深度信息的方法.
 
#维护本地深度
说明:
 
全量深度推送(full=true): 当频道推送的深度为全量深度时,需要将该深度数据完整替换本地深度,并将深度ID更新为消息中的字段 u。服务端可能会重复推送全量深度。
订阅该频道时,首次推送为全量深度。
增量深度推送(full=false): 增量消息中不会显示 full 字段,此时消息包含字段 U(深度起始ID)和 u(深度结束ID)。
如果 U = 本地深度ID + 1,则表示深度连续更新:
将本地深度ID替换为消息中的 u。
若更新中的 a 和 b 不为空,分别按价格更新对应的买、卖深度数量(level[0] 为价格,level[1] 为数量)。当数量 level[1]= "0" 时,需移除对应档位。
若 U ≠ 本地深度ID + 1,则深度数据不连续,需要取消订阅该市场,并重新订阅以获取初始化深度。
订阅限制: 针对同一合约的同一深度流,一个链接只允许订阅一次,重复订阅会返回错误。失败示例:
{
  "time": 1747391482,
  "time_ms": 1747391482960,
  "id": 1,
  "conn_id": "d9db9373dc5e081e",
  "trace_id": "ee001938590e183db957bd5ba71651c0",
  "channel": "futures.obu",
  "event": "subscribe",
  "payload": [
    "ob.BTC_USDT.400"
  ],
  "error": {
    "code": 2,
    "message": "Alert sub ob.BTC_USDT.400"
  },
  "result": {
    "status": "fail"
  }
}
Copy
#深度频道V2订阅
#请求参数
channel
 
futures.obu
 
event
 
subscribe
 
params
 
payload是一个包含流名称的列表. 格式为: ob.{symbol}.{level}; 例如 ob.BTC_USDT.400、ob.BTC_USDT.50
 
其中level枚举为:400、50;更新频率: 400档为100ms;50档为20ms;
 
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/usdt")
ws.send('{"time" : 123456, "channel" : "futures.obu",
        "event": "subscribe", "payload" : ["ob.BTC_USDT.400"]}')
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1747391482,
  "time_ms": 1747391482384,
  "id": 1,
  "conn_id": "d9db9373dc5e081e",
  "trace_id": "ee001938590e183db957bd5ba71651c0",
  "channel": "futures.obu",
  "event": "subscribe",
  "payload": [
    "ob.BTC_USDT.400"
  ],
  "result": {
    "status": "success"
  }
}
Copy
#深度v2订阅推送
深度频道V2的消息推送
 
#推送参数
channel
 
futures.obu
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    Object    自上次更新以来发生变更要价和出价
»t    Integer    订单簿生成时间戳(以毫秒为单位)
»full    Boolean    true 代表全量的深度;false 代表增量的深度,为 false 时,不传输该字段
»s    String    深度流的名称
»U    Integer    本次更新开始的订单簿更新 ID
»u    Integer    本次更新结束的订单簿更新 ID
»b    Array[OrderBookArray]    自上次更新以来的 bids 更新
»» OrderBookArray    Array[String]    [Price, Amount] 数组对, Amount=0应当从本地深度中移除
»a    Array[OrderBookArray]    自上次更新以来的 asks 更新
»» OrderBookArray    Array[String]    [Price, Amount] 数组对, Amount=0应当从本地深度中移除
全量推送示例:
 
{
    "channel": "futures.obu",
    "result": {
        "t": 1743673026995,
        "full": true,
        "s": "ob.BTC_USDT.400",
        "u": 79072179673,
        "b": [
            ["83705.9", "30166"]
        ],
        "a": [
            ["83706", "4208"]
        ]
    },
    "time_ms": 1743673026999
}
Copy
增量推送示例:
 
{
    "channel": "futures.obu",
    "result": {
        "t": 1743673027017,
        "s": "ob.BTC_USDT.400",
        "U": 79072179674,
        "u": 79072179694,
        "b": [
            ["83702.2", "62"],
            ["83702.1", "0"],
            ["83702", "0"],
            ["83685.6", "120"],
            ["83685", "239"]
        ]
    },
    "time_ms": 1743673027020
}
Copy
#深度频道V2取消订阅
取消指定合约的市场的深度频道V2订阅
 
#请求参数
channel
 
futures.obu
 
event
 
unsubscribe
 
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
ws.send(
  '{"time" : 123456, "channel" : "futures.obu", "event": "unsubscribe", "payload" : ["ob.BTC_USDT.400"]}')
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1743673617,
  "time_ms": 1743673617242,
  "id": 1,
  "conn_id": "7b06ff199a98ab0e",
  "trace_id": "8f86e4021a84440e502f73fde5b94918",
  "channel": "futures.obu",
  "event": "unsubscribe",
  "payload": ["ob.BTC_USDT.400"],
  "result": {
    "status": "success"
  }
}
Copy
#K 线频道
提供一种访问 K 线信息的方法.
 
#K 线订阅
如果在contract前面加上mark_,则将订阅合约的标记价格 K 线;如果 前缀为“index_”,将订阅指数价格 K 线.
 
#请求参数
channel
 
futures.candlesticks
 
event
 
subscribe
 
params
 
请求参数
名称    类型    描述
interval    String    Interval : "10s", "1m", "5m", "15m", "30m", "1h", "4h", "8h", "1d", "7d"
contract    String    合约名称
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
ws.send('{"time" : 123456, "channel" : "futures.candlesticks","event": "subscribe", "payload" : ["1m", "BTC_USD"]}')
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545445847,
  "time_ms": 1545445847123,
  "channel": "futures.candlesticks",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#k 线消息推送
k 线的消息推送
 
#推送参数
channel
 
futures.candlesticks
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    Array    Array of objects
推送参数
名称    类型    描述
t    Integer    时间
o    String    开盘价格
c    String    收盘价格
h    String    最高价格
l    String    最低价格
v    String/Integer    成交量
n    String    合约名称
a    String    成交原始币种数量
w    Boolean    true 表示窗口已关闭。注:可能会缺失 true 的消息,但不影响数据的完整性
{
  "time": 1542162490,
  "time_ms": 1542162490123,
  "channel": "futures.candlesticks",
  "event": "update",
  "result": [
    {
      "t": 1545129300,
      "v": "27525555",
      "c": "95.4",
      "h": "96.9",
      "l": "89.5",
      "o": "94.3",
      "n": "1m_BTC_USD",
      "a": "314732.87412",
      "w": false
    },
    {
      "t": 1545129300,
      "v": "27525555",
      "c": "95.4",
      "h": "96.9",
      "l": "89.5",
      "o": "94.3",
      "n": "1m_BTC_USD",
      "a": "314732.87412",
      "w": true
    }
  ]
}
Copy
#取消订阅
取消订阅指定市场 K 线信息
 
#请求参数
channel
 
futures.candlesticks
 
event
 
unsubscribe
 
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
ws.send(
  '{"time" : 123456, "channel" : "futures.candlesticks", "event": "unsubscribe", "payload" : ["1m", "BTC_USD"]}')
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545445847,
  "time_ms": 1545445847123,
  "channel": "futures.candlesticks",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#公共强平订单频道
提供一种接收Gate强平订单信息的方式,每个合约每1秒最多推一条强平订单数据
 
#公共强平订单订阅
如果您想订阅所有合约中的强平订单推送,请在订阅请求列表中使用 !all
 
订阅公共强平订单推送
 
#请求参数
channel
 
futures.public_liquidates
 
event
 
subscribe
 
params
 
名称    类型    必选    描述
contract    String    是    合约名称列表
代码示例
 
import json
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
    "time": 123456,
    "channel": "futures.public_liquidates",
    "event": "subscribe",
    "payload": ["BTC_USD","ETH_USD"],
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
    "time": 1545459681,
    "time_ms": 1545459681123,
    "channel": "futures.public_liquidates",
    "event": "subscribe",
    "result": {
        "status": "success"
    }
}
Copy
#公共强平订单推送
推送公共强制平仓更新
 
#推送参数
channel
 
futures.public_liquidates
 
event
 
update
 
params
 
名称    类型    描述
result    Array    Array of objects
名称    类型    描述
price    Float    订单价格
size    String/Integer    强平订单数量
time_ms    Integer    时间(以毫秒为单位)
contract    String    合约名称
{
    "channel": "futures.public_liquidates",
    "event": "update",
    "time": 1541505434,
    "time_ms": 1541505434123,
    "result": [
        {
        "price": 215.1,
        "size": "-124",
        "time_ms": 1541486601123,
        "contract": "BTC_USD",
        }
    ]
}
Copy
#取消订阅
取消订阅公共强平订单更新
 
#请求参数
channel
 
futures.public_liquidates
 
event
 
unsubscribe
 
代码示例
 
import json
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
    "time": 123456,
    "channel": "futures.public_liquidates",
    "event": "unsubscribe",
    "payload": ["BTC_USD"],
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
 {
    "time": 1545459681,
    "time_ms": 1545459681123,
     "channel": "futures.public_liquidates",
     "event": "unsubscribe",
     "result": {
        "status": "success"
     }
}
Copy
#合约统计信息频道
contract_stats 通道允许您获取合约统计信息
 
#订阅操作
订阅合约统计信息
 
#请求参数
channel
 
futures.contract_stats
 
event
 
subscribe
 
params
 
名称    类型    必选    描述
contract    String    Yes    合约名称
interval    String    Yes    Interval : "1m", "5m", "15m", "30m", "1h", "4h", "8h", "1d", "3d", "7d"
代码示例
 
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
ws.send('{"time" : 123456, "channel" : "futures.contract_stats","event": "subscribe", "payload" : ["BTC_USD","1m"]}')
print(ws.recv())
Copy
上面的订阅请求返回 JSON 结构如下:
 
{
  "time": 1545404023,
  "time_ms": 1545404023123,
  "channel": "futures.contract_stats",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#contract_stats 推送
合约统计信息推送
 
#推送参数
channel
 
futures.contract_stats
 
event
 
update
 
params
 
名称    类型    描述
result    Array    Array of objects
名称    类型    描述
time    Integer    统计时间(时间戳)
contract    string    合约名称
mark_price    Float    当前标记价格
lsr_taker    Float    多空吃单比
lsr_account    Float    多空持仓用户比
long_liq_size    string/Integer    做多爆仓量(张)
long_liq_amount    Float    做多爆仓量(交易币种)
long_liq_usd    Float    做多爆仓量(计价币种)
short_liq_size    string/Integer    做空爆仓量(张)
short_liq_amount    Float    做空爆仓量(交易币种)
short_liq_usd    Float    做空爆仓量(计价币种)
open_interest    string/Integer    总持仓量(张)
open_interest_usd    Float    总持仓量(计价币种)
top_lsr_account    Float    大户多空账户比
top_lsr_size    Float    大户多空持仓比
{
  "time": 1541659086,
  "time_ms": 1541659086123,
  "channel": "futures.contract_stats",
  "event": "update",
  "result": [
    {
      "time": 1603865400,
      "contract":"BTC_USDT",
      "lsr_taker": 100,
      "lsr_account": 0.5,
      "long_liq_size": "0",
      "short_liq_size": "0",
      "open_interest": "124724",
      "short_liq_usd": 0,
      "mark_price": "8865",
      "top_lsr_size": 1.02,
      "short_liq_amount": 0,
      "long_liq_amount": 0,
      "open_interest_usd": 1511,
      "top_lsr_account": 1.5,
      "long_liq_usd": 0
    }
  ]
}
Copy
#取消订阅
取消订阅
 
#请求参数
channel
 
futures.contract_stats
 
event
 
unsubscribe
 
params
 
名称    类型    必选    描述
contract    String    Yes    合约名称
interval    String    Yes    Interval : "1m", "5m", "15m", "30m", "1h", "4h", "8h", "1d", "3d", "7d"
注意:contract为unsub_all,表示全部取消
 
代码示例
 
import json
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
    "time": 123456,
    "channel": "futures.contract_stats",
    "event": "unsubscribe",
    "payload": ["BTC_USD","1m"]
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的请求返回 JSON 结构如下:
 
{
  "time": 1545404900,
  "time_ms": 1545404900123,
  "channel": "futures.contract_stats",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#订单频道
提供接收用户订单的推送
 
需要认证.
 
#订单订阅
如果您想订阅所有合约中的订单更新,请在合约列表中使用 !all。
 
订阅订单更新推送
 
#请求参数
channel
 
futures.orders
 
event
 
subscribe
 
params
 
请求参数
名称    类型    必选    描述
user id    String    是    用户 ID
contract    String    是    合约名称
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
  "time": int(time.time()),
  "channel": "futures.orders",
  "event": "subscribe",
  "payload": ["20011", "BTC_USD"],
  "auth": {
    "method": "api_key",
    "KEY": "xxxx",
    "SIGN": "xxxx"
  }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.orders",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#订单推送
下单、更新或完成时通知用户订单信息
 
#推送参数
channel
 
futures.orders
 
event
 
update
 
params
 
推送结果参数含义请参考http接口.
 
推送参数
名称    类型    描述
result    Array    Array of objects
推送参数
名称    类型    描述
create_time    Integer    订单创建时间(已弃用)
create_time_ms    Integer    订单创建时间戳(以毫秒为单位)
fill_price    Float    订单成交价格
finish_as    String    订单是如何完成的。
- filled:全部成交
- cancelled:手动取消
- liquidated:因清算而取消
- ioc:生效时间为 IOC,立即完成
- auto_deleveraging:ADL 完成
- reduce_only:因减仓设置而增仓而取消
- position_close:因平仓而取消
- stp:订单发生自成交限制而被撤销
- _new:新建
- _update:成交或部分成交或更新订单
- reduce_out: 只减仓被排除的不容易成交的挂单
iceberg    String/Integer    冰山下单显示的数量,不指定或传 0 都默认为普通下单。目前不支持全部冰山。
id    Integer    订单 ID
is_close    Bool    该订单是否为 close position
is_liq    Bool    该订单是否为 liquidation
left    String/Integer    剩余可交易数量
mkfr    Float    Maker 费用
is_reduce_only    Bool    该订单是否为 reduce-only
status    String    订单状态
- open: 等待交易
- finished: 完成
tkfr    Float    taker 费用
price    Float    订单价格。 0 表示市价订单,tif 设置为 ioc
refu    Integer    推荐用户 ID
refr    Float    
size    String/Integer    订单大小。指定正数进行出价,指定负数进行询问
text    String    用户定义的信息
tif    String    有效时间
- gtc:GoodTillCancelled
- ioc:ImmediateOrCancelled,仅接受者
- poc:PendingOrCancelled,只进行后订单,始终享受挂单费用
- fok: FillOrKill,完全填充或不填充
type=market 时仅支持 ioc 和 fok
finish_time    Integer    订单结束 unix 时间戳(以秒为单位),未结束订单此字段返回0
finish_time_ms    Integer    订单结束 unix 时间戳(以毫秒为单位),未结束订单此字段返回0
user    String    用户 ID
contract    String    合约名称
stp_id    String    同一 stp_id 组内的用户之间的订单不允许自交易
1.如果匹配的两个订单的 stp_id 非零且相等,则不会被执行。而是根据 taker 的 stp_act 执行相应的策略。
2.对于未设置 STP 组的订单,stp_id 默认返回 0
stp_act    String    自我交易预防行动。用户可以通过该字段设置自我交易防范策略
1.用户加入 STP Group 后,可以通过 stp_act 来限制用户的自我交易防范策略。如果不传 stp_act,则默认为 cn 策略。
2.当用户没有加入 STP 组时,传递 stp_act 参数时会返回错误。
3.如果用户下单时没有使用'stp_act','stp_act'将返回'-'
- cn: 取消最新订单,取消新订单并保留旧订单
- co: 取消最旧订单,取消旧订单并保留新订单
- cb:取消两者,新旧订单都会被取消
amend_text    String    用户修改订单时备注的自定义数据
update_id    Integer    更新id
update_time    Integer    更新时间 (毫秒时间戳)
biz_info    String    用户可以备注这次修改的信息
stop_profit_price    String    止盈价格
stop_loss_price    String    止损价格
market_order_slip_ratio    String    该笔市价单的预设的最大滑点比率(不代表实际的滑点),0.03代表3%的最大滑点
{
  "channel": "futures.orders",
  "event": "update",
  "time": 1541505434,
  "time_ms": 1541505434123,
  "result": [
    {
      "contract": "BTC_USD",
      "create_time": 1628736847,
      "create_time_ms": 1628736847325,
      "fill_price": 40000.4,
      "finish_as": "filled",
      "finish_time": 1628736848,
      "finish_time_ms": 1628736848321,
      "iceberg": "0",
      "id": 4872460,
      "is_close": false,
      "is_liq": false,
      "is_reduce_only": false,
      "left": "0",
      "mkfr": -0.00025,
      "price": 40000.4,
      "refr": 0,
      "refu": 0,
      "size": "1",
      "status": "finished",
      "text": "-",
      "tif": "gtc",
      "tkfr": 0.0005,
      "user": "110xxxxx",
      "update_id": 1,
      "update_time": 1541505434123,
      "stop_loss_price": "",
      "stop_profit_price": "",
      "market_order_slip_ratio": "0.03"
    }
  ]
}
Copy
#取消订阅
取消订阅订单更新通知
 
#请求参数
channel
 
futures.orders
 
event
 
unsubscribe
 
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
  "time": int(time.time()),
  "channel": "futures.orders",
  "event": "unsubscribe",
  "payload": ["20011", "BTC_USD"],
  "auth": {
    "method": "api_key",
    "KEY": "xxxx",
    "SIGN": "xxxx"
  }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.orders",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#用户私有成交频道
提供接收用户交易的方式
 
需要认证
 
#用户私有成交订阅
如果您想订阅所有的市场交易更新,请在请求参数列表中使用!all。
 
订阅私有成交更新
 
#请求参数
channel
 
futures.usertrades
 
event
 
subscribe
 
params
 
请求参数
名称    类型    必选    描述
user id    String    是    用户 ID
contract    String    是    合约名称
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
  "time": int(time.time()),
  "channel": "futures.usertrades",
  "event": "subscribe",
  "payload": ["20011", "BTC_USD"],
  "auth": {
    "method": "api_key",
    "KEY": "xxxx",
    "SIGN": "xxxx"
  }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.usertrades",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#用户私有成交推送
推送用户私有成交更新
 
#推送参数
channel
 
futures.usertrades
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    Array    Array of objects
推送参数
名称    类型    描述
contract    String    合约名称
create_time    Integer    创建时间
create_time_ms    Integer    创建时间(以毫秒为单位)
id    String    交易 ID
order_id    String    订单 ID
price    String    交易价格
size    String/Integer    交易数量
role    String    用户角色 (maker/taker)
text    String    订单自定义信息,用户可以用该字段设置自定义 ID,用户自定义字段必须满足以下条件:
 
1. 必须以 t- 开头
2. 不计算 t- ,长度不能超过 28 字节
3. 输入内容只能包含数字、字母、下划线(_)、中划线(-) 或者点(.)
 
除用户自定义信息以外,以下为内部保留字段,标识订单来源:
 
- web: 网页
- api: API 调用
- app: 移动端
- auto_deleveraging: 自动减仓
- liquidation: 老经典模式仓位强制平仓
- liq-xxx: a. 新经典模式仓位强制平仓,包含逐仓、单向全仓、双向全仓非对冲仓位强平。 b. 统一账户单币种保证金模式逐仓强制平仓
- hedge-liq-xxx: 新经典模式双向全仓对冲部分强制平仓,即同时平多空仓位
- pm_liquidate: 统一账户跨币种保证金模式强制平仓
- comb_margin_liquidate: 统一账户组合保证金模式强制平仓
- scm_liquidate: 统一账户单币种保证金模式仓位强制平仓
- insurance: 保险
- clear: 合约下架清退
fee    Float    手续费
point_fee    Float    点卡手续费
{
  "time": 1543205083,
  "time_ms": 1543205083123,
  "channel": "futures.usertrades",
  "event": "update",
  "result": [
    {
      "id": "3335259",
      "create_time": 1628736848,
      "create_time_ms": 1628736848321,
      "contract": "BTC_USD",
      "order_id": "4872460",
      "size": "1",
      "price": "40000.4",
      "role": "maker",
      "text": "api",
      "fee": 0.0009290592,
      "point_fee": 0
    }
  ]
}
Copy
#取消订阅
取消私有成交订阅
 
#请求参数
channel
 
futures.usertrades
 
event
 
unsubscribe
 
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
  "time": int(time.time()),
  "channel": "futures.usertrades",
  "event": "unsubscribe",
  "payload": ["20011", "BTC_USD"],
  "auth": {
    "method": "api_key",
    "KEY": "xxxx",
    "SIGN": "xxxx"
  }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.usertrades",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#强制平仓频道
提供一种接收用户强制平仓信息的方式
 
需要认证
 
#清算订阅
如果您想订阅所有合约中的强制平仓推送,请在订阅请求列表中使用 !all
 
订阅用户强制平仓推送
 
#请求参数
channel
 
futures.liquidates
 
event
 
subscribe
 
params
 
请求参数
名称    类型    必选    描述
user id    String    是    用户 ID
contract    String    是    合约名称
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
  "time": int(time.time()),
  "channel": "futures.liquidates",
  "event": "subscribe",
  "payload": ["20011", "BTC_USD"],
  "auth": {
    "method": "api_key",
    "KEY": "xxxx",
    "SIGN": "xxxx"
  }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.liquidates",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#强制平仓推送
推送强制平仓更新
 
#推送参数
channel
 
futures.liquidates
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    Array    Array of objects
推送参数
名称    类型    描述
entry_price    Float    平均入场价
fill_price    Float    平均执行价格
leverage    Float    杠杆大小
liq_price    Float    清算价格
margin    Float    Margin
mark_price    Float    标记价格
order_id    Integer    订单 ID
order_price    Float    订单价格
left    String/Integer    订单未完成数量
size    Integer    原始订单数量
time    Integer    时间
time_ms    Integer    时间(以毫秒为单位)
user    String    用户 ID
contract    String    合约名称
{
  "channel": "futures.liquidates",
  "event": "update",
  "time": 1541505434,
  "time_ms": 1541505434123,
  "result": [
    {
      "entry_price": 209,
      "fill_price": 215.1,
      "left": 0,
      "leverage": 0.0,
      "liq_price": 213,
      "margin": 0.007816722941,
      "mark_price": 213,
      "order_id": 4093362,
      "order_price": 215.1,
      "size": "-124",
      "time": 1541486601,
      "time_ms": 1541486601123,
      "contract": "BTC_USD",
      "user": "1040xxxx"
    }
  ]
}
Copy
#取消订阅
取消订阅清算更新
 
#请求参数
channel
 
futures.liquidates
 
event
 
unsubscribe
 
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
  "time": int(time.time()),
  "channel": "futures.liquidates",
  "event": "unsubscribe",
  "payload": ["20011", "BTC_USD"],
  "auth": {
    "method": "api_key",
    "KEY": "xxxx",
    "SIGN": "xxxx"
  }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.liquidates",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#自动减仓频道
提供一种接收用户自动减仓信息的方法
 
需要认证
 
#自动减仓订阅
如果您想订阅所有合约的自动减仓更新,请在请求参数列表中使用!all
 
订阅用户自动减仓更新
 
#请求参数
channel
 
futures.auto_deleverages
 
event
 
subscribe
 
params
 
请求参数
名称    类型    必选    描述
user id    String    是    用户 ID
contract    String    是    合约名称
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
  "time": int(time.time()),
  "channel": "futures.auto_deleverages",
  "event": "subscribe",
  "payload": ["20011", "BTC_USD"],
  "auth": {
    "method": "api_key",
    "KEY": "xxxx",
    "SIGN": "xxxx"
  }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.auto_deleverages",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#自动减仓推送
自动减仓消息
 
#推送参数
channel
 
futures.auto_deleverages
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    Array    Array of objects
推送参数
名称    类型    描述
entry_price    Float    入场价格
fill_price    Float    执行价格
position_size    Integer    持仓规模
trade_size    Integer    交易数量
time    Integer    时间
time_ms    Integer    时间(以毫秒为单位)
user    String    用户 ID
contract    String    合约名称
{
  "channel": "futures.auto_deleverages",
  "event": "update",
  "time": 1541505434,
  "time_ms": 1541505434123,
  "result": [
    {
      "entry_price": 209,
      "fill_price": 215.1,
      "position_size": "10",
      "trade_size": "10",
      "time": 1541486601,
      "time_ms": 1541486601123,
      "contract": "BTC_USD",
      "user": "1040"
    }
  ]
}
Copy
#取消订阅
取消订阅自动减仓
 
#请求参数
channel
 
futures.auto_deleverages
 
event
 
unsubscribe
 
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
  "time": int(time.time()),
  "channel": "futures.auto_deleverages",
  "event": "unsubscribe",
  "payload": ["20011", "BTC_USD"],
  "auth": {
    "method": "api_key",
    "KEY": "xxxx",
    "SIGN": "xxxx"
  }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.auto_deleverages",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#平仓频道
提供一种接收用户仓位平仓信息的方法
 
需要认证
 
#平仓订阅
如果您想订阅所有合约的平仓更新,请在合约列表中使用 !all
 
订阅用户平仓信息更新
 
#请求参数
channel
 
futures.position_closes
 
event
 
subscribe
 
params
 
请求参数
名称    类型    必选    描述
user id    String    是    用户 ID
contract    String    是    合约名称
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
  "time": int(time.time()),
  "channel": "futures.position_closes",
  "event": "subscribe",
  "payload": ["20011", "BTC_USD"],
  "auth": {
    "method": "api_key",
    "KEY": "xxxx",
    "SIGN": "xxxx"
  }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.position_closes",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#平仓信息推送
平仓信息推送
 
#推送参数
channel
 
futures.position_closes
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    Array    Array of objects
推送参数
名称    类型    描述
contract    String    合约名称
pnl    Number    利润损失
side    String    方向 (long or short)
text    String    附带信息
time    Integer    时间
time_ms    Integer    时间(以毫秒为单位)
user    String    用户 ID
{
  "channel": "futures.position_closes",
  "event": "update",
  "time": 1541505434,
  "time_ms": 1541505434123,
  "result": [
    {
      "contract": "BTC_USD",
      "pnl": -0.000624354791,
      "side": "long",
      "text": "web",
      "time": 1547198562,
      "time_ms": 1547198562123,
      "user": "211xxxx"
    }
  ]
}
Copy
#取消订阅
取消订阅平仓更新
 
#请求参数
channel
 
futures.position_closes
 
event
 
unsubscribe
 
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
    "time": int(time.time()),
    "channel": "futures.position_closes",
    "event": "unsubscribe",
    "payload": ["20011", "BTC_USD"],
    "auth": {
        "method": "api_key",
        "KEY": "xxxx",
        "SIGN": "xxxx"
    }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.position_closes",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#余额频道
提供一种接收用户余额信息的方法
 
需要认证
 
#余额信息订阅
订阅用户余额更新
 
#请求参数
channel
 
futures.balances
 
event
 
subscribe
 
params
 
请求参数
名称    类型    必选    描述
user id    String    是    用户 ID
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
    "time": int(time.time()),
    "channel": "futures.balances",
    "event": "subscribe",
    "payload": ["20011"],
    "auth": {
        "method": "api_key",
        "KEY": "xxxx",
        "SIGN": "xxxx"
    }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.balances",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#余额更新推送
通知余额更新信息
 
#推送参数
channel
 
futures.balances
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    Array    Array of objects
推送参数
名称    类型    描述
balance    Number    余额最终数量
change    Number    余额变化数量
text    String    附带信息
time    Integer    时间
time_ms    Integer    时间(以毫秒为单位)
type    String    变更类型:
dnw: 出入金
pnl:盈亏
refr: 推荐人费用
fund: 资金费用
cross_settle: 统一账户结算
point_dnw: 点卡出入金
point_fee: 点卡手续费
point_refr: 点卡推荐人费用
bonus_dnw: 体验金出入金
pv_dnw: 仓位体验券充值提现
fee: 手续费
user    String    用户 ID
currency    String    币种
{
  "channel": "futures.balances",
  "event": "update",
  "time": 1541505434,
  "time_ms": 1541505434123,
  "result": [
    {
      "balance": 9.998739899488,
      "change": -0.000002074115,
      "text": "BTC_USD:3914424",
      "time": 1547199246,
      "time_ms": 1547199246123,
      "type": "fee",
      "user": "211xxx",
      "currency": "btc"
    }
  ]
}
Copy
#取消订阅
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
    "time": int(time.time()),
    "channel": "futures.balances",
    "event": "unsubscribe",
    "payload": ["20011"],
    "auth": {
        "method": "api_key",
        "KEY": "xxxx",
        "SIGN": "xxxx"
    }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.balances",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#降低风险率频道
推送用户降低风险率信息
 
需要认证
 
#降低风险率订阅
如果您想订阅所有合约的降低风险率更新,请在合约列表中使用 !all。
 
订阅用户降低风险率更新
 
#请求参数
channel
 
futures.reduce_risk_limits
 
event
 
subscribe
 
params
 
请求参数
名称    类型    必选    描述
user id    String    是    用户 ID
contract    String    是    合约名称
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
    "time": int(time.time()),
    "channel": "futures.reduce_risk_limits",
    "event": "subscribe",
    "payload": ["20011", "BTC_USD"],
    "auth": {
        "method": "api_key",
        "KEY": "xxxx",
        "SIGN": "xxxx"
    }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.reduce_risk_limits",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#降低风险率推送
通知降低风险限制更新
 
#推送参数
channel
 
futures.reduce_risk_limits
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    Array    Array of objects
推送参数
名称    类型    描述
cancel_orders    Integer    Cancel orders
contract    String    合约名称
leverage_max    Integer    最大杠杆
liq_price    Float    清算价格
maintenance_rate    Float    Maintenance rate
risk_limit    Integer    风险限额
time    Integer    时间
time_ms    Integer    时间(以毫秒为单位)
user    String    用户 ID
{
  "time": 1551858330,
  "time_ms": 1551858330123,
  "channel": "futures.reduce_risk_limits",
  "event": "update",
  "result": [
    {
      "cancel_orders": 0,
      "contract": "ETH_USD",
      "leverage_max": 10,
      "liq_price": 136.53,
      "maintenance_rate": 0.09,
      "risk_limit": 450,
      "time": 1551858330,
      "time_ms": 1551858330123,
      "user": "20011"
    }
  ]
}
Copy
#取消订阅
退订降低风险限制更新
 
#请求参数
channel
 
futures.reduce_risk_limits
 
event
 
unsubscribe
 
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
    "time": int(time.time()),
    "channel": "futures.reduce_risk_limits",
    "event": "unsubscribe",
    "payload": ["20011", "BTC_USD"],
    "auth": {
        "method": "api_key",
        "KEY": "xxxx",
        "SIGN": "xxxx"
    }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
#仓位频道
提供一种接收用户仓位信息的方法
 
需要认证
 
#仓位订阅
如果您想订阅所有合约的持仓更新,请在合约列表中使用 !all
 
订阅用户仓位更新
 
#请求参数
channel
 
futures.positions
 
event
 
subscribe
 
params
 
请求参数
名称    类型    必选    描述
user id    String    是    用户 ID (该字段已废弃,仅做占位符使用)
contract    String    是    合约名称
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
    "time": int(time.time()),
    "channel": "futures.positions",
    "event": "subscribe",
    "payload": ["20011", "BTC_USD"],
    "auth": {
        "method": "api_key",
        "KEY": "xxxx",
        "SIGN": "xxxx"
    }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.positions",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#仓位信息推送
推送仓位更新.
 
#推送参数
channel
 
futures.positions
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    Array    Array of objects
推送参数
名称    类型    描述
contract    String    合约名称
cross_leverage_limit    Float    全仓模式下的杠杆倍数
entry_price    Float    开仓价格
history_pnl    Float    已平仓的仓位总盈亏
history_point    Float    已平仓的点卡总盈亏
last_close_pnl    Float    最近一次平仓的盈亏
leverage    Integer    杠杆倍数,0代表全仓,正数代表逐仓
leverage_max    Integer    当前风险限额下,允许的最大杠杆倍数
liq_price    Float    爆仓价格
maintenance_rate    Float    当前风险限额下,维持保证金比例
margin    Float    保证金
realised_pnl    Float    已实现盈亏
realised_point    Float    点卡已实现盈亏
risk_limit    Integer    风险限额
size    String/Integer    合约 size
time    Integer    更新 unix 时间戳
time_ms    Integer    更新 unix 时间戳(以毫秒为单位)
user    String    用户 ID
update_id    Integer    消息序列号,每次推送 order 之后会自增 1
{
  "time": 1588212926,
  "time_ms": 1588212926123,
  "channel": "futures.positions",
  "event": "update",
  "result": [
    {
      "contract": "BTC_USD",
      "cross_leverage_limit": 0,
      "entry_price": 40000.36666661111,
      "history_pnl": -0.000108569505,
      "history_point": 0,
      "last_close_pnl": -0.000050123368,
      "leverage": 0,
      "leverage_max": 100,
      "liq_price": 0.1,
      "maintenance_rate": 0.005,
      "margin": 49.999890611186,
      "mode": "single",
      "realised_pnl": -1.25e-8,
      "realised_point": 0,
      "risk_limit": 100,
      "size": "3",
      "time": 1628736848,
      "time_ms": 1628736848321,
      "user": "110xxxxx",
      "update_id": 170919
    }
  ]
}
Copy
#取消订阅
取消订阅仓位更新
 
#请求参数
channel
 
futures.positions
 
event
 
unsubscribe
 
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
    "time": int(time.time()),
    "channel": "futures.positions",
    "event": "unsubscribe",
    "payload": ["20011", "BTC_USD"],
    "auth": {
        "method": "api_key",
        "KEY": "xxxx",
        "SIGN": "xxxx"
    }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.positions",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#仓位 Adl 排名频道
推送用户仓位 adl 排名信息的频道
 
需要认证
 
#仓位 adl 订阅
如果您想订阅所有合约的 adl 更新,请在合约列表中使用 !all
 
订阅用户仓位 adl 更新
 
#请求参数
channel
 
futures.position_adl_rank
 
event
 
subscribe
 
params
 
请求参数
名称    类型    必选    描述
contract    String    是    合约名称
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://ws-testnet.gate.com/v4/ws/futures/usdt")
req = {
    "time": int(time.time()),
    "channel": "futures.position_adl_rank",
    "event": "subscribe",
    "payload": ["BTC_USDT"],
    "auth": {
        "method": "api_key",
        "KEY": "xxxx",
        "SIGN": "xxxx"
    }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.position_adl_rank",
  "event": "subscribe",
  "payload": [
    "BTC_USDT"
  ],
  "result": {
    "status": "success"
  }
}
Copy
#仓位 adl 信息推送
推送仓位更新.
 
#推送参数
channel
 
futures.position_adl_rank
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    Array    Array of objects
推送参数
名称    类型    描述
contract    String    合约名称
mode    String    持仓模式
rank_division    Integer    排名区间(1~6,1为最优先被ADL的区间,5为最靠后被ADL的区间。6:爆仓中不参与ADL排序)
time_ms    Integer    消息推送的毫秒时间戳
user_id    Integer    用户 ID
{
    "time": 1588212926,
    "time_ms": 1588212926123,
    "channel": "futures.position_adl_rank",
    "event": "update",
    "result": [
        {
            "contract": "BTC_USDT",
            "mode": "single",
            "rank_division": 1,
            "time_ms": 1588212926119,
            "user_id": 2124426495
        }
    ]
}
Copy
#取消订阅
取消订阅仓位更新
 
#请求参数
channel
 
futures.position_adl_rank
 
event
 
unsubscribe
 
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://ws-testnet.gate.com/v4/ws/futures/usdt")
req = {
    "time": int(time.time()),
    "channel": "futures.position_adl_rank",
    "event": "unsubscribe",
    "payload": ["BTC_USDT"],
    "auth": {
        "method": "api_key",
        "KEY": "xxxx",
        "SIGN": "xxxx"
    }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.position_adl_rank",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#自动订单频道
提供一种接收用户自动订单信息的方法
 
需要认证
 
#自动订单订阅
如果您想订阅所有合约中的自动订单更新,请在合约列表中使用!all
 
订阅用户自动订单更新
 
#请求参数
channel
 
futures.autoorders
 
event
 
subscribe
 
params
 
请求参数
名称    类型    必选    描述
contract    String    是    合约名称
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
    "time": int(time.time()),
    "channel": "futures.autoorders",
    "event": "subscribe",
    "payload": ["BTC_USDT"],
    "auth": {
        "method": "api_key",
        "KEY": "xxxx",
        "SIGN": "xxxx"
    }
}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.autoorders",
  "event": "subscribe",
  "result": {
    "status": "success"
  }
}
Copy
#自动订单消息推送
通知自动订单更新
 
#推送参数
channel
 
futures.autoorders
 
event
 
update
 
params
 
推送参数
名称    类型    描述
result    Array    Array of objects
推送参数
名称    类型    描述
user    Number    用户 ID
trigger    Object    
initial    Object    
id    Number    自动订单 ID
trade_id    Number    交易 ID
status    String    订单状态
reason    String    变更原因
create_time    Number    创建时间
name    String    名称
is_stop_order    boolean    是否停止
stop_trigger    Object    
order_type    String    止盈/止损类型,详情参见 http api
me_order_id    Number    订单止盈/止损对应订单 ID.
{
  "time": 1596798126,
  "time_ms": 1596798126123,
  "channel": "futures.autoorders",
  "event": "update",
  "result": [
    {
      "user": 123456,
      "trigger": {
        "strategy_type": 0,
        "price_type": 0,
        "price": "10000",
        "rule": 2,
        "expiration": 86400
      },
      "initial": {
        "contract": "BTC_USDT",
        "size": "10",
        "price": "10000",
        "tif": "gtc",
        "text": "web",
        "iceberg": "0",
        "is_close": false,
        "is_reduce_only": false,
        "auto_size": ""
      },
      "id": 9256,
      "trade_id": 0,
      "status": "open",
      "reason": "",
      "create_time": 1596798126,
      "name": "price_autoorders",
      "is_stop_order": false,
      "stop_trigger": {
        "rule": 0,
        "trigger_price": "",
        "order_price": ""
      },
      "order_type": "close-long-order",
      "me_order_id": "213867453823"
    }
  ]
}
Copy
#取消订阅
取消订阅自动订单更新
 
#请求参数
channel
 
futures.autoorders
 
event
 
unsubscribe
 
代码示例
 
import json, time
from websocket import create_connection
 
ws = create_connection("wss://fx-ws-testnet.gateio.ws/v4/ws/btc")
req = {
    "time": int(time.time()),
    "channel": "futures.autoorders",
    "event": "unsubscribe",
    "payload": ["BTC_USDT"],
    "auth": {
        "method": "api_key",
        "KEY": "xxxx",
        "SIGN": "xxxx"
    }}
ws.send(json.dumps(req))
print(ws.recv())
Copy
上面的命令返回 JSON 结构如下:
 
{
  "time": 1545459681,
  "time_ms": 1545459681123,
  "channel": "futures.autoorders",
  "event": "unsubscribe",
  "result": {
    "status": "success"
  }
}
Copy
#账户交易 API
#Websocket 交易 API
WebSocket API 允许通过 WebSocket 连接下单、取消、修改、查询订单.
 
#Websocket API 客户端请求
客户端发起的 api 请求遵循通用的 JSON 格式, 包含以下字段:
 
名称    类型    必选    描述
time    Integer    是    请求时间(以秒为单位)。请求时间和服务器时间之间的差距不得超过 60 秒
id    Integer    否    可选的请求 ID,将由服务器发回,以帮助您识别服务器响应哪个请求
channel    String    是    要访问的 WebSocket 频道
event    String    是    固定为api
payload    Object    是    可选请求详细参数
»req_id    String    是    消息的唯一标识符由客户端提供,将在响应消息中返回,用于标识相应的请求。
»timestamp    String    是    签名时间(秒)
»api_key    String    是    Gate APIv4 APIKey
»signature    String    是    使用 GateAPIv4 密钥和请求信息生成的身份验证签名,
详细信息请参见[Websocket API 身份验证](#Websocket API 身份验证)部分
»req_param    []Byte    是    请求 api 参数
请注意,payload.req_param 的类型是与频道(channel字段)绑定的,频道不同payload.req_param 的字段也不同,以 futures.order_place 为例,payload.req_param 与 apiv4 /futures/{settle}/orders (opens new window)。 例如,您可以对 BTC_USDT 下限价单
 
代码示例
 
#!/usr/bin/python
 
import time
import json
import hmac
import hashlib
import websocket
import threading
 
 
API_KEY = "xxxxx"
SECRET = "xxxxx"
WS_URL = "wss://fx-ws.gateio.ws/v4/ws/usdt"
CHANNEL_LOGIN = "futures.login"
CHANNEL_ORDER_PLACE = "futures.order_place"
 
def get_ts():
    return int(time.time())
 
def get_ts_ms():
    return int(time.time() * 1000)
 
def get_signature(secret, channel, request_param_bytes, ts):
    key = f"api\n{channel}\n{request_param_bytes.decode()}\n{ts}"
    return hmac.new(secret.encode(), key.encode(), hashlib.sha512).hexdigest()
 
def build_login_request():
    ts = get_ts()
    req_id = f"{get_ts_ms()}-1"
    request_param = b""
 
    sign = get_signature(SECRET, CHANNEL_LOGIN, request_param, ts)
 
    payload = {
        "api_key": API_KEY,
        "signature": sign,
        "timestamp": str(ts),
        "req_id": req_id
    }
 
    return {
        "time": ts,
        "channel": CHANNEL_LOGIN,
        "event": "api",
        "payload": payload
    }
 
 
def build_order_request():
    ts = get_ts()
    req_id = f"{get_ts_ms()}-2"
    order_param = {
        "contract": "BTC_USDT",
        "size": 6024,
        "iceberg": 0,
        "price": "3765",
        "tif": "gtc",
        "text": "t-my-custom-id",
        "stp_act": "-"
    }
 
 
    payload = {
        "req_id": req_id,
        "req_param": order_param
    }
 
    return {
        "time": ts,
        "channel": CHANNEL_ORDER_PLACE,
        "event": "api",
        "payload": payload
    }
 
 
def on_message(ws, message):
    print(f"recv: {message}")
 
def on_error(ws, error):
    print(f"error: {error}")
 
def on_close(ws, close_status_code, close_msg):
    print("connection closed")
 
def on_open(ws):
    print("WebSocket opened")
 
    login_payload = build_login_request()
    print("login payload:", login_payload)
    ws.send(json.dumps(login_payload))
 
    def delayed_order():
        time.sleep(2)
        order_payload = build_order_request()
        print("order payload:", order_payload)
        ws.send(json.dumps(order_payload))
 
    threading.Thread(target=delayed_order).start()
 
custom_headers = {
    "X-Gate-Size-Decimal": "1"
}
 
if __name__ == "__main__":
    ws = websocket.WebSocketApp(
        WS_URL,
        on_message=on_message,
        on_error=on_error,
        on_close=on_close,
        on_open=on_open,
        header=custom_headers
    )
    ws.run_forever()
 
Copy
{
  "time": 1680772890,
  "channel": "futures.order_place",
  "event": "api",
  "payload": {
    "req_id": "xxxx",
    "req_param": {
      "contract": "BTC_USDT",
      "size": "10",
      "price": "80048.240000",
      "tif": "gtc",
      "text": "t-my-custom-id"
    }
  }
}
Copy
#Websocket API 服务响应
服务器响应包括对客户端请求的 ack 响应和 api 结果消息推送。 服务器响应遵循通用的 JSON 格式,其中包含以下字段:
 
名称    类型    描述
request_id    String    对应的请求 ID
header    Map    响应元信息
»response_time    String    响应发送时间(毫秒)
»channel    String    请求频道
»event    String    请求event
»client_id    String    唯一的客户端 ID
»x_in_time    Integer    ws 接收请求的时间(以微秒为单位)
»x_out_time    Integer    ws 返回响应的时间(以微秒为单位)
»x_gate_ratelimit_requests_remain    Integer    (仅涉及下单/改单/撤单)当前时间窗口剩余可用请求数(为0不展示)
»x_gate_ratelimit_limit    Integer    (仅涉及下单/改单/撤单)当前频率限制上限(为0不展示)
»x_gat_ratelimit_reset_timestamp    Integer    (仅涉及下单/改单/撤单)已超过当前窗口频率限制,表示下个可用时间窗口的时间戳(毫秒),即什么时候可以恢复访问;未超过当前窗口频率限制,表示返回的是当前服务器时间(毫秒)
»conn_id    String    与客户端建立连接的链接Id(同一个连接的链接Id保持一致)
»conn_trace_id    String    与客户端建立连接的TraceId
»trace_id    String    执行下单操作的TraceId
data    Object    请求响应的数据
»result    Object    如果这是 ack 响应,则结果是请求的payload,否则结果是 api 的响应
»errs    Object    仅当请求失败时可用
»»label    String    错误类型
»»message    String    详细错误信息
服务器回声确认响应示例(目前仅在下单请求中有回声响应)
 
{
  "request_id": "request-id-1",
  "ack": true,
  "header": {
    "response_time": "1681195121499",
    "status": "200",
    "channel": "futures.order_place",
    "event": "api",
    "client_id": "::1-0x140031563c0",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d",
    "x_gate_ratelimit_requests_remain": 99,
    "x_gate_ratelimit_limit": 100,
    "x_gate_ratelimit_reset_timestamp": 1681195121499
  },
  "data": {
    "result": {
      "req_id": "request-id-1",
      "req_param": {
        "contract": "BTC_USDT",
        "size": "10",
        "price": "31503.280000",
        "tif": "gtc",
        "text": "t-my-custom-id"
      }
    }
  }
}
Copy
服务器 API 响应示例
 
{
  "request_id": "request-id-1",
  "ack": false,
  "header": {
    "response_time": "1681195121639",
    "status": "200",
    "channel": "futures.order_place",
    "event": "api",
    "client_id": "::1-0x140031563c0",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d",
    "x_gate_ratelimit_requests_remain": 99,
    "x_gate_ratelimit_limit": 100,
    "x_gate_ratelimit_reset_timestamp": 1681195121639
  },
  "data": {
    "result": {
      "id": 74046511,
      "user": 6790020,
      "create_time": 1681195121.754,
      "finish_time": 1681195121.754,
      "finish_as": "filled",
      "status": "finished",
      "contract": "BTC_USDT",
      "size": "10",
      "price": "31503.3",
      "tif": "gtc",
      "fill_price": "31500",
      "text": "t-my-custom-id",
      "tkfr": "0.0003",
      "mkfr": "0",
      "stp_id": 2,
      "stp_act": "cn",
      "amend_text": "-"
    }
  }
}
Copy
#错误
错误响应详情具有以下格式:
 
 
名称    类型    描述
label    String    错误类型
message    String    详细错误信息
限频相关的错误码说明:
 
错误码    描述
100    限流内部异常错误
311    合约限流
312    合约成交比率限流
错误响应通知示例
 
{
  "request_id": "request-id-1",
  "ack": false,
  "header": {
    "response_time": "1681195360034",
    "status": "401",
    "channel": "futures.login",
    "event": "api",
    "client_id": "::1-0x140001a2600",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d"
  },
  "data": {
    "errs": {
      "label": "INVALID_KEY",
      "message": "Invalid key provided"
    }
  }
}
Copy
Error 推送示例(限速)
 
{
  "request_id": "xxxx",
  "header": {
    "response_time": "1677816784084",
    "status": "429",
    "channel": "futures.order_place",
    "event": "api",
    "client_id": "::1-0x14002ba2300",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d",
    "x_gate_ratelimit_limit": 100,
    "x_gate_ratelimit_reset_timestamp": 1677816785084
  },
  "data": {
    "errs": {
      "label": "TOO_MANY_REQUESTS",
      "message": "Request Rate limit Exceeded (311)"
    }
  }
}
Copy
#登录
注意:您使用的 GateAPIv4 密钥对必须具有合约账户对应的权限(例如:order-place 频道必须具有合约账户写入权限), 如果启用了密钥的白名单,则您的出站 IP 地址必须在密钥的 IP 白名单中.
 
#登录请求
客户端 API 请求
 
payload参数:
 
名称    类型    必选    描述
req_id    string    是    请求 id,将由服务器发回,以帮助您识别服务器响应哪个请求,
它与外部的id不同
api_key    string    是    Apiv4 key
req_header    object    是    Apiv4 自定义 header
signature    string    是    Apiv4 签名
timestamp    string    是    Unix 时间戳(以秒为单位)
WebSocket api 操作认证使用与 Gate APIv4 API 相同的签名计算方法,即 HexEncode(HMAC_SHA512(secret,signature_string)),但有以下区别:
 
签名字符串拼接方式:<event>\n<channel>\n<req_param>\n<timestamp>, 其中<event>、<channel>、<req_param>、<timestamp>是对应的请求信息
login频道中的 req_param始终为空字符串
身份验证信息在请求正文中的payload字段中发送。
代码示例
 
import hmac
import hashlib
import json
import time
import websocket
import ssl
 
def get_api_signature(secret, channel, request_param, ts):
    key = f"api\n{channel}\n{request_param}\n{ts}"
    hash_object = hmac.new(secret.encode(), key.encode(), hashlib.sha512)
    return hash_object.hexdigest()
 
class ApiPayload:
    def __init__(self, api_key, signature, timestamp, req_id, request_param):
        self.api_key = api_key
        self.signature = signature
        self.timestamp = timestamp
        self.req_id = req_id
        self.request_param = request_param
 
class ApiRequest:
    def __init__(self, ts, channel, event, payload):
        self.time = ts
        self.channel = channel
        self.event = event
        self.payload = payload
 
def main():
    api_key = "YOUR_API_KEY"
    secret = "YOUR_API_SECRET"
    request_param = ""
    channel = "futures.login"
    ts = int(time.time())
    request_id = f"{int(time.time() * 1000)}-1"
 
    payload = ApiPayload(
        api_key=api_key,
        signature=get_api_signature(secret, channel, request_param, ts),
        timestamp=str(ts),
        req_id=request_id,
        request_param=request_param
    )
 
    req = ApiRequest(ts=ts, channel=channel, event="api", payload=payload)
 
    print(get_api_signature(secret, channel, request_param, ts))
 
    req_json = json.dumps(req, default=lambda o: o.__dict__)
    print(req_json)
 
    # Connect to WebSocket
    ws_url = "wss://fx-ws.gateio.ws/v4/ws/usdt"  # Replace with your WebSocket URL
    websocket.enableTrace(False)
    ws = websocket.create_connection(ws_url, sslopt={"cert_reqs": ssl.CERT_NONE})
 
    # Function to receive messages
    def recv_messages():
        while True:
            try:
                message = ws.recv()
                print(f"recv: {message}")
            except Exception as e:
                print(f"Error receiving message: {e}")
                ws.close()
                break
 
    # Start receiving messages in a separate thread
    import threading
    receive_thread = threading.Thread(target=recv_messages)
    receive_thread.start()
 
    # Send the request
    ws.send(req_json)
 
    # Keep the main thread running
    receive_thread.join()
 
if __name__ == "__main__":
    main()
Copy
请求示例
 
{
  "time": 1681984544,
  "channel": "futures.login",
  "event": "api",
  "payload": {
    "api_key": "ea83fad2604399da16bf97e6eea772a6",
    "signature": "6fa3824c8141f2b2283108558ec50966d7caf749bf04a3b604652325b50b47d2343d569d848373d58e65c49d9622ba2e73dc25797abef11c9f20c07da741591e",
    "timestamp": "1681984544",
    "req_id": "request-1"
  }
}
Copy
#登录响应
响应参数:
 
名称    类型    描述
request_id    String    对应的请求 ID
header    Map    响应元信息
»response_time    String    响应发送时间(毫秒)
»channel    String    请求频道
»event    String    请求event
»client_id    String    唯一的客户端 ID
»x_in_time    Integer    ws 接收请求的时间(以微秒为单位)
»x_out_time    Integer    ws 返回响应的时间(以微秒为单位)
»conn_id    String    与客户端建立连接的链接Id(同一个连接的链接Id保持一致)
»conn_trace_id    String    与客户端建立连接的TraceId
»trace_id    String    执行下单操作的TraceId
data    Object    请求响应的数据
»result    Object    如果这是 ack 响应,则结果是请求的payload,否则结果是 api 的响应
»»api_key    String    登录成功的 apikey
»»uid    String    登录成功的用户 ID
»errs    Object    仅当请求失败时可用
»»label    String    错误类型
»»message    String    详细错误信息
登录响应示例
 
{
  "request_id": "request-1",
  "header": {
    "response_time": "1681985856666",
    "status": "200",
    "channel": "futures.login",
    "event": "api",
    "clientId": "",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d"
  },
  "data": {
    "result": {
      "api_key": "ea83fad2604399da16bf97e6eea772a6",
      "uid": "110284739"
    }
  }
}
Copy
#下单
futures.order_place
 
您可以通过此频道进行下单操作.
 
本频道和以下的 APIV4 功能相同:
 
POST /futures/{
  settle
}/orders
#下单请求
payload参数:
 
名称    类型    必选    描述
req_id    string    是    请求 id,服务器会发回,帮助你识别服务器响应的是哪个请求,
它与外部的id不同
req_param    object    是    使用 api 下单参数; api 下单参数详细信息api(opens new window)
req_header    object    否    Apiv4 自定义请求头
req_param API 订单模型的 JSON 字节数据:
 
字段    类型    必选    描述
contract    string    是    合约
size    int64    是    订单大小。指定正数进行出价,指定负数进行询问
iceberg    string    否    冰山订单的显示尺寸。0 表示非冰山。请注意,您需要支付隐藏尺寸的接受者费用
price    string    否    订单价格。0 表示市价订单,tif设置为ioc
close    bool    否    设置为true平仓,size设置为 0
reduce_only    bool    否    设置为true仅减少订单
tif    string    否    有效时间
text    string    否    用户定义的信息。如果不为空,则必须遵循以下规则:
auto_size    string    否    将侧面设置为关闭双模式位置。close_long闭合长边;而close_short短的。注意size还需要设置为 0
stp_act    string    否    自我交易预防行动。用户可以通过该字段设置自助交易防范策略
market_order_slip_ratio    string    否    该笔市价单的预设的最大滑点比率(不代表实际的滑点),0.03代表3%的最大滑点
req_header 自定义 header 数据:
 
字段    类型    必选    描述
x-gate-exptime    string    否    指定过期的时间戳(毫秒)。如果 ws 收到请求的时间大于过期时间,请求将被拒绝
#详细描述
tif: 有效时间
 
gtc:取消前有效
ioc: ImmediateOrCancelled, 仅接受者
poc:PendingOrCancelled,仅发布订单,始终享受挂单费用
fok:FillOrKill,完全填充或不填充
text: 订单自定义信息,用户可以用该字段设置自定义 ID,用户自定义字段必须满足以下条件:
 
必须以 t- 开头
不计算 t- ,长度不能超过 28 字节
输入内容只能包含数字、字母、下划线(_)、中划线(-) 或者点(.)
不填,默认 apiv4-ws,来自 ws
web:来自网络
api:来自 API
app:来自手机
auto_deleveraging:来自 ADL
liquidation:来自清算
insurance:来自保险
stp_act:自我交易预防行动。用户可以通过该字段设置自助交易防范策略 用户加入后STP Group,他可以通过stp_act限制用户的自我交易防范策略。如果stp_act不通过则默认为cn策略。 当用户没有加入时STP group,传递参数时会返回错误stp_act。 如果用户下单时没有使用stp_act,stp_act将返回-
 
cn:取消最新订单,取消新订单并保留旧订单
co:取消最旧的订单,取消旧订单并保留新订单
cb:取消两者,新旧订单都会被取消
代码示例:请求前要先登录
 
import time
import json
 
# pip install websocket_client
from websocket import create_connection
 
api_order = {
      "contract": "BTC_USDT",
      "size": 10,
      "price": "31503.280000",
      "tif": "gtc",
      "text": "t-my-custom-id"
    }
 
ws = create_connection("wss://fx-ws.gateio.ws/v4/ws/usdt")
ws.send(json.dumps(
    {"time": int(time.time()),
    "channel": "futures.order_place",
    "event": "api",
    "payload": {
        "req_id": "1ewq-3123w-5",
        "req_param": api_order
    }}
))
 
print(ws.recv())
Copy
请求示例
 
{
  "time": 1681195484,
  "channel": "futures.order_place",
  "event": "api",
  "payload": {
    "req_id": "request-id-1",
    "req_param": {
      "contract": "BTC_USDT",
      "size": "10",
      "price": "31503.280000",
      "tif": "gtc",
      "text": "t-my-custom-id"
    }
  }
}
Copy
#订单请求回声消息
订单确认回声通知示例
 
{
  "request_id": "request-id-1",
  "ack": true,
  "header": {
    "response_time": "1681195484268",
    "status": "200",
    "channel": "futures.order_place",
    "event": "api",
    "client_id": "::1-0x140001a2600",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d",
    "x_gate_ratelimit_requests_remain": 99,
    "x_gate_ratelimit_limit": 100,
    "x_gat_ratelimit_reset_timestamp": 1736408263764
  },
  "data": {
    "result": {
      "req_id": "request-id-1",
      "req_header": null,
      "req_param": {
        "contract": "BTC_USDT",
        "size": "10",
        "price": "31503.280000",
        "tif": "gtc",
        "text": "t-my-custom-id"
      }
    }
  }
}
Copy
#下单结果通知
下单时返回订单信息 响应参数:
 
名称    类型    描述
request_id    String    对应的请求 ID
ack    Bool    "ack"消息的返回表示 WebSocket 的确认消息(目前在下单接口中存在)。
如果ack为 false(false 该字段不会出现在响应中),则说明该消息是响应消息,可以判断请求是否成功<br / >通过检查data.errs。
header    Map    响应元信息
»response_time    String    响应发送时间(毫秒)
»channel    String    请求频道
»event    String    请求event
»client_id    String    唯一的客户端 ID
»x_in_time    Integer    ws 接收请求的时间(以微秒为单位)
»x_out_time    Integer    ws 返回响应的时间(以微秒为单位)
»conn_trace_id    String    与客户端建立连接的TraceId
»trace_id    String    执行下单操作的TraceId
»x_gate_ratelimit_requests_remain    Integer    当前时间窗口剩余可用请求数(为0不展示)
»x_gate_ratelimit_limit    Integer    当前频率限制上限(为0不展示)
»x_gat_ratelimit_reset_timestamp    Integer    已超过当前窗口频率限制,表示下个可用时间窗口的时间戳(毫秒),即什么时候可以恢复访问;未超过当前窗口频率限制,表示返回的是当前服务器时间(毫秒)
»conn_id    String    与客户端建立连接的链接Id(同一个连接的链接Id保持一致)
data    Object    请求响应的数据
»result    Object    如果这是 ack 响应,则结果是请求的payload,否则结果是 api 的响应
»errs    Object    仅当请求失败时可用
»»label    String    错误类型
»»message    String    详细错误信息
响应返回示例
 
{
  "request_id": "request-id-1",
  "ack": false,
  "header": {
    "response_time": "1681195484360",
    "status": "200",
    "channel": "futures.order_place",
    "event": "api",
    "client_id": "::1-0x140001a2600",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d",
    "x_gate_ratelimit_requests_remain": 99,
    "x_gate_ratelimit_limit": 100,
    "x_gat_ratelimit_reset_timestamp": 1736408263764
  },
  "data": {
    "result": {
      "id": 74046514,
      "user": 6790020,
      "create_time": 1681195484.462,
      "finish_time": 1681195484.462,
      "finish_as": "filled",
      "status": "finished",
      "contract": "BTC_USDT",
      "size": "10",
      "price": "31503.3",
      "tif": "gtc",
      "fill_price": "31500",
      "text": "t-my-custom-id",
      "tkfr": "0.0003",
      "mkfr": "0",
      "stp_id": 2,
      "stp_act": "cn",
      "amend_text": "-"
    }
  }
}
Copy
#批量下单
futures.order_batch_place
 
您可以通过该频道批量下单
 
本频道和以下的 APIV4 功能相同:
 
POST /futures/{
  settle
}/batch_orders
#批量下单请求
payload 参数:
 
名称    类型    必选    描述
req_id    string    是    请求 id,服务器会发回,帮助你识别服务器响应的是哪个请求,
它与外部的id不同
req_param    object    是    参考 api 批量下单的请求数组; api 批量下单详情api(opens new window)
req_header    object    否    Apiv4 自定义 header
req_param API 订单模型的 JSON 字节数据可以参考单个下单,是多个单个下单数组,详情参考下单
 
req_header 自定义 header 数据:
 
字段    类型    必选    描述
x-gate-exptime    string    否    指定过期的时间戳(毫秒)。如果 ws 收到请求的时间大于过期时间,请求将被拒绝
代码示例:请求前要先登录
 
import time
import json
 
# pip install websocket_client
from websocket import create_connection
 
api_order=[
      {
        "contract": "BTC_USDT",
        "size": 10,
        "price": "31403.180000",
        "tif": "gtc",
        "text": "t-my-custom-id"
      }
    ]
 
ws = create_connection("wss://fx-ws.gateio.ws/v4/ws/usdt")
ws.send(json.dumps({
    "time": int(time.time()),
    "channel": "futures.order_batch_place",
    "event": "api",
    "payload": {
        "header":{
            "x-gate-channel-id":"xxxx",
        },
        "req_id": "1ewq-3123w-5",
        "req_param": api_order
    }
}))
 
print(ws.recv())
Copy
请求示例
 
{
  "time": 1681196536,
  "channel": "futures.order_batch_place",
  "event": "api",
  "payload": {
    "req_id": "request-id-6",
    "req_param": [
      {
        "contract": "BTC_USDT",
        "size": "10",
        "price": "31403.180000",
        "tif": "gtc",
        "text": "t-my-custom-id"
      }
    ]
  }
}
Copy
#批量下单确认通知
确认通知示例
 
{
  "request_id": "request-id-6",
  "ack": true,
  "header": {
    "response_time": "1681196536283",
    "status": "200",
    "channel": "futures.order_batch_place",
    "event": "api",
    "client_id": "::1-0x14002cfa0c0",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d",
    "x_gate_ratelimit_requests_remain": 99,
    "x_gate_ratelimit_limit": 100,
    "x_gat_ratelimit_reset_timestamp": 1736408263764
  },
  "data": {
    "result": {
      "req_id": "request-id-6",
      "req_header": null,
      "req_param": [
        {
          "contract": "BTC_USDT",
          "size": "10",
          "price": "31403.180000",
          "tif": "gtc",
          "text": "t-my-custom-id"
        }
      ]
    }
  }
}
Copy
#批量下单结果通知
批量下单订单信息返回
 
响应参数:
 
名称    类型    描述
request_id    String    对应的请求 ID
ack    Bool    "ack"消息的返回表示 WebSocket 的确认消息(目前在下单接口中存在)。
如果ack为 false(false 该字段不会出现在响应中),则说明该消息是响应消息,可以判断请求是否成功<br / >通过检查data.errs。
header    Map    响应元信息
»response_time    String    响应发送时间(毫秒)
»channel    String    请求频道
»event    String    请求event
»client_id    String    唯一的客户端 ID
»x_in_time    Integer    ws 接收请求的时间(以微秒为单位)
»x_out_time    Integer    ws 返回响应的时间(以微秒为单位)
»conn_id    String    与客户端建立连接的链接Id(同一个连接的链接Id保持一致)
»conn_trace_id    String    与客户端建立连接的TraceId
»trace_id    String    执行下单操作的TraceId
»x_gate_ratelimit_requests_remain    Integer    当前时间窗口剩余可用请求数(为0不展示)
»x_gate_ratelimit_limit    Integer    当前频率限制上限(为0不展示)
»x_gat_ratelimit_reset_timestamp    Integer    已超过当前窗口频率限制,表示下个可用时间窗口的时间戳(毫秒),即什么时候可以恢复访问;未超过当前窗口频率限制,表示返回的是当前服务器时间(毫秒)
data    Object    请求响应的数据
»result    Object    如果这是 ack 响应,则结果是请求的payload,否则结果是 api 的响应
»errs    Object    仅当请求失败时可用
»»label    String    错误类型
»»message    String    详细错误信息
响应返回示例
 
{
  "request_id": "request-id-6",
  "ack": false,
  "header": {
    "response_time": "1681196536532",
    "status": "200",
    "channel": "futures.order_batch_place",
    "event": "api",
    "client_id": "::1-0x14002cfa0c0",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d",
    "x_gate_ratelimit_requests_remain": 99,
    "x_gate_ratelimit_limit": 100,
    "x_gat_ratelimit_reset_timestamp": 1736408263764
  },
  "data": {
    "result": [
      {
        "succeeded": true,
        "id": 74046545,
        "user": 6790020,
        "create_time": 1681196536.592,
        "status": "open",
        "contract": "BTC_USDT",
        "size": "10",
        "price": "31403.2",
        "tif": "gtc",
        "left": "10",
        "fill_price": "0",
        "text": "t-my-custom-id",
        "tkfr": "0.0003",
        "mkfr": "0"
      }
    ]
  }
}
Copy
#订单取消
futures.order_cancel
 
您可以通过此频道取消订单
 
本频道和以下的 APIV4 功能相同:
 
DELETE /futures/{
  settle
}/orders/{
  order_id
}
#订单取消请求
payload 参数:
 
名称    类型    必选    描述
req_id    string    是    请求 id,服务器会发回,帮助你识别服务器响应的是哪个请求,
它与外部的id不同
req_param    object    是    API 取消订单,详情至api(opens new window)
req_header    object    否    Apiv4 自定义请求头
req_param API 订单模型的 JSON 字节数据:
 
字段    类型    必选    描述
order_id    string    是    成功创建订单时返回的订单 ID 或者用户创建时指定的自定义 ID(即text 字段)。
req_header 自定义 header 数据:
 
字段    类型    必选    描述
x-gate-exptime    string    否    指定过期的时间戳(毫秒)。如果 ws 收到请求的时间大于过期时间,请求将被拒绝
代码示例:请求前要先登录
 
import time
import json
 
# pip install websocket_client
from websocket import create_connection
 
ws = create_connection("wss://fx-ws.gateio.ws/v4/ws/usdt")
api_cancel_order = {
      "order_id": "74046514"
    }
ws.send(json.dumps({
    "time": int(time.time()),
    "channel": "futures.order_cancel",
    "event": "api",
    "payload": {
        "req_id": "1ewq-3123w-5",
        "req_param": api_cancel_order
    }
}))
 
print(ws.recv())
Copy
订单取消请求示例
 
{
  "time": 1681195485,
  "channel": "futures.order_cancel",
  "event": "api",
  "payload": {
    "req_id": "request-id-5",
    "req_param": {
      "order_id": "74046514"
    }
  }
}
Copy
#订单取消通知
响应参数:
 
名称    类型    描述
request_id    String    对应的请求 ID
header    Map    响应元信息
»response_time    String    响应发送时间(毫秒)
»channel    String    请求频道
»event    String    请求event
»client_id    String    唯一的客户端 ID
»x_in_time    Integer    ws 接收请求的时间(以微秒为单位)
»x_out_time    Integer    ws 返回响应的时间(以微秒为单位)
»conn_id    String    与客户端建立连接的链接Id(同一个连接的链接Id保持一致)
»conn_trace_id    String    与客户端建立连接的TraceId
»trace_id    String    执行下单操作的TraceId
»x_gate_ratelimit_requests_remain    Integer    当前时间窗口剩余可用请求数(为0不展示)
»x_gate_ratelimit_limit    Integer    当前频率限制上限(为0不展示)
»x_gat_ratelimit_reset_timestamp    Integer    已超过当前窗口频率限制,表示下个可用时间窗口的时间戳(毫秒),即什么时候可以恢复访问;未超过当前窗口频率限制,表示返回的是当前服务器时间(毫秒)
data    Object    请求响应的数据
»result    Object    订单取消参数,详情至api(opens new window)
»errs    Object    仅当请求失败时可用
»»label    String    错误类型
»»message    String    详细错误信息
订单取消返回示例
 
{
  "request_id": "request-id-5",
  "header": {
    "response_time": "1681196536282",
    "status": "200",
    "channel": "futures.order_cancel",
    "event": "api",
    "client_id": "::1-0x14002cfa0c0",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d",
    "x_gate_ratelimit_requests_remain": 99,
    "x_gate_ratelimit_limit": 100,
    "x_gat_ratelimit_reset_timestamp": 1736408263764
  },
  "data": {
    "result": {
      "id": 74046543,
      "user": 6790020,
      "create_time": 1681196535.01,
      "finish_time": 1681196536.343,
      "finish_as": "cancelled",
      "status": "finished",
      "contract": "BTC_USDT",
      "size": "10",
      "price": "31303.2",
      "tif": "gtc",
      "left": "10",
      "fill_price": "0",
      "text": "t-my-custom-id",
      "tkfr": "0.0003",
      "mkfr": "0",
      "stp_id": 2,
      "stp_act": "cn",
      "amend_text": "-"
    }
  }
}
Copy
#取消所有 ID 列表内的订单
您可以使用此频道futures.order_cancel_ids取消所有 ID 列表内的订单。
 
可以指定多个不同的订单id。一次请求最多只能撤销 20 条记录
 
以下是 API 的功能:
 
POST /futures/{settle}/batch_cancel_orders
#取消所有 ID 列表内的订单请求
Payload 格式:
 
字段    类型    必选    描述
req_id    string    是    服务器将发送回的请求 ID,用于帮助您识别服务器响应的是哪个请求,它与外部的 id 不同。
req_param    array    是    订单 ID 列表
req_header    object    否    apiv4 自定义 header
req_header 自定义 header 数据:
 
字段    类型    必选    描述
x-gate-exptime    string    否    指定过期的时间戳(毫秒)。如果 ws 收到请求的时间大于过期时间,请求将被拒绝
代码示例:请求前要先登录
 
#!/usr/bin/python
 
import time
import json
# pip install websocket_client
from websocket import create_connection
 
ws = create_connection("wss://fx-ws.gateio.ws/v4/ws/usdt")
cancelWithIdsParam = ["1694883366","123"]
ws.send(json.dumps({
    "time":int(time.time()),
    "channel":"futures.order_cancel_ids",
    "event":"api",
    "payload":{
        "req_id":"test_1",
        "req_param": cancelWithIdsParam
    }
}))
 
print(ws.recv())
Copy
客户端请求示例
 
{
  "time": 1681986208,
  "channel": "futures.order_cancel_ids",
  "event": "api",
  "payload": {
    "req_id": "request-9",
    "req_param": [
      "1700664343",
      "123"
    ]
  }
}
Copy
#取消所有 ID 列表内的订单推送
推送格式:
 
字段    类型    描述
request_id    String    消息的唯一标识符
header    Map    响应的元信息
»response_time    String    响应发送时间(以毫秒为单位)
»channel    String    请求的频道
»event    String    请求事件
»client_id    String    唯一客户端标识 ID
»x_in_time    Integer    ws 接收请求的时间(以微秒为单位)
»x_out_time    Integer    ws 返回响应的时间(以微秒为单位)
»conn_id    String    与客户端建立连接的链接Id(同一个连接的链接Id保持一致)
»conn_trace_id    String    与客户端建立连接的TraceId
»trace_id    String    执行下单操作的TraceId
data    Object    请求响应的数据
»result    Object    响应详见api(opens new window)
»errs    Object    只有在请求失败时才可用
»»label    String    以字符串格式表示错误类型
»»message    String    错误信息详情
取消订单推送示例
 
{
  "request_id": "request-9",
  "header": {
    "response_time": "1681986208564",
    "status": "200",
    "channel": "futures.order_cancel_ids",
    "event": "api",
    "client_id": "::1-0x140001623c0",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d"
  },
  "data": {
    "result": [
      {
        "id": "1694883366",
        "user_id": 111,
        "succeeded": true
      },
      {
        "id": "123",
        "user_id": 111,
        "message": "ORDER_NOT_FOUND"
      }
    ]
  }
}
Copy
#取消匹配的未结束订单
futures.order_cancel_cp
 
您可以通过此渠道取消所有匹配的未结束的订单
 
本频道和以下的 APIV4 功能相同:
 
DELETE /futures/{
  settle
}/orders
#请求
payload 参数:
 
名称    类型    必选    描述
req_id    string    是    请求 id,服务器会发回,帮助你识别服务器响应的是哪个请求,
它与外部的id不同
req_param    object    是    详情至api(opens new window)
req_header    object    否    Apiv4 自定义请求头
req_param API 订单模型的 JSON 字节数据:
 
字段    类型    必选    描述
contract    string    是    合约
side    string    否    所有出价或要价。如果没有特别说明,两者都包括在内。
req_header 自定义 header 数据:
 
字段    类型    必选    描述
x-gate-exptime    string    否    指定过期的时间戳(毫秒)。如果 ws 收到请求的时间大于过期时间,请求将被拒绝
代码示例:请求前要先登录
 
import time
import json
 
# pip install websocket_client
from websocket import create_connection
 
ws = create_connection("wss://fx-ws.gateio.ws/v4/ws/usdt")
api_cancel_all_order = {
      "contract": "BTC_USDT",
      "side": "bid"
    }
ws.send(json.dumps({
    "time": int(time.time()),
    "channel": "futures.order_cancel_cp",
    "event": "api",
    "payload": {
        "req_id": "1ewq-3123w-5",
        "req_param": api_cancel_all_order
    }
}))
 
print(ws.recv())
Copy
客户请求示例
 
{
  "time": 1681196537,
  "channel": "futures.order_cancel_cp",
  "event": "api",
  "payload": {
    "req_id": "request-id-7",
    "req_param": {
      "contract": "BTC_USDT",
      "side": "bid"
    }
  }
}
Copy
#响应结果
响应参数:
 
名称    类型    描述
request_id    String    对应的请求 ID
header    Map    响应元信息
»response_time    String    响应发送时间(毫秒)
»channel    String    请求频道
»event    String    请求event
»client_id    String    唯一的客户端 ID
»x_in_time    Integer    ws 接收请求的时间(以微秒为单位)
»x_out_time    Integer    ws 返回响应的时间(以微秒为单位)
»conn_id    String    与客户端建立连接的链接Id(同一个连接的链接Id保持一致)
»conn_trace_id    String    与客户端建立连接的TraceId
»trace_id    String    执行下单操作的TraceId
»x_gate_ratelimit_requests_remain    Integer    当前时间窗口剩余可用请求数(为0不展示)
»x_gate_ratelimit_limit    Integer    当前频率限制上限(为0不展示)
»x_gat_ratelimit_reset_timestamp    Integer    已超过当前窗口频率限制,表示下个可用时间窗口的时间戳(毫秒),即什么时候可以恢复访问;未超过当前窗口频率限制,表示返回的是当前服务器时间(毫秒)
data    Object    请求响应的数据
»result    Object    详情至api(opens new window)
»errs    Object    仅当请求失败时可用
»»label    String    错误类型
»»message    String    详细错误信息
订单取消返回示例
 
{
  "request_id": "request-id-7",
  "header": {
    "response_time": "1681196537567",
    "status": "200",
    "channel": "futures.order_cancel_cp",
    "event": "api",
    "client_id": "::1-0x14002cfa0c0",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d",
    "x_gate_ratelimit_requests_remain": 99,
    "x_gate_ratelimit_limit": 100,
    "x_gat_ratelimit_reset_timestamp": 1736408263764
  },
  "data": {
    "result": [
      {
        "id": 74046545,
        "user": 6790020,
        "create_time": 1681196536.592,
        "finish_time": 1681196537.626,
        "finish_as": "cancelled",
        "status": "finished",
        "contract": "BTC_USDT",
        "size": "10",
        "price": "31403.2",
        "tif": "gtc",
        "left": "10",
        "fill_price": "0",
        "text": "t-my-custom-id",
        "tkfr": "0.0003",
        "mkfr": "0",
        "stp_id": 2,
        "stp_act": "cn",
        "amend_text": "-"
      }
    ]
  }
}
Copy
#修改订单
futures.order_amend
 
您可以通过此频道修改未结束的订单
 
本频道和以下的 APIV4 功能相同:
 
PUT /futures/{settle}/orders/{order_id}
#请求
payload 参数:
 
名称    类型    必选    描述
req_id    string    是    请求 id,服务器会发回,帮助你识别服务器响应的是哪个请求,
它与外部的id不同
req_param    object    是    API 修改订单参数,详情至api(opens new window)
req_header    object    否    Apiv4 自定义请求头
req_param API 订单模型的 JSON 字节数据:
 
字段    类型    必选    描述
order_id    string    是    成功创建订单时返回的订单 ID 或者用户创建时指定的自定义 ID(即text 字段)。
size    int64    否    必选。交易数量,正数为买入,负数为卖出。平仓委托则设置为 0。
price    string    否    价格
amend_text    int64    否    修改订单时的自定义信息
req_header 自定义 header 数据:
 
字段    类型    必选    描述
x-gate-exptime    string    否    指定过期的时间戳(毫秒)。如果 ws 收到请求的时间大于过期时间,请求将被拒绝
#详细描述
=> size: 新订单尺寸,包括已填充部分。
 
如果新尺寸小于或等于已填充尺寸,订单将被取消。
订单面必须与原始面相同。
平仓订单大小无法更改。
对于仅减少订单,增加尺寸可能会导致其他仅减少订单被取消。
如果价格不变,减少数量不会改变其在订单簿中的优先级,而增加数量则会以当前价格将其移至最后。
代码示例:请求前要先登录
 
import time
import json
 
# pip install websocket_client
from websocket import create_connection
 
ws = create_connection("wss://fx-ws.gateio.ws/v4/ws/usdt")
api_amend_order = {
      "order_id": "74046543",
      "price": "31303.180000"
    }
ws.send(json.dumps({
    "time": int(time.time()),
    "channel": "futures.order_amend",
    "event": "api",
    "payload": {
        "req_id": "1ewq-3123w-5",
        "req_param": api_amend_order
    }
}))
 
print(ws.recv())
Copy
客户请求示例
 
{
  "time": 1681196536,
  "channel": "futures.order_amend",
  "event": "api",
  "payload": {
    "req_id": "request-id-4",
    "req_param": {
      "order_id": "74046543",
      "price": "31303.180000"
    }
  }
}
Copy
#响应结果
响应参数:
 
名称    类型    描述
request_id    String    对应的请求 ID
header    Map    响应元信息
»response_time    String    响应发送时间(毫秒)
»channel    String    请求频道
»event    String    请求event
»client_id    String    唯一的客户端 ID
»x_in_time    Integer    ws 接收请求的时间(以微秒为单位)
»x_out_time    Integer    ws 返回响应的时间(以微秒为单位)
»conn_id    String    与客户端建立连接的链接Id(同一个连接的链接Id保持一致)
»conn_trace_id    String    与客户端建立连接的TraceId
»trace_id    String    执行下单操作的TraceId
»x_gate_ratelimit_requests_remain    Integer    当前时间窗口剩余可用请求数(为0不展示)
»x_gate_ratelimit_limit    Integer    当前频率限制上限(为0不展示)
»x_gat_ratelimit_reset_timestamp    Integer    已超过当前窗口频率限制,表示下个可用时间窗口的时间戳(毫秒),即什么时候可以恢复访问;未超过当前窗口频率限制,表示返回的是当前服务器时间(毫秒)
data    Object    请求响应的数据
»result    Object    详情至api(opens new window)
»errs    Object    仅当请求失败时可用
»»label    String    错误类型
»»message    String    详细错误信息
订单修改返回示例
 
{
  "request_id": "request-id-4",
  "header": {
    "response_time": "1681196536251",
    "status": "200",
    "channel": "futures.order_amend",
    "event": "api",
    "client_id": "::1-0x14002cfa0c0",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d",
    "x_gate_ratelimit_requests_remain": 99,
    "x_gate_ratelimit_limit": 100,
    "x_gat_ratelimit_reset_timestamp": 1736408263764
  },
  "data": {
    "result": {
      "id": 74046543,
      "user": 6790020,
      "create_time": 1681196535.01,
      "status": "open",
      "contract": "BTC_USDT",
      "size": "10",
      "price": "31303.2",
      "tif": "gtc",
      "left": "10",
      "fill_price": "0",
      "text": "t-my-custom-id",
      "tkfr": "0.0003",
      "mkfr": "0",
      "stp_id": 2,
      "stp_act": "cn",
      "amend_text": "-"
    }
  }
}
Copy
#获取订单列表
futures.order_list
 
您可以通过此频道获取订单列表
 
本频道和以下的 APIV4 功能相同:
 
GET /futures/{settle}/orders
#订单列表请求
payload 参数:
 
名称    类型    必选    描述
req_id    string    是    请求 id,服务器会发回,帮助你识别服务器响应的是哪个请求,
它与外部的id不同
req_param    object    是    API 请求订单列表参数,详情至api(opens new window)
req_param API 订单模型的 JSON 字节数据:
 
字段    类型    必选    描述
contract    string    否    合约标识,如果指定则只返回该合约相关数据
status    string    是    只列出具有此状态的订单
limit    int    否    单个列表中返回的最大记录数
offset    int    否    列表偏移量,从 0 开始
last_id    string    否    使用先前列表查询结果中最后一条记录的id 指定列表起始点
代码示例:请求前要先登录
 
import time
import json
 
# pip install websocket_client
from websocket import create_connection
 
ws = create_connection("wss://fx-ws.gateio.ws/v4/ws/usdt")
api_list_order = {
      "contract": "BTC_USDT",
      "status": "open"
    }
ws.send(json.dumps({
    "time": int(time.time()),
    "channel": "futures.order_list",
    "event": "api",
    "payload": {
        "req_id": "1ewq-3123w-5",
        "req_param": api_list_order
    }
}
))
 
print(ws.recv())
Copy
客户请求示例
 
{
  "time": 1681196535,
  "channel": "futures.order_list",
  "event": "api",
  "payload": {
    "req_id": "request-id-3",
    "req_param": {
      "contract": "BTC_USDT",
      "status": "open"
    }
  }
}
Copy
#订单列表响应
响应参数:
 
名称    类型    描述
request_id    String    对应的请求 ID
header    Map    响应元信息
»response_time    String    响应发送时间(毫秒)
»channel    String    请求频道
»event    String    请求event
»client_id    String    唯一的客户端 ID
»x_in_time    Integer    ws 接收请求的时间(以微秒为单位)
»x_out_time    Integer    ws 返回响应的时间(以微秒为单位)
»conn_id    String    与客户端建立连接的链接Id(同一个连接的链接Id保持一致)
»conn_trace_id    String    与客户端建立连接的TraceId
»trace_id    String    执行下单操作的TraceId
data    Object    请求响应的数据
»result    Object    详情至api(opens new window)
»errs    Object    仅当请求失败时可用
»»label    String    错误类型
»»message    String    详细错误信息
订单列表返回示例
 
{
  "request_id": "request-id-3",
  "header": {
    "response_time": "1681196536017",
    "status": "200",
    "channel": "futures.order_list",
    "event": "api",
    "client_id": "::1-0x14002cfa0c0",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d"
  },
  "data": {
    "result": [
      {
        "id": 74046543,
        "user": 6790020,
        "create_time": 1681196535.01,
        "finish_time": 1681196535.01,
        "update_time": 1681196535.01,
        "finish_as": "filled",
        "status": "open",
        "contract": "BTC_USDT",
        "size": "10",
        "price": "31403.2",
        "tif": "gtc",
        "left": "10",
        "fill_price": "0",
        "text": "t-my-custom-id",
        "tkfr": "0.0003",
        "mkfr": "0",
        "stp_id": 2,
        "stp_act": "cn",
        "amend_text": "-"
      }
    ]
  }
}
Copy
#查询订单详情
futures.order_status
 
您可以通过该频道查询订单详情
 
本频道和以下的 APIV4 功能相同:
 
GET /futures/{settle}/orders/{order_id}
#订单详情请求
payload 参数:
 
名称    类型    必选    描述
req_id    string    是    请求 id,服务器会发回,帮助你识别服务器响应的是哪个请求,
它与外部的id不同
req_param    object    是    详情至api(opens new window)
req_param` API 订单模型的 JSON 字节数据:
 
字段    类型    必选    描述
order_id    string    是    成功创建订单时返回的订单 ID 或者用户创建时指定的自定义 ID(即text 字段)。
代码示例:请求前要先登录
 
import time
import json
 
# pip install websocket_client
from websocket import create_connection
 
ws = create_connection("wss://fx-ws.gateio.ws/v4/ws/usdt")
 
api_status_order = {
      "order_id": "74046543"
    }
 
ws.send(json.dumps({
    "time": int(time.time()),
    "channel": "futures.order_status",
    "event": "api",
    "payload": {
        "req_id": "1ewq-3123w-5",
        "req_param": api_status_order
    }
}))
 
print(ws.recv())
Copy
客户请求示例
 
{
  "time": 1681196535,
  "channel": "futures.order_status",
  "event": "api",
  "payload": {
    "req_id": "request-id-2",
    "req_param": {
      "order_id": "74046543"
    }
  }
}
Copy
#订单详情响应
响应参数:
 
名称    类型    描述
request_id    String    对应的请求 ID
header    Map    响应元信息
»response_time    String    响应发送时间(毫秒)
»channel    String    请求频道
»event    String    请求event
»client_id    String    唯一的客户端 ID
»x_in_time    Integer    ws 接收请求的时间(以微秒为单位)
»x_out_time    Integer    ws 返回响应的时间(以微秒为单位)
»conn_id    String    与客户端建立连接的链接Id(同一个连接的链接Id保持一致)
»conn_trace_id    String    与客户端建立连接的TraceId
»trace_id    String    执行下单操作的TraceId
data    Object    请求响应的数据
»result    Object    详情至api(opens new window)
»errs    Object    仅当请求失败时可用
»»label    String    错误类型
»»message    String    详细错误信息
订单详情返回示例
 
{
  "request_id": "request-id-2",
  "header": {
    "response_time": "1681196535985",
    "status": "200",
    "channel": "futures.order_status",
    "event": "api",
    "client_id": "::1-0x14002cfa0c0",
    "x_in_time": 1681985856667508,
    "x_out_time": 1681985856667598,
    "conn_id": "5e74253e9c793974",
    "conn_trace_id": "1bde5aaa0acf2f5f48edfd4392e1fa68",
    "trace_id": "e410abb5f74b4afc519e67920548838d"
  },
  "data": {
    "result": {
      "id": 74046543,
      "user": 6790020,
      "create_time": 1681196535.01,
      "status": "open",
      "contract": "BTC_USDT",
      "size": "10",
      "price": "31403.2",
      "tif": "gtc",
      "left": "10",
      "fill_price": "0",
      "text": "t-my-custom-id",
      "tkfr": "0.0003",
      "mkfr": "0",
      "stp_id": 2,
      "stp_act": "cn",
      "amend_text": "-"
    }
  }
}