goctp

package module
v0.6.3-20211216 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2021 License: MIT Imports: 10 Imported by: 3

README

goctp

介绍

CTP 封装之 golang 版,支持 Windows Linux x64. 采用二次封装,将 C++封装成 C,并 export. win lnx 封装逻辑相同: trade.go quote.go

运行

环境变量
"tradeFront": "tcp://180.168.146.187:10130",
"quoteFront": "tcp://180.168.146.187:10131",
"loginInfo": "9999/008107/1/simnow_client_test/0000000000000000"
看穿式评测
# 替换接口库文件
cp CTPv6.3.19_20200423_cp/*.so lnx/
cp CTPv6.3.19_20200423_cp/*.dll win/
示例
package main

import (
	"encoding/json"
	"fmt"
	"os"
	"strings"
	"time"

	"gitee.com/haifengat/goctp"
	// ctp "gitee.com/haifengat/goctp/lnx" // linx
	ctp "gitee.com/haifengat/goctp/win"  // windows
)

var (
	investorID, password, brokerID, appID, authCode string
	tradeFront, quoteFront, loginInfo               string
)

var t = ctp.NewTrade()
var q = ctp.NewQuote()

func init() {
	tradeFront = os.Getenv("tradeFront")
	quoteFront = os.Getenv("quoteFront")
	loginInfo = os.Getenv("loginInfo")
	fs := strings.Split(loginInfo, "/")
	brokerID, investorID, password, appID, authCode = fs[0], fs[1], fs[2], fs[3], fs[4]
	fmt.Println("tradeFront: ", tradeFront)
	fmt.Println("quoteFront: ", quoteFront)
	fmt.Printf("brokerID:%s\ninvestorID:%s\npassword:%s\nappID:%s\nauthCode:%s\n", brokerID, investorID, password, appID, authCode)
}

func testQuote() {
	q.RegOnFrontConnected(func() {
		fmt.Println("quote connected")
		q.ReqLogin(investorID, password, brokerID)
	})
	q.RegOnRspUserLogin(func(login *goctp.RspUserLoginField, info *goctp.RspInfoField) {
		fmt.Println("quote login:", info)
	})
	q.RegOnTick(func(tick *goctp.TickField) {
		bs, _ := json.Marshal(tick)
		fmt.Println(string(bs))
	})
	fmt.Println("quote connecting " + quoteFront)
	q.ReqConnect(quoteFront)
}

func testTrade() {
	t.RegOnFrontConnected(func() {
		fmt.Println("trade connected")
		go t.ReqLogin(investorID, password, brokerID, appID, authCode)
	})
	t.RegOnRspUserLogin(func(login *goctp.RspUserLoginField, info *goctp.RspInfoField) {
		fmt.Println(info)
		bs, _ := json.Marshal(login)
		fmt.Println("login: ", string(bs))
	})

	t.RegOnRtnOrder(func(field *goctp.OrderField) {
		bs, _ := json.Marshal(field)
		fmt.Println("OnRtnOrder:", string(bs))
	})
	t.RegOnRtnCancel(func(field *goctp.OrderField) {
		bs, _ := json.Marshal(field)
		fmt.Println("OnRtnCancel: ", string(bs))
	})
	t.RegOnErrRtnOrder(func(field *goctp.OrderField, info *goctp.RspInfoField) {
		bs, _ := json.Marshal(info)
		fmt.Println("OnErrRtnOrder: ", string(bs))
	})
	// 交易状态
	t.RegOnRtnInstrumentStatus(func(field *goctp.InstrumentStatus) {
		// fmt.Println(field)
	})
	// 断开
	t.RegOnFrontDisConnected(func(reason int) {
		fmt.Println("disconntcted: ", reason)
	})
	fmt.Println("connecting to trade " + tradeFront)
	t.ReqConnect(tradeFront)
}

func main() {
	go testQuote()
	go testTrade()
	for !t.IsLogin {
		time.Sleep(1 * time.Second)
	}

	time.Sleep(3 * time.Second)
	// 委托测试
	if true {
		t.ReqOrderInsert("rb2205", goctp.DirectionBuy, goctp.OffsetFlagOpen, 4000, 1)
	}
	// 合约
	if true {
		cnt := 0
		t.Instruments.Range(func(k, v interface{}) bool {
			cnt++
			return true
		})
		fmt.Println("instrument count:", cnt)
	}
	// 权益
	if true {
		bs, _ := json.Marshal(t.Account)
		fmt.Println(string(bs))
	}
	// 委托信息
	if true {
		t.Orders.Range(func(key, value interface{}) bool {
			fmt.Printf("%s: %v\n", key, value)
			return true
		})
	}
	// 成交信息
	if true {
		t.Trades.Range(func(key, value interface{}) bool {
			fmt.Printf("%s: %v\n", key, value)
			return true
		})
	}
	// 持仓
	if true {
		t.Positions.Range(func(key, value interface{}) bool {
			p := value.(*goctp.PositionField)
			fmt.Printf("%s: %s: 昨:%d,今:%d,总: %d, 可: %d\n", key, p.InstrumentID, p.YdPosition, p.TodayPosition, p.Position, p.Position-p.ShortFrozen)
			return true
		})
		time.Sleep(500 * time.Millisecond)
	}
	// 入金
	if false {
		t.RegOnRtnFromFutureToBank(func(field *goctp.TransferField) {
			fmt.Println(field)
		})
		t.ReqFutureToBank("", "", 30)
	}
	// 订阅合约
	if true {
		q.ReqSubscript("rb2205")
	}

	fmt.Scanf("exit: ")
	t.Release()
	q.Release()
}

版本切换

复制 6.5.1 版本以上官方库文件覆盖到 lnx win 下同名文件即可。

QA

operator delete(void*, unsigned long)@CXXABI_1.3.9’未定义的引用

不同系统,不同版本的底层依赖不同 重新编译即可

cd lnx && g++ -shared -fPIC -Wl,-rpath . -o ./libctp_quote.so ../generate/quote.cpp  thostmduserapi_se.so && cd ..
cd lnx && g++ -shared -fPIC -Wl,-rpath . -o ./libctp_trade.so ../generate/trade.cpp  thosttraderapi_se.so && cd ..

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes2String

func Bytes2String(t []byte) string

Types

type AccountField

type AccountField struct {
	// 上次质押金额
	PreMortgage float64
	// 上次存款额
	PreDeposit float64
	// 上次结算准备金
	PreBalance float64
	// 上次占用的保证金
	PreMargin float64
	// 利息基数
	InterestBase float64
	// 利息收入
	Interest float64
	// 入金金额
	Deposit float64
	// 出金金额
	Withdraw float64
	// 冻结的保证金
	FrozenMargin float64
	// 冻结的资金
	FrozenCash float64
	// 冻结的手续费
	FrozenCommission float64
	// 当前保证金总额
	CurrMargin float64
	// 资金差额
	CashIn float64
	// 手续费
	Commission float64
	// 平仓盈亏
	CloseProfit float64
	// 持仓盈亏
	PositionProfit float64
	// 期货结算准备金
	Balance float64
	// 可用资金
	Available float64
	// 可取资金
	WithdrawQuota float64
	// 基本准备金
	Reserve float64
	// 信用额度
	Credit float64
	// 质押金额
	Mortgage float64
	// 交易所保证金
	ExchangeMargin float64
	// 投资者交割保证金
	DeliveryMargin float64
	// 交易所交割保证金
	ExchangeDeliveryMargin float64
	// 保底期货结算准备金
	ReserveBalance float64
	// 币种代码
	CurrencyID string
	// 上次货币质入金额
	PreFundMortgageIn float64
	// 上次货币质出金额
	PreFundMortgageOut float64
	// 货币质入金额
	FundMortgageIn float64
	// 货币质出金额
	FundMortgageOut float64
	// 货币质押余额
	FundMortgageAvailable float64
	// 可质押货币金额
	MortgageableFund float64
}

资金账户

type CombinationTypeType

type CombinationTypeType byte

组合类型

const (
	// 期货组合
	CombinationTypeFuture CombinationTypeType = '0'
	// 垂直价差BUL
	CombinationTypeBUL CombinationTypeType = '1'
	// 垂直价差BER
	CombinationTypeBER CombinationTypeType = '2'
	// 跨式组合
	CombinationTypeSTD CombinationTypeType = '3'
	// 宽跨式组合
	CombinationTypeSTG CombinationTypeType = '4'
	// 备兑组合
	CombinationTypePRT CombinationTypeType = '5'
	// 时间价差组合
	CombinationTypeCLD CombinationTypeType = '6'
)

type DirectionType

type DirectionType byte

买卖方向类型

const (
	// 买
	DirectionBuy DirectionType = '0'
	// 卖
	DirectionSell DirectionType = '1'
)

type GetVersionType added in v1.0.1

type GetVersionType func() string

type HFQuote added in v1.0.1

type HFQuote struct {
	InvestorID string
	BrokerID   string

	ReqConnect   ReqConnectType
	Release      ReleaseAPIType
	ReqUserLogin ReqUserLoginType
	ReqSubscript ReqSubscriptType
	// contains filtered or unexported fields
}

HFQuote 行情接口

func (*HFQuote) FrontConnected added in v1.0.1

func (q *HFQuote) FrontConnected()

func (*HFQuote) FrontDisConnected added in v1.0.1

func (q *HFQuote) FrontDisConnected(reason int)

func (*HFQuote) Init added in v1.0.1

func (q *HFQuote) Init()

func (*HFQuote) RegOnFrontConnected added in v1.0.1

func (q *HFQuote) RegOnFrontConnected(on OnFrontConnectedType)

RegOnFrontConnected 注册前置响应

func (*HFQuote) RegOnFrontDisConnected added in v1.0.1

func (q *HFQuote) RegOnFrontDisConnected(on OnFrontDisConnectedType)

RegOnFrontDisConnected 注册连接响应

func (*HFQuote) RegOnRspUserLogin added in v1.0.1

func (q *HFQuote) RegOnRspUserLogin(on OnRspUserLoginType)

RegOnRspUserLogin 注册登录响应

func (*HFQuote) RegOnTick added in v1.0.1

func (q *HFQuote) RegOnTick(on OnTickType)

RegOnTick 注册行情响应

func (*HFQuote) ReqLogin added in v1.0.1

func (q *HFQuote) ReqLogin(investor, pwd, broker string)

ReqLogin 登录

func (*HFQuote) RspUserLogin added in v1.0.1

func (q *HFQuote) RspUserLogin(loginField *ctpdefine.CThostFtdcRspUserLoginField, infoField *ctpdefine.CThostFtdcRspInfoField)

func (*HFQuote) RtnDepthMarketData added in v1.0.1

func (q *HFQuote) RtnDepthMarketData(dataField *ctpdefine.CThostFtdcDepthMarketDataField)

type HFTrade added in v1.0.1

type HFTrade struct {
	InvestorID string // 帐号
	BrokerID   string // 经纪商
	TradingDay string // 交易日

	SessionID int // 判断是否自己的委托用

	Instruments       sync.Map // 合约列表 (key: InstrumentID, value: *InstrumentField)
	InstrumentStatuss sync.Map // 合约状态 (key: InstrumentID, value: *InstrumentStatus)

	Positions sync.Map // 合成后的持仓 (key: instrument_long/short value: *ctp.CThostFtdcInvestorPositionField)
	Orders    sync.Map // 委托 (key: sessionID_OrderRef, value: *OrderField)
	Trades    sync.Map // 成交 (key: TradeID_buy/sell, value: &TradeField)

	Account *AccountField // 帐户权益

	IsLogin bool   // 登录成功
	Version string // 版本号,如 v6.5.1_20200908 10:25:08

	// 继承类要实现的函数
	ReqConnect                  ReqConnectType
	ReleaseAPI                  ReleaseAPIType
	ReqUserLogin                ReqUserLoginType
	ReqAuthenticate             ReqAuthenticateType
	ReqSettlementInfoConfirm    ReqSettlementInfoConfirmType
	ReqQryInstrument            ReqQryInstrumentType
	ReqQryClassifiedInstrument  ReqQryClassifiedInstrumentType
	ReqQryTradingAccount        ReqQryTradingAccountType
	ReqQryInvestorPosition      ReqQryInvestorPositionType
	ReqOrder                    ReqOrderInsertType
	ReqAction                   ReqOrderActionType
	ReqFromBankToFutureByFuture ReqTransferType
	ReqFromFutureToBankByFuture ReqTransferType
	GetVersion                  GetVersionType
	// contains filtered or unexported fields
}

HFTrade 交易接口

func (*HFTrade) ErrRtnOrderAction added in v1.0.1

func (t *HFTrade) ErrRtnOrderAction(field *ctp.CThostFtdcOrderActionField, info *ctp.CThostFtdcRspInfoField)

ErrRtnOrderAction 撤单错误

func (*HFTrade) ErrRtnOrderInsert added in v1.0.1

func (t *HFTrade) ErrRtnOrderInsert(field *ctp.CThostFtdcInputOrderField, info *ctp.CThostFtdcRspInfoField)

ErrRtnOrderInsert 委托错误

func (*HFTrade) FrontConnected added in v1.0.1

func (t *HFTrade) FrontConnected()

FrontConnected 连接

func (*HFTrade) FrontDisConnected added in v1.0.1

func (t *HFTrade) FrontDisConnected(reason int)

FrontDisConnected 断开响应

func (*HFTrade) Init added in v1.0.1

func (t *HFTrade) Init()

func (*HFTrade) RegOnErrAction added in v1.0.1

func (t *HFTrade) RegOnErrAction(on OnRtnErrActionType)

RegOnErrAction 注册撤单响应

func (*HFTrade) RegOnErrRtnOrder added in v1.0.1

func (t *HFTrade) RegOnErrRtnOrder(on OnRtnErrOrderType)

RegOnErrRtnOrder 注册委托响应

func (*HFTrade) RegOnFrontConnected added in v1.0.1

func (t *HFTrade) RegOnFrontConnected(on OnFrontConnectedType)

RegOnFrontConnected 注册连接响应

func (*HFTrade) RegOnFrontDisConnected added in v1.0.1

func (t *HFTrade) RegOnFrontDisConnected(on OnFrontDisConnectedType)

RegOnFrontDisConnected 注册连接响应

func (*HFTrade) RegOnRspUserLogin added in v1.0.1

func (t *HFTrade) RegOnRspUserLogin(on OnRspUserLoginType)

RegOnRspUserLogin 注册登陆响应

func (*HFTrade) RegOnRtnCancel added in v1.0.1

func (t *HFTrade) RegOnRtnCancel(on OnRtnOrderType)

RegOnRtnCancel 注册撤单响应

func (*HFTrade) RegOnRtnFromBankToFuture added in v1.0.1

func (t *HFTrade) RegOnRtnFromBankToFuture(on OnRtnFromBankToFutureByFuture)

RegOnRtnFromBankToFuture 注册银行转期货

func (*HFTrade) RegOnRtnFromFutureToBank added in v1.0.1

func (t *HFTrade) RegOnRtnFromFutureToBank(on OnRtnFromFutureToBankByFuture)

RegOnRtnFromFutureToBank 注册期货转银行

func (*HFTrade) RegOnRtnInstrumentStatus added in v1.0.1

func (t *HFTrade) RegOnRtnInstrumentStatus(on OnRtnInstrumentStatusType)

RegOnRtnInstrumentStatus 注册合约状态变化

func (*HFTrade) RegOnRtnOrder added in v1.0.1

func (t *HFTrade) RegOnRtnOrder(on OnRtnOrderType)

RegOnRtnOrder 注册委托响应

func (*HFTrade) RegOnRtnTrade added in v1.0.1

func (t *HFTrade) RegOnRtnTrade(on OnRtnTradeType)

RegOnRtnTrade 注册成交响应

func (*HFTrade) Release added in v1.0.1

func (t *HFTrade) Release()

func (*HFTrade) ReqBankToFuture added in v1.0.1

func (t *HFTrade) ReqBankToFuture(bankID, bankAccount, bankPwd string, amount float64)

ReqBankToFuture 银行转期货

func (*HFTrade) ReqFutureToBank added in v1.0.1

func (t *HFTrade) ReqFutureToBank(bankID, bankAccount string, amount float64)

ReqFutureToBank 期货转银行

func (*HFTrade) ReqLogin added in v1.0.1

func (t *HFTrade) ReqLogin(investor, pwd, broker, appID, authCode string)

ReqLogin 登录

func (*HFTrade) ReqOrderAction added in v1.0.1

func (t *HFTrade) ReqOrderAction(orderID string) int

ReqOrderAction 撤单

func (*HFTrade) ReqOrderInsert added in v1.0.1

func (t *HFTrade) ReqOrderInsert(instrument string, buySell DirectionType, openClose OffsetFlagType, price float64, volume int) string

ReqOrderInsert 限价委托

func (*HFTrade) ReqOrderInsertFAK added in v1.0.1

func (t *HFTrade) ReqOrderInsertFAK(instrument string, buySell DirectionType, openClose OffsetFlagType, price float64, volume int) string

ReqOrderInsertFAK FAK委托[全成or撤单]

func (*HFTrade) ReqOrderInsertFOK added in v1.0.1

func (t *HFTrade) ReqOrderInsertFOK(instrument string, buySell DirectionType, openClose OffsetFlagType, price float64, volume int) string

ReqOrderInsertFOK FOK委托[部成撤单]

func (*HFTrade) ReqOrderInsertMarket added in v1.0.1

func (t *HFTrade) ReqOrderInsertMarket(instrument string, buySell DirectionType, openClose OffsetFlagType, volume int) string

ReqOrderInsertMarket 市价委托

func (*HFTrade) RspAuthenticate added in v1.0.1

func (t *HFTrade) RspAuthenticate(info *ctp.CThostFtdcRspInfoField)

RspAuthenticate 认证

func (*HFTrade) RspQryInstrument added in v1.0.1

func (t *HFTrade) RspQryInstrument(field *ctp.CThostFtdcInstrumentField, b bool)

RspQryInstrument 合约

func (*HFTrade) RspQryInvestorPosition added in v1.0.1

func (t *HFTrade) RspQryInvestorPosition(field *ctp.CThostFtdcInvestorPositionField, b bool)

RspQryInvestorPosition 持仓

func (*HFTrade) RspQryTradingAccount added in v1.0.1

func (t *HFTrade) RspQryTradingAccount(field *ctp.CThostFtdcTradingAccountField)

RspQryTradingAccount 权益

func (*HFTrade) RspSettlementInfoConfirm added in v1.0.1

func (t *HFTrade) RspSettlementInfoConfirm()

RspSettlementInfoConfirm 确认结算

func (*HFTrade) RspUserLogin added in v1.0.1

func (t *HFTrade) RspUserLogin(loginField *ctp.CThostFtdcRspUserLoginField, infoField *ctp.CThostFtdcRspInfoField)

RspUserLogin 登录

func (*HFTrade) RtnFromBankToFutureByFuture added in v1.0.1

func (t *HFTrade) RtnFromBankToFutureByFuture(field *ctp.CThostFtdcRspTransferField)

RtnFromBankToFutureByFuture 银行转期货-期货端

func (*HFTrade) RtnFromFutureToBankByFuture added in v1.0.1

func (t *HFTrade) RtnFromFutureToBankByFuture(field *ctp.CThostFtdcRspTransferField)

RtnFromFutureToBankByFuture // 期货转银行-期货端

func (*HFTrade) RtnInstrumentStatus added in v1.0.1

func (t *HFTrade) RtnInstrumentStatus(field *ctp.CThostFtdcInstrumentStatusField)

RtnInstrumentStatus 合约/品种/交易所 状态响应

func (*HFTrade) RtnOrder added in v1.0.1

func (t *HFTrade) RtnOrder(field *ctp.CThostFtdcOrderField)

RtnOrder 委托响应

func (*HFTrade) RtnTrade added in v1.0.1

func (t *HFTrade) RtnTrade(field *ctp.CThostFtdcTradeField)

RtnTrade 成交响应

type HedgeFlagType

type HedgeFlagType byte

投机套保标志类型

const (
	// 投机
	HedgeFlagSpeculation HedgeFlagType = '1'
	// 套利
	HedgeFlagArbitrage HedgeFlagType = '2'
	// 套保
	HedgeFlagHedge HedgeFlagType = '3'
	// 做市商
	HedgeFlagMarketMaker HedgeFlagType = '5'
	// 第一腿投机第二腿套保 大商所专用
	HedgeFlagSpecHedge HedgeFlagType = '6'
	// 第一腿套保第二腿投机  大商所专用
	HedgeFlagHedgeSpec HedgeFlagType = '7'
)

type InstrumentField

type InstrumentField struct {
	// 合约代码
	InstrumentID string
	// 交易所代码
	ExchangeID string
	// 产品代码
	ProductID string
	// 产品类型
	ProductClass ProductClassType
	// 市价单最大下单量
	MaxMarketOrderVolume int
	// 市价单最小下单量
	MinMarketOrderVolume int
	// 限价单最大下单量
	MaxLimitOrderVolume int
	// 限价单最小下单量
	MinLimitOrderVolume int
	// 合约数量乘数
	VolumeMultiple int
	// 最小变动价位
	PriceTick float64
	// 持仓类型
	PositionType PositionTypeType
	// 是否使用大额单边保证金算法
	UseMaxMarginSideAlgorithm bool
	// 基础商品代码
	UnderlyingInstrID string
	// 执行价
	StrikePrice float64
	// 期权类型
	OptionsType OptionsTypeType
	// 合约基础商品乘数
	UnderlyingMultiple float64
	// 组合类型
	CombinationType CombinationTypeType
}

合约

type InstrumentStatus added in v0.1.8

type InstrumentStatus struct {
	// 交易所代码
	ExchangeID string
	// 合约代码
	InstrumentID string
	// 合约交易状态
	InstrumentStatus InstrumentStatusType
	// 进入本状态时间
	EnterTime string
}

InstrumentStatus 合约状态

type InstrumentStatusType

type InstrumentStatusType byte

合约交易状态类型

const (
	// 开盘前
	InstrumentStatusBeforeTrading InstrumentStatusType = '0'
	// 非交易
	InstrumentStatusNoTrading InstrumentStatusType = '1'
	// 连续交易
	InstrumentStatusContinous InstrumentStatusType = '2'
	// 集合竞价报单
	InstrumentStatusAuctionOrdering InstrumentStatusType = '3'
	// 集合竞价价格平衡
	InstrumentStatusAuctionBalance InstrumentStatusType = '4'
	// 集合竞价撮合
	InstrumentStatusAuctionMatch InstrumentStatusType = '5'
	// 收盘
	InstrumentStatusClosed InstrumentStatusType = '6'
)

type OffsetFlagType

type OffsetFlagType byte

开平标志类型

const (
	// 开仓
	OffsetFlagOpen OffsetFlagType = '0'
	// 平仓
	OffsetFlagClose OffsetFlagType = '1'
	// 强平
	OffsetFlagForceClose OffsetFlagType = '2'
	// 平今
	OffsetFlagCloseToday OffsetFlagType = '3'
	// 平昨
	OffsetFlagCloseYesterday OffsetFlagType = '4'
	// 强减
	OffsetFlagForceOff OffsetFlagType = '5'
	// 本地强平
	OffsetFlagLocalForceClose OffsetFlagType = '6'
)

type OnFrontConnectedType

type OnFrontConnectedType func()

公共-连接

type OnFrontDisConnectedType added in v0.1.8

type OnFrontDisConnectedType func(reason int)

公共-断开

type OnRspUserLoginType

type OnRspUserLoginType func(loginField *RspUserLoginField, info *RspInfoField)

公共-登录

type OnRtnErrActionType

type OnRtnErrActionType func(orderID string, info *RspInfoField)

交易-错误撤单

type OnRtnErrOrderType

type OnRtnErrOrderType func(field *OrderField, info *RspInfoField)

交易-错误委托

type OnRtnFromBankToFutureByFuture added in v0.2.4

type OnRtnFromBankToFutureByFuture func(field *TransferField)

银转-银行->期货

type OnRtnFromFutureToBankByFuture added in v0.2.4

type OnRtnFromFutureToBankByFuture func(field *TransferField)

银转-期货->银行

type OnRtnInstrumentStatusType added in v0.1.8

type OnRtnInstrumentStatusType func(field *InstrumentStatus)

交易-合约状态响应

type OnRtnOrderType

type OnRtnOrderType func(field *OrderField)

交易-委托响应

type OnRtnTradeType

type OnRtnTradeType func(field *TradeField)

交易-成交响应

type OnTickType

type OnTickType func(tick *TickField)

行情

type OptionsTypeType

type OptionsTypeType byte

期权类型

const (
	// 看涨
	OptionsTypeCallOptions OptionsTypeType = '1'
	// 看跌
	OptionsTypePutOptions OptionsTypeType = '2'
)

type OrderField

type OrderField struct {
	// 合约代码
	InstrumentID string
	// 报单引用
	OrderRef string
	// 买卖方向
	Direction DirectionType
	// 组合开平标志
	OffsetFlag OffsetFlagType
	// 组合投机套保标志
	HedgeFlag HedgeFlagType
	// 价格
	LimitPrice float64
	// 数量
	VolumeTotalOriginal int
	// 交易所代码
	ExchangeID string
	// 报单编号
	OrderSysID string
	// 报单状态
	OrderStatus OrderStatusType
	// 今成交数量
	VolumeTraded int
	// 剩余数量
	VolumeLeft int
	// 报单日期
	InsertDate string
	// 委托时间
	InsertTime string
	// 撤销时间
	CancelTime string
	// 前置编号
	FrontID int
	// 会话编号
	SessionID int
	// 状态信息
	StatusMsg string
	// 是否本次登录后的委托
	IsLocal bool
	// 成交时间(有OnTrade更新)
	LastTradeTime string
	// 成交均价
	TradePrice float64
}

报单

type OrderStatusType

type OrderStatusType byte

报单状态类型

const (
	// 全部成交
	OrderStatusAllTraded OrderStatusType = '0'
	// 部分成交还在队列中
	OrderStatusPartTradedQueueing OrderStatusType = '1'
	// 部分成交不在队列中
	OrderStatusPartTradedNotQueueing OrderStatusType = '2'
	// 未成交还在队列中
	OrderStatusNoTradeQueueing OrderStatusType = '3'
	// 未成交不在队列中
	OrderStatusNoTradeNotQueueing OrderStatusType = '4'
	// 撤单
	OrderStatusCanceled OrderStatusType = '5'
	// 未知
	OrderStatusUnknown OrderStatusType = 'a'
	// 尚未触发
	OrderStatusNotTouched OrderStatusType = 'b'
	// 已触发
	OrderStatusTouched OrderStatusType = 'c'
)

type PosiDirectionType

type PosiDirectionType byte

持仓多空方向类型

const (
	// 净
	PosiDirectionNet PosiDirectionType = '1'
	// 多头
	PosiDirectionLong PosiDirectionType = '2'
	// 空头
	PosiDirectionShort PosiDirectionType = '3'
)

type PositionField

type PositionField struct {
	// 合约代码
	InstrumentID string
	// 持仓多空方向
	PositionDirection PosiDirectionType
	// 投机套保标志
	HedgeFlag HedgeFlagType
	// 上日持仓
	YdPosition int
	// 今日持仓
	Position int
	// 多头冻结
	LongFrozen int
	// 空头冻结
	ShortFrozen int
	// 开仓冻结金额
	LongFrozenAmount float64
	// 开仓冻结金额
	ShortFrozenAmount float64
	// 开仓量
	OpenVolume int
	// 平仓量
	CloseVolume int
	// 开仓金额
	OpenAmount float64
	// 平仓金额
	CloseAmount float64
	// 持仓成本
	PositionCost float64
	// 上次占用的保证金
	PreMargin float64
	// 占用的保证金
	UseMargin float64
	// 冻结的保证金
	FrozenMargin float64
	// 冻结的资金
	FrozenCash float64
	// 冻结的手续费
	FrozenCommission float64
	// 资金差额
	CashIn float64
	// 手续费
	Commission float64
	// 平仓盈亏
	CloseProfit float64
	// 持仓盈亏
	PositionProfit float64
	// 上次结算价
	PreSettlementPrice float64
	// 本次结算价
	SettlementPrice float64
	// 开仓成本
	OpenCost float64
	// 交易所保证金
	ExchangeMargin float64
	// 组合成交形成的持仓
	CombPosition int
	// 组合多头冻结
	CombLongFrozen int
	// 组合空头冻结
	CombShortFrozen int
	// 逐日盯市平仓盈亏
	CloseProfitByDate float64
	// 逐笔对冲平仓盈亏
	CloseProfitByTrade float64
	// 今日持仓
	TodayPosition int
	// 执行冻结
	StrikeFrozen int
	// 执行冻结金额
	StrikeFrozenAmount float64
	// 放弃执行冻结
	AbandonFrozen int
	// 交易所代码
	ExchangeID string
	// 执行冻结的昨仓
	YdStrikeFrozen int
	// 大商所持仓成本差值,只有大商所使用
	PositionCostOffset float64
}

投资者持仓

type PositionTypeType

type PositionTypeType byte

持仓类型类型

const (
	// 净持仓
	PositionTypeNet PositionTypeType = '1'
	// 综合持仓
	PositionTypeGross PositionTypeType = '2'
)

type ProductClassType

type ProductClassType byte

产品类型类型

const (
	// 期货
	ProductClassFutures ProductClassType = '1'
	// 期货期权
	ProductClassOptions ProductClassType = '2'
	// 组合
	ProductClassCombinationProductClassType = '3'
	// 即期
	ProductClassSpot ProductClassType = '4'
	// 期转现
	ProductClassEFP ProductClassType = '5'
	// 现货期权
	ProductClassSpotOption ProductClassType = '6'
)

type ReleaseAPIType added in v1.0.1

type ReleaseAPIType func()

type ReqAuthenticateType added in v1.0.1

type ReqAuthenticateType func(*ctp.CThostFtdcReqAuthenticateField, int)

type ReqConnectType added in v1.0.1

type ReqConnectType = func(string)

type ReqOrderActionType added in v1.0.1

type ReqOrderActionType = func(*ctp.CThostFtdcInputOrderActionField, int)

type ReqOrderInsertType added in v1.0.1

type ReqOrderInsertType func(*ctp.CThostFtdcInputOrderField, int)

type ReqQryClassifiedInstrumentType added in v1.0.1

type ReqQryClassifiedInstrumentType func(*ctp.CThostFtdcQryClassifiedInstrumentField, int)

type ReqQryInstrumentType added in v1.0.1

type ReqQryInstrumentType func(*ctp.CThostFtdcQryInstrumentField, int)

type ReqQryInvestorPositionType added in v1.0.1

type ReqQryInvestorPositionType func(*ctp.CThostFtdcQryInvestorPositionField, int)

type ReqQryTradingAccountType added in v1.0.1

type ReqQryTradingAccountType func(*ctp.CThostFtdcQryTradingAccountField, int)

type ReqSettlementInfoConfirmType added in v1.0.1

type ReqSettlementInfoConfirmType func(*ctp.CThostFtdcSettlementInfoConfirmField, int)

type ReqSubscriptType added in v1.0.1

type ReqSubscriptType func(string)

type ReqTransferType added in v1.0.1

type ReqTransferType = func(*ctp.CThostFtdcReqTransferField, int)

type ReqUserLoginType added in v1.0.1

type ReqUserLoginType func(*ctp.CThostFtdcReqUserLoginField, int)

type RspInfoField

type RspInfoField struct {
	// 错误代码
	ErrorID int
	// 错误信息
	ErrorMsg string
}

响应信息

type RspUserLoginField

type RspUserLoginField struct {
	// 交易日
	TradingDay string
	// 登录成功时间
	LoginTime string
	// 经纪公司代码
	BrokerID string
	// 用户代码
	UserID string
	// 交易系统名称
	//SystemName string
	// 前置编号
	FrontID int
	// 会话编号
	SessionID int
	// 最大报单引用
	MaxOrderRef string
}

用户登录应答

type TickField

type TickField struct {
	// 交易日
	TradingDay string
	// 合约代码
	InstrumentID string
	// 交易所代码
	ExchangeID string
	// 合约在交易所的代码
	//ExchangeInstID string
	// 最新价
	LastPrice float64
	// 上次结算价
	//PreSettlementPrice float64
	// 昨收盘
	//PreClosePrice float64
	// 昨持仓量
	//PreOpenInterest float64
	// 今开盘
	OpenPrice float64
	// 最高价
	HighestPrice float64
	// 最低价
	LowestPrice float64
	// 数量
	Volume int
	// 成交金额
	Turnover float64
	// 持仓量
	OpenInterest float64
	// 今收盘
	ClosePrice float64
	// 本次结算价
	SettlementPrice float64
	// 涨停板价
	UpperLimitPrice float64
	// 跌停板价
	LowerLimitPrice float64
	// 昨虚实度
	//PreDelta float64
	// 今虚实度
	CurrDelta float64
	// 最后修改时间
	UpdateTime string
	// 最后修改毫秒
	UpdateMillisec int
	// 申买价一
	BidPrice1 float64
	// 申买量一
	BidVolume1 int
	// 申卖价一
	AskPrice1 float64
	// 申卖量一
	AskVolume1 int
	// 申买价二
	BidPrice2 float64
	// 申买量二
	BidVolume2 int
	// 申卖价二
	AskPrice2 float64
	// 申卖量二
	AskVolume2 int
	// 申买价三
	BidPrice3 float64
	// 申买量三
	BidVolume3 int
	// 申卖价三
	AskPrice3 float64
	// 申卖量三
	AskVolume3 int
	// 申买价四
	BidPrice4 float64
	// 申买量四
	BidVolume4 int
	// 申卖价四
	AskPrice4 float64
	// 申卖量四
	AskVolume4 int
	// 申买价五
	BidPrice5 float64
	// 申买量五
	BidVolume5 int
	// 申卖价五
	AskPrice5 float64
	// 申卖量五
	AskVolume5 int
	// 当日均价
	AveragePrice float64
	// 业务日期
	ActionDay string
}

行情响应

type TradeField

type TradeField struct {
	// 合约代码
	InstrumentID string
	// 交易所代码
	ExchangeID string
	// 成交编号
	TradeID string
	// 买卖方向
	Direction DirectionType
	// 报单编号
	OrderSysID string
	// 开平标志
	OffsetFlag OffsetFlagType
	// 投机套保标志
	HedgeFlag HedgeFlagType
	// 价格
	Price float64
	// 数量
	Volume int
	// 成交时期
	TradeDate string
	// 成交时间
	TradeTime string
	// 交易日
	TradingDay string
}

成交

type TransferField added in v0.2.4

type TransferField struct {
	Time       string  // 时间
	CurrencyID string  // 币种
	Amout      float64 // 金额
	ErrorID    int     // 错误码
	ErrorMsg   string  // 错误描述
}

TransferField 银转响应

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL