Documentation
¶
Overview ¶
功能:提供请求验证、数据转换、时间处理等相关函数。
Index ¶
- Constants
- Variables
- func BuildUri(uri string, instId string, optionalParams map[string]string) string
- func CalCloseStrPx(p *Positions, goal, fee_open, fee_close float64) string
- func Decimal(value float64) float64
- func GetLinesCsv(filename string, passTitle bool) ([][]string, error)
- func GetResponseDataJsonString(response *http.Response) string
- func GetResponsePageJsonString(response *http.Response) string
- func GetTickSzFromJson(filename, instId string) string
- func GetTickSzQuick(id1 string) string
- func GetctValFromJson(filename, instId string) string
- func Headers(request *http.Request, config Config, timestamp string, sign string)
- func HmacSha256Base64Signer(message string, secretKey string) (string, error)
- func IdAndBarToTable(id, bar string) string
- func NewParams() map[string]string
- func ParseRequestParams(params interface{}) (string, *bytes.Reader, error)
- func PreHashString(timestamp string, method string, requestPath string, body string) string
- func SetMyLog()
- func StructToMap(s interface{}) (d map[string]string)
- func TimeSplit1(end string, start string, bar string) [][2]string
- func TimeSplit2(end string, start string, bar string) [][2]string
- func TimeToMs(s string) (r int64)
- type AccConfig
- type AccountBalanceData
- type AccountBalanceDataDetails
- type AccountBalanceResult
- type AccountInstrumentsData
- type AccountInstrumentsResult
- type ApiCodeMsg
- type AssetBalances
- type AssetBalancesResult
- type BaseCancelOrderResult
- type BaseLeverResult
- type BaseOrderResult
- type BaseSpendingOrderResult
- type BaseTickerResult
- type BaseTradeOrderInfoResult
- type Bills
- type BillsResult
- type Books
- type BooksData
- type CancelOrderParam
- type CancelOrderResult
- type Client
- func (client *Client) CancelOrders(param interface{}) (r CancelOrderResult, err error)
- func (client *Client) Get3MonthsBills(optionalParams map[string]string) (r BillsResult, err error)
- func (client *Client) GetAccountBalance(ccy string) (r AccountBalanceResult, err error)
- func (client *Client) GetAccountConfig() (r ConfigResult, err error)
- func (client *Client) GetAccountInstruments(params map[string]string) (r AccountInstrumentsResult, err error)
- func (client *Client) GetAndWriteAccountInstruments(instType, filename string)
- func (client *Client) GetAndWritePublicInstruments(instType, filename string)
- func (client *Client) GetBills(optionalParams map[string]string) (r BillsResult, err error)
- func (client *Client) GetBillsPlus(optionalParams map[string]string) ([]Bills, error)
- func (client *Client) GetBooks(params map[string]string) (r Books, err error)
- func (client *Client) GetFundingRate(instId string) (r FundingRate, err error)
- func (client *Client) GetFundingRateHistory(instId string, optionalParams map[string]string) (r FundingRate, err error)
- func (client *Client) GetKlines(instId string, params map[string]string) (r Klines, err error)
- func (client *Client) GetKlinesHistory(instId string, params map[string]string) (r Klines, err error)
- func (client *Client) GetKlinesHistoryPlus1(instId string, params map[string]string) ([]KlineData, error)
- func (client *Client) GetKlinesHistoryPlus2(instId string, params map[string]string, flag int) ([]KlineData, error)
- func (client *Client) GetKlinesSync(id string, p map[string]string, ch chan []KlineData)
- func (client *Client) GetLeverInfo(optionalParams map[string]string) (r LeverInfoResult, err error)
- func (client *Client) GetMaxAvailSize(params map[string]string) (r MaxAvailSizeResult, err error)
- func (client *Client) GetMaxSize(params map[string]string) (r MaxSizeResult, err error)
- func (client *Client) GetPendingOrders(param map[string]string) (r SpendingOrderResult, err error)
- func (client *Client) GetPositions(optionalParams map[string]string) (r PositionsResult, err error)
- func (client *Client) GetPublicInstruments(params map[string]string) (r AccountInstrumentsResult, err error)
- func (client *Client) GetServerTime() (serverTime ServerTime, err error)
- func (client *Client) GetTickSz(instType, instId string) (ticksz string, err error)
- func (client *Client) GetTicker(instId string) (r TickerResult, err error)
- func (client *Client) GetTickerType(instType string) (r TickerResult, err error)
- func (client *Client) GetTradeFee(params map[string]string) (r TradeFeeResult, err error)
- func (client *Client) GetTradeOrderInfo(param map[string]string) (r TradeOrderInfoResult, err error)
- func (client *Client) Request(method string, requestPath string, params, result interface{}) (response *http.Response, err error)
- func (client *Client) SetLever(leverParam interface{}) (r LeverResult, err error)
- func (client *Client) TradeOrder(orderParam interface{}) (r OrderResult, err error)
- type Config
- type ConfigResult
- type Currencies
- type CurrenciesResult
- type FundingRate
- type FundingRateData
- type KlineData
- type KlineDataS
- type Klines
- type LeverInfo
- type LeverInfoResult
- type LeverParam
- type LeverResult
- type MaxAvailSize
- type MaxAvailSizeResult
- type MaxSize
- type MaxSizeResult
- type MyMacdClass
- func (mymacd *MyMacdClass) Append(close1 float64)
- func (mymacd *MyMacdClass) CalMacd()
- func (mymacd *MyMacdClass) CrossOver(pos int) bool
- func (mymacd *MyMacdClass) CrossOverTwice(pos int) bool
- func (mymacd *MyMacdClass) CrossUnder(pos int) bool
- func (mymacd *MyMacdClass) CrossUnderTwice(pos int) bool
- func (mymacd *MyMacdClass) CsToFloat64(cs []string) []float64
- func (mymacd *MyMacdClass) Init(closeData []float64, fast int, slow int, signal int)
- func (mymacd *MyMacdClass) OverZero(pos int) bool
- func (mymacd *MyMacdClass) UnderZero(pos int) bool
- func (mymacd *MyMacdClass) Up3Hist(pos int) bool
- func (mymacd *MyMacdClass) UpHist(pos int) bool
- type MyMariaDBClass
- func (mydb *MyMariaDBClass) CheckTableExists(table string) bool
- func (mydb *MyMariaDBClass) Connect(user, passwd, ip, port, dbName string) error
- func (mydb *MyMariaDBClass) CreateGameData2() (r []KlineDataS)
- func (mydb *MyMariaDBClass) CreateTable(table string) error
- func (mydb *MyMariaDBClass) CreateTradeGameData3(a bool, b bool, bar string) (r []KlineDataS, stock string, name string)
- func (mydb *MyMariaDBClass) Delete(table string, n int, direct int, orderby string) (err error)
- func (mydb *MyMariaDBClass) DeleteNum(table string, n int, direct int, orderby string) (err error)
- func (mydb *MyMariaDBClass) DeleteTable(table string) (err error)
- func (mydb *MyMariaDBClass) GetRowCount(table string) (int, error)
- func (mydb *MyMariaDBClass) Init(user, passwd, ip, port, dbName string) (err error)
- func (mydb *MyMariaDBClass) InsertDict(table string, dict map[string]string) (err error)
- func (mydb *MyMariaDBClass) InsertStructs(table string, items interface{}) (err error)
- func (mydb *MyMariaDBClass) InsertUseIdAndBar(c *Client, id string, bar string, start string, end string, table string, ...) error
- func (mydb *MyMariaDBClass) InsertUseIdAndBar2(c *Client, id string, bar string, start string, end string, table string, ...) error
- func (maria *MyMariaDBClass) InsertUseIdAndBarSync(c *Client, id string, bar string, start string)
- func (mydb *MyMariaDBClass) InsertUseIdAndBarSyncCh(c *Client, id string, bar string, start string)
- func (mydb *MyMariaDBClass) Query(r interface{}, sql string) (err error)
- func (mydb *MyMariaDBClass) QueryClose(table string, start string, end string) ([]string, error)
- func (mydb *MyMariaDBClass) QueryNum(r interface{}, table string, direct int, limit int) (err error)
- func (mydb *MyMariaDBClass) QueryRand(r interface{}, table string, n int) (err error)
- func (mydb *MyMariaDBClass) QueryStartEnd(r interface{}, table string, start string, end string) (err error)
- func (mydb *MyMariaDBClass) RenameTableToLower() error
- type OrderResult
- type PositionModeParam
- type Positions
- type PositionsResult
- type ServerTime
- type SpendingOrderResult
- type SwapOrderParam
- type TickerResult
- type Times
- type TradeFee
- type TradeFeeResult
- type TradeOrderInfoResult
Constants ¶
const ( // http header CONTENT_TYPE = "Content-Type" OK_ACCESS_KEY = "OK-ACCESS-KEY" OK_ACCESS_SIGN = "OK-ACCESS-SIGN" OK_ACCESS_PASSPHRASE = "OK-ACCESS-PASSPHRASE" OK_ACCESS_TIMESTAMP = "OK-ACCESS-TIMESTAMP" X_SIMULATE_TRADING = "x-simulated-trading" APPLICATION_JSON = "application/json" APPLICATION_JSON_UTF8 = "application/json; charset=UTF-8" ENGLISH = "en_US" SIMPLIFIED_CHINESE = "zh_CN" TRADITIONAL_CHINESE = "zh_HK" ACCEPT = "Accept" COOKIE = "Cookie" LOCALE = "locale=" ResultDataJsonString = "resultDataJsonString" ResultPageJsonString = "resultPageJsonString" // http method GET = "GET" POST = "POST" DELETE = "DELETE" )
const ( // 交易账户 account // 获取持仓信息 ACCOUNT_POSITIONS = "/api/v5/account/positions" // 可交易产品基础信息 ACCOUNT_INSTRUMENTS = "/api/v5/account/instruments" // 余额 ACCOUNT_BALANCE = "/api/v5/account/balance" // 交易流水:七天 ACCOUNT_BILLS = "/api/v5/account/bills" // 交易流水:三个月 ACCOUNT_BILLS_ARCHIVE = "/api/v5/account/bills-archive" // 账户配置 ACCOUNT_CONFIG = "/api/v5/account/config" // 设置账户交易模式 SET_POSITIONMODE = "/api/v5/account/set-position-mode" // 获取杠杆倍数 ACCOUNT_LEVERINFO = "/api/v5/account/leverage-info" // 设置杠杠 SET_LEVER = "/api/v5/account/set-leverage" // 获取最大可下单数量 Max_SIZE = "/api/v5/account/max-size" // 获取最大可用余额/保证金 Max_Avail_SIZE = "/api/v5/account/max-avail-size" // 获取交易手续费率 TRADE_FEE = "/api/v5/account/trade-fee" // 资金账户 asset // 获取平台所有币种列表 ASSET_CURRENCIES = "/api/v5/asset/currencies" // 获取资金账户余额 ASSET_BALANCES = "/api/v5/asset/balances" // 公共数据 public // 服务器时间 OKEX_TIME_URI = "/api/v5/public/time" // 可交易产品基础信息 PUBLIC_INSTRUMENTS = "/api/v5/public/instruments" // 当前资金费率 SWAP_FUNDING_RATE = "/api/v5/public/funding-rate" // 历史资金费率 SWAP_HISTORY_FUNDING_RATE = "/api/v5/public/funding-rate-history" // 行情数据 market // 获取全部产品行情信息 MARKET_TICKERS = "/api/v5/market/tickers" // 获取单个产品行情信息 MARKET_TICKER = "/api/v5/market/ticker" // Kline MARKET_CANDLES = "/api/v5/market/candles" MARKET_CANDLES_HISTORY = "/api/v5/market/history-candles" // books MARKET_BOOKS = "/api/v5/market/books" // 交易 trade // 下单、查询订单 TRADE_ORDER = "/api/v5/trade/order" // 获取未成交订单 TRADE_PENDING_ORDER = "/api/v5/trade/orders-pending" // 撤单 TRADE_CANCEL_ORDER = "/api/v5/trade/cancel-order" )
Variables ¶
var ( ISONow = mytime.ISONow TsNow = mytime.TsNow ISOCSTToTs = mytime.ISOCSTToTs TsToISOCST = mytime.TsToISOCST IntToString = myfun.IntToString Int64ToString = myfun.Int64ToString StringToFloat64 = myfun.StringToFloat64 StringToInt64 = myfun.StringToInt64 Float64ToString = myfun.Float64ToString JsonBytes2Struct = myfun.JsonBytes2Struct Struct2JsonString = myfun.Struct2JsonString WriteJSONFile = myfun.WriteJSONFile ReadJSONFile = myfun.ReadJSONFile IfError = myfun.IfError )
设置函数别名,方便打字
Functions ¶
func CalCloseStrPx ¶ added in v0.0.4
Cal Price ======================================================================== Start: 根据持仓均价、收益率、方向、fee_open、fee_close,计算平仓价格
func GetLinesCsv ¶ added in v0.0.5
获取csv文件内容
func GetTickSzFromJson ¶ added in v0.0.4
获取下单价格精度,从本地文件
func GetctValFromJson ¶ added in v0.0.5
获取合约面值,从本地文件
func HmacSha256Base64Signer ¶
生成签名,即 OK-ACCESS-SIGN
func IdAndBarToTable ¶ added in v0.0.5
id := "DOGE-USDT-SWAP" bar := "1H" --> table: DOGEUSDTSWAP1H --> dogeusdtswap1h table 需要转为小写,为了跨平台。
func ParseRequestParams ¶
Http 函数 ======================================================================== Start 生成json和bin格式的body
func PreHashString ¶
请求验证 ========================================================================= Start 生成签名用的 message
func StructToMap ¶ added in v0.0.5
struct to map[string]string
func TimeSplit1 ¶ added in v0.0.5
功能:将给定的时间段,切分成每段100个k线。但是,每段的开始部分,回退了1s
func TimeSplit2 ¶ added in v0.0.5
功能:将给定的时间段,切分成每段100个k线;不过,与上面的不同,这是整齐的分段。
Types ¶
type AccConfig ¶
type AccConfig struct {
Uid string `json:"uid"`
AcctLv string `json:"acctLv"`
PosMode string `json:"posMode"`
AutoLoan bool `json:"autoLoan"`
GreeksType string `json:"greeksType"`
Level string `json:"level"`
Label string `json:"label"`
Ip string `json:"ip"`
Perm string `json:"perm"`
LiquidationGear string `json:"liquidationGear"`
}
账户配置
type AccountBalanceData ¶
type AccountBalanceData struct {
UTime string `json:"uTime"` // 账户信息的更新时间
TotalEq string `json:"totalEq"` // 美金层面权益
IsoEq string `json:"isoEq"` // 美金层面逐仓仓位权益
AdjEq string `json:"adjEq"` // 美金层面有效保证金
OrdFroz string `json:"ordFroz"` // 美金层面全仓挂单占用保证金
Imr string `json:"imr"` // 美金层面占用保证金
Mmr string `json:"mmr"` // 美金层面维持保证金
BorrowFroz string `json:"borrowFroz"` // 账户美金层面潜在借币占用保证金率
MgnRatio string `json:"mgnRatio"` // 美金层面保证金率
NotionalUsd string `json:"notionalUsd"` // 仓位美金价值
Upl string `json:"upl"` // 账户层面未实现盈亏
Details []AccountBalanceDataDetails `json:"details"` // 各币种资产详细信息
}
账户余额
type AccountBalanceDataDetails ¶
type AccountBalanceDataDetails struct {
Ccy string `json:"ccy"` // 币种
Eq string `json:"eq"` // 币种总权益
CashBal string `json:"cashBal"` // 币种余额
UTime string `json:"uTime"` // 时间戳
IsoEq string `json:"isoEq"` // 币种逐仓仓位权益
AvailEq string `json:"availEq"` // 可用保证金
DisEq string `json:"disEq"` // 美金层面币种折算权益
FixedBal string `json:"fixedBal"` // 抄底宝、逃顶宝功能的币种冻结金额
AvailBal string `json:"availBal"` // 可用余额
FronzenBal string `json:"fronzenBal"` // 币种占用余额
OrdFrozen string `json:"ordFrozen"` // 挂单冻结数量
Liab string `json:"liab"` // 币种负债额
Upl string `json:"upl"` // 未实现盈亏
UplLiab string `json:"uplLiab"` // 由于仓位未实现亏损导致的负债
CrossLiab string `json:"crossLiab"` // 币种全仓负债额
IsoLiab string `json:"isoLiab"` // 币种逐仓负债额
MgnRatio string `json:"mgnRatio"` // 币种全仓保证金率
Imr string `json:"imr"` // 币种维度全仓占用保证金
Mmr string `json:"mmr"` // 币种维度全仓维持保证金
Interest string `json:"interest"` // 应扣未扣利息
}
type AccountBalanceResult ¶
type AccountBalanceResult struct {
ApiCodeMsg
Data []AccountBalanceData `json:"data"`
}
type AccountInstrumentsData ¶
type AccountInstrumentsData struct {
InstType string `json:"instType"` // 产品类型
InstId string `json:"instId"` // 产品ID
Uly string `json:"uly"` // 标的指数
InstFamily string `json:"instFamly"` // 交易品种
BaseCcy string `json:"baseCcy"` // 交易货币币种
QuoteCcy string `json:"quoteCcy"` // 计价货币币种
SettleCcy string `json:"settleCcy"` // 盈亏结算和保证金币种
CtVal string `json:"ctVal"` // 合约面值
CtMult string `json:"ctMult"` // 合约乘数
CtValCcy string `json:"ctValCcy"` // 合约面值计价币种
OptType string `json:"optType"` // 期权类型
Stk string `json:"stk"` // 行权价格
ListTime string `json:"listTime"` // 上线时间
ExpTime string `json:"expTime"` // 下线时间
Lever string `json:"lever"` // 最大杠杆倍数
TickSz string `json:"tickSz"` // 下单价格精度
LotSz string `json:"lotSz"` // 下单数量精度
MinSz string `json:"minSz"` // 最小下单数量
CtType string `json:"ctType"` // 合约类型
State string `json:"state"` // 产品状态
RuleType string `json:"ruleType"` // 交易规则类型
MaxLmtSz string `json:"maxLmtSz"` // 限价单的单笔最大委托数量
MaxMktSz string `json:"maxMktSz"` // 市价单的单笔最大委托数量
MaxLmtAmt string `json:"maxLmtAmt"` // 限价单的单笔最大美元价值
MaxMktAmt string `json:"maxMktAmt"` // 市价单的单笔最大美元价值
MaxTwapSz string `json:"maxTwapSz"` // 时间加权单的单笔最大委托数量
MaxIcebergSz string `json:"maxIcebergSz"` // 冰山委托的单笔最大委托数量
MaxTriggerSz string `json:"maxTriggerSz"` // 计划委托委托的单笔最大委托数量
MaxStopSz string `json:"maxStopSz"` // 止盈止损市价委托的单笔最大委托数量
}
交易账户 account: (对应,下面还有资金账户 asset ) Account ========================================================= Start: 获取当前账户可交易产品的信息列表
type AccountInstrumentsResult ¶
type AccountInstrumentsResult struct {
ApiCodeMsg
Data []AccountInstrumentsData `json:"data"`
}
type ApiCodeMsg ¶
返回结果必包含这两个基本信息
type AssetBalances ¶
type AssetBalances struct {
Ccy string `json:"ccy"`
Bal string `json:"bal"`
FrozenBal string `json:"frozenBal"`
AvailBal string `json:"availBal"`
}
获取资金账户余额
type AssetBalancesResult ¶
type AssetBalancesResult struct {
ApiCodeMsg
Data []AssetBalances `json:"data"`
}
type BaseCancelOrderResult ¶ added in v0.0.4
撤单返回的结构体
type BaseLeverResult ¶
type BaseLeverResult struct {
Lever string `json:"lever"`
MgnMode string `json:"mgnMode"` // isolated, cross
InstId string `json:"instId"`
PosSide string `json:"posSide"` // long, short
}
设置杠杠返回的数据结构
type BaseOrderResult ¶ added in v0.0.4
type BaseOrderResult struct {
OrderId string `json:"ordId"`
ClOrdId string `json:"clOrdId"`
Tag string `json:"tag"`
SCode string `json:"sCode"`
SMsg string `json:"sMsg"`
}
下单返回的数据结构,主要的
type BaseSpendingOrderResult ¶ added in v0.0.4
type BaseSpendingOrderResult struct {
InstId string `json:"instId"`
OrdId string `json:"ordId"`
Px string `json:"px"`
Side string `json:"side"`
Sz string `json:"sz"`
PosSide string `json:"posside"`
CTime string `json:"cTime"`
}
查询未成交订单时,返回的结构体
type BaseTickerResult ¶ added in v0.0.5
type BaseTickerResult struct {
InstId string `json:"instId"`
InstType string `json:"instType"`
Last string `json:"last"`
LastSz string `json:"lastSz"`
Ts string `json:"ts"`
AskPx string `json:"askPx"`
AskSz string `json:"askSz"`
BidPx string `json:"bidPx"`
BidSz string `json:"bidSz"`
}
行情信息结构,待完善
type BaseTradeOrderInfoResult ¶ added in v0.0.4
type BaseTradeOrderInfoResult struct {
OrdId string `json:"ordId"`
State string `json:"state"`
AccFillSz string `json:"accFillSz"`
}
查询订单时,返回的结构体
type Bills ¶
type Bills struct {
InstId string `json:"instId"`
InstType string `json:"instType"`
MgnMode string `json:"mgnMode"`
Ts string `json:"ts"`
Type string `json:"type"`
SubType string `json:"subType"`
Sz string `json:"sz"`
Pnl string `json:"pnl"` // 收益
Fee string `json:"fee"` // 手续费
BillId string `json:"billId"` // 账单ID
}
账户流水
type BillsResult ¶
type BillsResult struct {
ApiCodeMsg
Data []Bills `json:"data"`
}
type Books ¶ added in v0.0.5
type Books struct {
ApiCodeMsg
Data []BooksData `json:"data"`
}
type BooksData ¶ added in v0.0.5
type BooksData struct {
Asks [][]string `json:"asks"`
Bids [][]string `json:"bids"`
Ts string `json:"ts"`
}
深度数据
type CancelOrderParam ¶ added in v0.0.4
撤单参数
type CancelOrderResult ¶ added in v0.0.4
type CancelOrderResult struct {
ApiCodeMsg
Data []BaseCancelOrderResult `json:"data"`
}
type Client ¶
func (*Client) CancelOrders ¶ added in v0.0.4
func (client *Client) CancelOrders(param interface{}) (r CancelOrderResult, err error)
撤销订单
func (*Client) Get3MonthsBills ¶ added in v0.0.5
func (client *Client) Get3MonthsBills(optionalParams map[string]string) (r BillsResult, err error)
获取近3个月的账户流水
func (*Client) GetAccountBalance ¶
func (client *Client) GetAccountBalance(ccy string) (r AccountBalanceResult, err error)
获取交易账户中资金余额信息
func (*Client) GetAccountConfig ¶ added in v0.0.5
func (client *Client) GetAccountConfig() (r ConfigResult, err error)
获取账户配置
func (*Client) GetAccountInstruments ¶ added in v0.0.4
func (client *Client) GetAccountInstruments(params map[string]string) (r AccountInstrumentsResult, err error)
获取当前账户可交易产品的信息
func (*Client) GetAndWriteAccountInstruments ¶ added in v0.0.4
将获取的可交易产品信息并写入json文件,如写入 account-instruments.json
func (*Client) GetAndWritePublicInstruments ¶ added in v0.0.5
将获取公开产品信息并写入json文件,如写入 account-instruments.json
func (*Client) GetBills ¶ added in v0.0.5
func (client *Client) GetBills(optionalParams map[string]string) (r BillsResult, err error)
获取近7天的账户流水
func (*Client) GetBillsPlus ¶ added in v0.0.5
获取账户流水 Plus版 : 任意时间段
func (*Client) GetFundingRate ¶ added in v0.0.5
func (client *Client) GetFundingRate(instId string) (r FundingRate, err error)
获取永续合约当前资金费率
func (*Client) GetFundingRateHistory ¶ added in v0.0.5
func (client *Client) GetFundingRateHistory(instId string, optionalParams map[string]string) (r FundingRate, err error)
获取永续合约历史资金费率
func (*Client) GetKlines ¶ added in v0.0.5
Klines ================================================================================= Start: 获取K线数据 (end, start) 0->1 new->old ;最多可获取最近1440条数据。
func (*Client) GetKlinesHistory ¶ added in v0.0.5
func (client *Client) GetKlinesHistory(instId string, params map[string]string) (r Klines, err error)
获取K线历史数据。这个不行的,要看下面的Plus
func (*Client) GetKlinesHistoryPlus1 ¶ added in v0.0.5
func (client *Client) GetKlinesHistoryPlus1(instId string, params map[string]string) ([]KlineData, error)
获取K线数据 history 加强版1 (End,start],且不限时间段,不限数量。 0 --> 1 == new to old, but not include the kline(now).
func (*Client) GetKlinesHistoryPlus2 ¶ added in v0.0.5
func (client *Client) GetKlinesHistoryPlus2(instId string, params map[string]string, flag int) ([]KlineData, error)
获取K线数据 history 加强版2,且不限时间段,不限数量。 flag=0, (end, start) ; flag=1, (end, start] ; flag=2, [end, start]
func (*Client) GetKlinesSync ¶ added in v0.0.5
实时获取k线,并发送到通道ch。这个函数主要是为了方便地写入数据库。
func (*Client) GetLeverInfo ¶ added in v0.0.5
func (client *Client) GetLeverInfo(optionalParams map[string]string) (r LeverInfoResult, err error)
获取杠杆倍数
func (*Client) GetMaxAvailSize ¶ added in v0.0.5
func (client *Client) GetMaxAvailSize(params map[string]string) (r MaxAvailSizeResult, err error)
获取最大可用余额/保证金
func (*Client) GetMaxSize ¶ added in v0.0.5
func (client *Client) GetMaxSize(params map[string]string) (r MaxSizeResult, err error)
获取最大可下单数量:对应下单时的 sz 字段
func (*Client) GetPendingOrders ¶ added in v0.0.4
func (client *Client) GetPendingOrders(param map[string]string) (r SpendingOrderResult, err error)
获取未成交订单列表
func (*Client) GetPositions ¶ added in v0.0.4
func (client *Client) GetPositions(optionalParams map[string]string) (r PositionsResult, err error)
获取持仓信息
func (*Client) GetPublicInstruments ¶ added in v0.0.5
func (client *Client) GetPublicInstruments(params map[string]string) (r AccountInstrumentsResult, err error)
获取公开产品的信息
func (*Client) GetServerTime ¶ added in v0.0.5
func (client *Client) GetServerTime() (serverTime ServerTime, err error)
获取服务器时间
func (*Client) GetTicker ¶ added in v0.0.5
func (client *Client) GetTicker(instId string) (r TickerResult, err error)
获取单个产品行情信息
func (*Client) GetTickerType ¶ added in v0.0.5
func (client *Client) GetTickerType(instType string) (r TickerResult, err error)
获取指定类型的行情信息
func (*Client) GetTradeFee ¶ added in v0.0.5
func (client *Client) GetTradeFee(params map[string]string) (r TradeFeeResult, err error)
获取当前账户交易手续费率
func (*Client) GetTradeOrderInfo ¶ added in v0.0.4
func (client *Client) GetTradeOrderInfo(param map[string]string) (r TradeOrderInfoResult, err error)
获取订单信息
func (*Client) Request ¶
func (client *Client) Request(method string, requestPath string, params, result interface{}) (response *http.Response, err error)
发送请求,然后返回响应
func (*Client) SetLever ¶ added in v0.0.5
func (client *Client) SetLever(leverParam interface{}) (r LeverResult, err error)
设置杠杠倍数
func (*Client) TradeOrder ¶ added in v0.0.4
func (client *Client) TradeOrder(orderParam interface{}) (r OrderResult, err error)
下单函数
type Config ¶
type ConfigResult ¶
type ConfigResult struct {
ApiCodeMsg
Data []AccConfig `json:"data"`
}
type Currencies ¶
type Currencies struct {
Ccy string `json:"ccy"`
Name string `json:"name"`
Chain string `json:"chain"`
CanDep bool `json:"canDep"`
CanWd bool `json:"canWd"`
CanInternal bool `json:"canInternal"`
MinWd string `json:"minWd"`
MinFee string `json:"minFee"`
MaxFee string `json:"maxFee"`
}
资金账户: Asset =========================================================== Start: 获取币种列表
type CurrenciesResult ¶
type CurrenciesResult struct {
ApiCodeMsg
Data []Currencies `json:"data"`
}
type FundingRate ¶ added in v0.0.5
type FundingRate struct {
ApiCodeMsg
Data []FundingRateData `json:"data"`
}
type FundingRateData ¶ added in v0.0.5
type FundingRateData struct {
InstType string `json:"instType" db:"instType"`
InstId string `json:"instId" db:"instId"`
FundingRate string `json:"fundingRate" db:"fundingRate"`
FundingTime string `json:"fundingTime" db:"fundingTime"`
RealizedRate string `json:"realizedRate" db:"realizedRate"` // 获取历史资金费率返回这个
NextFundingRate string `json:"nextFundingRate" db:"nextFundingRate"` // 获取当前资金费率返回这个
}
资金费率
type KlineDataS ¶ added in v0.0.5
type KlineDataS struct {
Ts string `json:"ts" db:"ts"`
O string `json:"o" db:"o"`
H string `json:"h" db:"h"`
L string `json:"l" db:"l"`
C string `json:"c" db:"c"`
Vol string `json:"vol" db:"vol"`
VolCcy string `json:"volCcy" db:"volCcy"`
VolCcyQuote string `json:"volCcyQuote" db:"volCcyQuote"`
Confirm string `json:"confirm" db:"confirm"`
Tstocst string `json:"tstocst" db:"tstocst"` // 这个我自己加上去的,方便看时间
}
Kline: 该格式主要用于数据库查询和插入kline
type Klines ¶ added in v0.0.5
type Klines struct {
ApiCodeMsg
Data []KlineData `json:"data"`
}
type of kline:
type LeverInfo ¶
type LeverInfo struct {
InstId string `json:"instId"`
MgnMode string `json:"mgnMode"`
PosSide string `json:"posSide"`
Lever string `json:"lever"`
}
查询杠杠倍数
type LeverInfoResult ¶
type LeverInfoResult struct {
ApiCodeMsg
Data []LeverInfo `json:"data"`
}
type LeverParam ¶
type LeverParam struct {
InstId string `json:"instId"`
Ccy string `json:"ccy"`
Lever string `json:"lever"`
MgnMode string `json:"mgnMode"` // isolated, cross
PosSide string `json:"posSide"` // long, short
}
设置杠杠时提交的参数
type LeverResult ¶
type LeverResult struct {
ApiCodeMsg
Data []BaseLeverResult `json:"data"`
}
type MaxAvailSize ¶
type MaxAvailSize struct {
InstId string `json:"instId"`
AvailBuy string `json:"availBuy"`
AvailSell string `json:"availSell"`
}
获取最大可用余额/保证金
type MaxAvailSizeResult ¶
type MaxAvailSizeResult struct {
ApiCodeMsg
Data []MaxAvailSize `json:"data"`
}
type MaxSize ¶
type MaxSize struct {
InstId string `json:"instId"`
Ccy string `json:"ccy"`
MaxBuy string `json:"maxBuy"`
MaxSell string `json:"maxSell"`
}
获取最大可下单数量:对应下单时的 sz 字段
type MaxSizeResult ¶
type MaxSizeResult struct {
ApiCodeMsg
Data []MaxSize `json:"data"`
}
type MyMacdClass ¶ added in v0.0.5
type MyMacdClass struct {
Date []string // ts or str???
Close []float64
Dif []float64
Dea []float64
Hist []float64
Fast int
Slow int
Signal int
}
构建 MyMacdClass 类
func (*MyMacdClass) Append ¶ added in v0.0.5
func (mymacd *MyMacdClass) Append(close1 float64)
添加数据 add date???
func (*MyMacdClass) CrossOver ¶ added in v0.0.5
func (mymacd *MyMacdClass) CrossOver(pos int) bool
close数组约定 old ---> new n 表示从new往old方向的位移 pos 标识确切位置 0,1,2,3...N-1 判断金叉
func (*MyMacdClass) CrossOverTwice ¶ added in v0.0.5
func (mymacd *MyMacdClass) CrossOverTwice(pos int) bool
判断低位二次金叉
func (*MyMacdClass) CrossUnder ¶ added in v0.0.5
func (mymacd *MyMacdClass) CrossUnder(pos int) bool
判断死叉
func (*MyMacdClass) CrossUnderTwice ¶ added in v0.0.5
func (mymacd *MyMacdClass) CrossUnderTwice(pos int) bool
判断高位二次死叉
func (*MyMacdClass) CsToFloat64 ¶ added in v0.0.5
func (mymacd *MyMacdClass) CsToFloat64(cs []string) []float64
将 cs:[]string ---> closeData:[]float64
func (*MyMacdClass) Init ¶ added in v0.0.5
func (mymacd *MyMacdClass) Init(closeData []float64, fast int, slow int, signal int)
初始化
func (*MyMacdClass) OverZero ¶ added in v0.0.5
func (mymacd *MyMacdClass) OverZero(pos int) bool
判断是否0轴上方
func (*MyMacdClass) UnderZero ¶ added in v0.0.5
func (mymacd *MyMacdClass) UnderZero(pos int) bool
判断是否0轴下方
func (*MyMacdClass) Up3Hist ¶ added in v0.0.5
func (mymacd *MyMacdClass) Up3Hist(pos int) bool
判断是否连续上涨3个Hist
func (*MyMacdClass) UpHist ¶ added in v0.0.5
func (mymacd *MyMacdClass) UpHist(pos int) bool
判断是否上涨 Hist
type MyMariaDBClass ¶ added in v0.0.5
构建 MyMariaDB 类
func (*MyMariaDBClass) CheckTableExists ¶ added in v0.0.5
func (mydb *MyMariaDBClass) CheckTableExists(table string) bool
查询表是否存在
func (*MyMariaDBClass) Connect ¶ added in v0.0.5
func (mydb *MyMariaDBClass) Connect(user, passwd, ip, port, dbName string) error
连接
func (*MyMariaDBClass) CreateGameData2 ¶ added in v0.0.5
func (mydb *MyMariaDBClass) CreateGameData2() (r []KlineDataS)
生成测试数据 for game
func (*MyMariaDBClass) CreateTable ¶ added in v0.0.5
func (mydb *MyMariaDBClass) CreateTable(table string) error
创建表
func (*MyMariaDBClass) CreateTradeGameData3 ¶ added in v0.0.5
func (mydb *MyMariaDBClass) CreateTradeGameData3(a bool, b bool, bar string) (r []KlineDataS, stock string, name string)
生成测试数据 for tradegame 混合大A和加密币。3:返回 股票名称
func (*MyMariaDBClass) DeleteTable ¶ added in v0.0.5
func (mydb *MyMariaDBClass) DeleteTable(table string) (err error)
删除表
func (*MyMariaDBClass) GetRowCount ¶ added in v0.0.8
func (mydb *MyMariaDBClass) GetRowCount(table string) (int, error)
查:表的行数
func (*MyMariaDBClass) Init ¶ added in v0.0.5
func (mydb *MyMariaDBClass) Init(user, passwd, ip, port, dbName string) (err error)
快速初始化
func (*MyMariaDBClass) InsertDict ¶ added in v0.0.5
func (mydb *MyMariaDBClass) InsertDict(table string, dict map[string]string) (err error)
增
func (*MyMariaDBClass) InsertStructs ¶ added in v0.0.5
func (mydb *MyMariaDBClass) InsertStructs(table string, items interface{}) (err error)
增:0 -> 1 == old -> new
func (*MyMariaDBClass) InsertUseIdAndBar ¶ added in v0.0.5
func (mydb *MyMariaDBClass) InsertUseIdAndBar(c *Client, id string, bar string, start string, end string, table string, history bool) error
get(from server) --> save(to maria) [a, b) id, bar, start, end, table, history:是否使用历史接口 history is false: 获取当前变化中的kline,confirm=0,这个不宜插入到数据库
func (*MyMariaDBClass) InsertUseIdAndBar2 ¶ added in v0.0.5
func (mydb *MyMariaDBClass) InsertUseIdAndBar2(c *Client, id string, bar string, start string, end string, table string, history bool) error
InsertUseIdAndBar2 : 重构 InsertUseIdAndBar get(from server) --> 检查数据 --> save(to maria) [a, b) id, bar, start, end, table, history:是否使用历史接口 history is false: 获取当前变化中的kline,confirm=0,这个不宜插入到数据库
func (*MyMariaDBClass) InsertUseIdAndBarSync ¶ added in v0.0.5
func (maria *MyMariaDBClass) InsertUseIdAndBarSync(c *Client, id string, bar string, start string)
实时同步K线数据(有sleep,阻塞式函数,最好goroutine运行)
func (*MyMariaDBClass) InsertUseIdAndBarSyncCh ¶ added in v0.0.5
func (mydb *MyMariaDBClass) InsertUseIdAndBarSyncCh(c *Client, id string, bar string, start string)
实时同步K线数据(有sleep,使用goroutine运行,并根据最新的GetKlinsSync函数进行修改。)
func (*MyMariaDBClass) Query ¶ added in v0.0.5
func (mydb *MyMariaDBClass) Query(r interface{}, sql string) (err error)
查
func (*MyMariaDBClass) QueryClose ¶ added in v0.0.5
获取close价格,以用于计算macd等。
func (*MyMariaDBClass) QueryNum ¶ added in v0.0.5
func (mydb *MyMariaDBClass) QueryNum(r interface{}, table string, direct int, limit int) (err error)
查: 正向或反向(-1),查询n条数据
func (*MyMariaDBClass) QueryRand ¶ added in v0.0.5
func (mydb *MyMariaDBClass) QueryRand(r interface{}, table string, n int) (err error)
查:随机n条
func (*MyMariaDBClass) QueryStartEnd ¶ added in v0.0.5
func (mydb *MyMariaDBClass) QueryStartEnd(r interface{}, table string, start string, end string) (err error)
查:根据时间范围 [a, b] 查询
func (*MyMariaDBClass) RenameTableToLower ¶ added in v0.1.1
func (mydb *MyMariaDBClass) RenameTableToLower() error
RenameTable 将数据库中所有表名转换为小写 一次性函数
type OrderResult ¶ added in v0.0.4
type OrderResult struct {
ApiCodeMsg
Data []BaseOrderResult `json:"data"`
}
下单返回的数据结构,完整的
type PositionModeParam ¶
type PositionModeParam struct {
PosMode string `json:"posMode"`
}
设置持仓模式时提交的参数
type Positions ¶
type Positions struct {
InstId string `json:"instId"`
InstType string `json:"instType"`
MgnMode string `json:"mgnMode"`
PosId string `json:"posId"`
PosSide string `json:"posSide"`
Pos string `json:"pos"`
AvailPos string `json:"availPos"`
AvgPx string `json:"avgPx"`
Upl string `json:"upl"`
UplRatio string `json:"uplRatio"`
Lever string `json:"lever"`
Last string `json:"last"`
CTime string `json:"cTime"`
UTime string `json:"uTime"`
Imr string `json:"imr"`
Mmr string `json:"mmr"`
Margin string `json:"margin"`
MgnRatio string `json:"mgnRatio"`
}
持仓信息
type PositionsResult ¶
type PositionsResult struct {
ApiCodeMsg
Data []Positions `json:"data"`
}
type ServerTime ¶ added in v0.0.5
type SpendingOrderResult ¶ added in v0.0.4
type SpendingOrderResult struct {
ApiCodeMsg
Data []BaseSpendingOrderResult `json:"data"`
}
type SwapOrderParam ¶ added in v0.0.4
type SwapOrderParam struct {
InstId string `json:"instId"`
TdMode string `json:"tdMode"` // isolated, cross
Side string `json:"side"` // buy, sell
PosSide string `json:"posSide"` // long, short
OrdType string `json:"OrdType"` //market, limit, post_only, fok, ioc
Sz string `json:"sz"` // 数量
Px string `json:"px"` // 价格
}
Swap 下单参数
type TickerResult ¶ added in v0.0.5
type TickerResult struct {
ApiCodeMsg
Data []BaseTickerResult `json:"data"`
}
type TradeFee ¶
type TradeFee struct {
Level string `json:"level"`
Maker string `json:"maker"`
Taker string `json:"taker"`
MakerU string `json:"makerU"` // USDT 合约
TakerU string `json:"takerU"`
Delivery string `json:"delivery"` // 交割
}
获取当前账户交易手续费率
type TradeFeeResult ¶
type TradeFeeResult struct {
ApiCodeMsg
Data []TradeFee `json:"data"`
}
type TradeOrderInfoResult ¶ added in v0.0.4
type TradeOrderInfoResult struct {
ApiCodeMsg
Data []BaseTradeOrderInfoResult `json:"data"`
}