基于通用HTTP协议,任何语言可轻松接入。
Time is money. You just need to think quickly and try quickly.
#!/bin/sh
host_url='http://127.0.0.1:8888'
#获取账户信息
curl ${host_url}/account
#获取当前持仓
curl ${host_url}/position
#获取实时行情
curl ${host_url}/quote/SHFE.rb2301
#获取K线行情
curl ${host_url}/klines/SHFE.rb2301_60_20
#获取Tick序列
curl ${host_url}/ticks/SHFE.rb2301_20
#委托下单
curl -X POST -H "Content-type: application/json" -d '{"symbol":"SHFE.rb2301", "direction":"BUY","offset":"OPEN","volume":1,"limit_price":"UPPER_LIMIT"}' ${host_url}/order
#取消委托单
curl -X POST -H "Content-type: application/json" -d '{"order_id":"f1786bea1ad045199925deea3cd6f1c7"}' ${host_url}/order/cancel
#获取委托单信息
curl ${host_url}/order/fbcce9326a3a4f8c80295b0e6e07434a
#获取当日可撤委托
curl ${host_url}/order/alive
import requests
host_url = 'http://127.0.0.1:8888'
#获取账户信息
requests.get(host_url+'/account').json()
#获取当前持仓
requests.get(host_url+'/position').json()
#获取实时行情
requests.get(host_url+'/quote/SHFE.rb2301').json();
#获取K线行情
requests.get(host_url+'/klines/SHFE.rb2301_60_20').json()
#获取Tick序列
requests.get(host_url+'/ticks/SHFE.rb2301_20').json()
#委托下单
requests.post(host_url+'/order', json={
'symbol' : 'SHFE.rb2301',
'direction' : 'BUY',
'offset': 'OPEN',
'volume': 1,
'limit_price': 'UPPER_LIMIT'
}).json()
#取消委托单
requests.post(host_url+'/order/cancel', json={
'order_id' : 'fbcce9326a3a4f8c80295b0e6e07434a',
}).json()
#获取委托单信息
requests.get(host_url+'/order/fbcce9326a3a4f8c80295b0e6e07434a').json()
#获取当日可撤委托
requests.get(host_url+'/order/alive').json()
<?php
function my_curl($url, $method = 'GET', $data = ''){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if($method == 'POST'){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS , $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length:' . strlen($data)));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
$host_url = 'http://127.0.0.1:8888';
//获取账户信息
my_curl($host_url.'/account');
//获取当前持仓
my_curl($host_url.'/position');
//获取实时行情
my_curl($host_url.'/quote/SHFE.rb2301');
//获取K线行情
my_curl($host_url.'/klines/SHFE.rb2301_60_20');
//获取Tick序列
my_curl($host_url.'/ticks/SHFE.rb2301_20');
//委托下单
my_curl($host_url.'/order', 'POST', json_encode([
'symbol' => 'SHFE.rb2301',
'direction' => 'BUY',
'offset'=> 'OPEN',
'volume'=> 1,
'limit_price'=> 'UPPER_LIMIT'
]));
//取消委托
my_curl($host_url.'/order/cancel', 'POST', json_encode([
'order_id' => 'fbcce9326a3a4f8c80295b0e6e07434a',
]));
//获取委托单信息
my_curl($host_url.'/order/fbcce9326a3a4f8c80295b0e6e07434a');
//获取当日可撤委托
my_curl($host_url.'/order/alive');
var request = require('request');
//服务地址
var host_url='http://127.0.0.1:8888';
//获取账户信息
request(host_url+'/account', function (error, response, body){
console.log(body);
});
//获取当前持仓
request(host_url+'/position', function (error, response, body){
console.log(body);
});
//获取实时行情
request(host_url+'/quote/SHFE.rb2301', function (error, response, body){
console.log(body);
});
//获取K线行情
request(host_url+'/klines/SHFE.rb2301_60_20', function (error, response, body){
console.log(body);
});
//获取Tick序列
request(host_url+'/ticks/SHFE.rb2301_20', function (error, response, body){
console.log(body);
});
//委托下单
request.post(
{
url: host_url+'/order',
headers: {},
json: {"symbol":"SHFE.rb2301", "direction":"BUY","offset":"OPEN","volume":1,"limit_price":"UPPER_LIMIT"}
},
function(error, response, body) {
console.log(body);
}
);
//取消委托单
request.post(
{
url: host_url+'/order/cancel',
headers: {},
json: {"order_id":"fbcce9326a3a4f8c80295b0e6e07434a"}
},
function(error, response, body) {
console.log(body);
}
);
//获取委托单信息
request(host_url+'/order/fbcce9326a3a4f8c80295b0e6e07434a', function (error, response, body){
console.log(body);
});
//获取当日可撤委托
request(host_url+'/order/alive', function (error, response, body){
console.log(body);
});
package main
import (
"bytes"
"io/ioutil"
"fmt"
"net/http"
)
func httpGet(url string) (string) {
response, err := http.Get(url)
if err != nil {
panic(err)
}
defer response.Body.Close()
body, err2 := ioutil.ReadAll(response.Body)
if err2 != nil {
panic(err2)
}
return string(body)
}
func httpPost(url string, jsonStr string) (string) {
var json = []byte(jsonStr)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(json))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err2 := ioutil.ReadAll(resp.Body)
if err2 != nil {
panic(err2)
}
return string(body)
}
func main(){
//服务地址
var host_url = "http://127.0.0.1:8888";
//获取账户信息
fmt.Println(httpGet(host_url+"/account"))
//获取当前持仓
fmt.Println(httpGet(host_url+"/position"))
//获取实时行情
fmt.Println(httpGet(host_url+"/quote/SHFE.rb2301"))
//获取K线行情
fmt.Println(httpGet(host_url+"/klines/SHFE.rb2301_60_20"))
//获取Tick序列
fmt.Println(httpGet(host_url+"/ticks/SHFE.rb2301_20"))
//委托下单
fmt.Println(httpPost(host_url+"/order",`{"symbol":"SHFE.rb2301", "direction":"BUY","offset":"OPEN","volume":1,"limit_price":"UPPER_LIMIT"}`))
//取消委托单
fmt.Println(httpPost(host_url+"/order/cancel",`{"order_id":"fbcce9326a3a4f8c80295b0e6e07434a"}`))
//获取委托单信息
fmt.Println(httpGet(host_url+"/order/fbcce9326a3a4f8c80295b0e6e07434a"))
//获取当日可撤委托
fmt.Println(httpGet(host_url+"/order/alive"))
}
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class MyHttp {
public static void main(String[] args) throws Exception {
MyHttp myHttp = new MyHttp();
//服务地址
String hostUrl = "http://127.0.0.1:8888";
//获取账户信息
System.out.println(myHttp.sendGet(hostUrl+"/account"));
//获取当前持仓
System.out.println(myHttp.sendGet(hostUrl+"/position"));
//获取实时行情
System.out.println(myHttp.sendGet(hostUrl+"/quote/SHFE.rb2301"));
//获取K线行情
System.out.println(myHttp.sendGet(hostUrl+"/klines/SHFE.rb2301_60_20"));
//获取Tick序列
System.out.println(myHttp.sendGet(hostUrl+"/ticks/SHFE.rb2301_20"));
//委托下单
System.out.println(myHttp.sendPost(hostUrl+"/order","{\"symbol\":\"SHFE.rb2301\", \"direction\":\"BUY\",\"offset\":\"OPEN\",\"volume\":1,\"limit_price\":\"UPPER_LIMIT\"}"));
//取消委托单
System.out.println(myHttp.sendPost(hostUrl+"/order/cancel","{\"order_id\":\"fbcce9326a3a4f8c80295b0e6e07434a\"}"));
//获取委托单信息
System.out.println(myHttp.sendGet(hostUrl+"/order/fbcce9326a3a4f8c80295b0e6e07434a"));
//获取当日可撤委托
System.out.println(myHttp.sendGet(hostUrl+"/order/alive"));
}
private String sendGet(String url) throws Exception {
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
return response.toString();
}
private String sendPost(String url, String jsonStr) throws Exception {
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type","application/json");
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(jsonStr);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
return response.toString();
}
}