-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathftnn_api_test.py
More file actions
executable file
·65 lines (54 loc) · 1.38 KB
/
ftnn_api_test.py
File metadata and controls
executable file
·65 lines (54 loc) · 1.38 KB
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
#!/usr/bin/python2.6
# -*- coding: utf-8 -*-
'''
Created on 2015年8月26日
@author: futu
'''
import socket
import json
import string
import sys
#futnn plubin会开启本地监听服务端
# 请求及发送数据都是jason格式, 具体详见插件的协议文档
host="localhost"
port=11111
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,port))
print "test quote price 00700"
print "-------------------------------------"
#发送报价请求
req = {'Protocol':'1001', 'ReqParam':{'Market':'1','StockCode':'00700'},'Version':'1'}
str = json.dumps(req) + "\n"
print str
s.send(str)
rsp = ""
while True:
buf = s.recv(1024)
rsp = rsp + buf
#找到"\n"就认为结束了
try:
rsp.index('\n')
break;
except Exception, e:
print "recving..."
print rsp
print "test trade buy 0700\n"
print "-------------------------------------"
#发送交易请求
req = {'Protocol':'6003','ReqParam':{'Cookie':'123456', 'EnvType':'0', 'OrderSide':'0','OrderType':'1','Price':'150','Qty':'22200','StockCode':'00700'},'Version':'1'}
str = json.dumps(req) + "\n"
print str
s.send(str)
rsp = ""
while True:
buf = s.recv(1024)
rsp = rsp + buf
#找到"\n"就认为结束了
try:
rsp.index('\n')
break;
except Exception, e:
print "recving..."
print rsp
print "-----------------over----------------"
s.close()