Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nntaoli committed Jun 29, 2020
2 parents 0c6e9c2 + 8a277fd commit 5430118
Show file tree
Hide file tree
Showing 24 changed files with 438 additions and 337 deletions.
17 changes: 0 additions & 17 deletions .vscode/launch.json

This file was deleted.

13 changes: 13 additions & 0 deletions Const.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,16 @@ const (
COINBENE = "coinbene.com"
ATOP = "a.top"
)

const (
SUB_ACCOUNT = iota //子账户
SPOT // 币币交易
_
FUTURE //交割合约
C2C //法币
SPOT_MARGIN //币币杠杆交易
WALLET // 资金账户
_
TIPS //余币宝
SWAP //永续合约
)
2 changes: 2 additions & 0 deletions FutureRestAPI.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type FutureRestAPI interface {
*/
PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice, leverRate int) (string, error)

LimitFuturesOrder(currencyPair CurrencyPair, contractType, price, amount string, openType int) (*FutureOrder, error)

/**
* 取消订单
* @param symbol btc_usd:比特币 ltc_usd :莱特币
Expand Down
73 changes: 55 additions & 18 deletions Models.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ import (
)

type Order struct {
Price float64
Amount float64
AvgPrice float64
DealAmount float64
Fee float64
Cid string //客户端自定义ID
OrderID2 string
OrderID int //deprecated
OrderTime int
Status TradeStatus
Currency CurrencyPair
Side TradeSide
Type string //limit / market
OrderType int //0:default,1:maker,2:fok,3:ioc
Price float64
Amount float64
AvgPrice float64
DealAmount float64
Fee float64
Cid string //客户端自定义ID
OrderID2 string
OrderID int //deprecated
Status TradeStatus
Currency CurrencyPair
Side TradeSide
Type string //limit / market
OrderType int //0:default,1:maker,2:fok,3:ioc
OrderTime int // create timestamp
FinishedTime int64 //finished timestamp
}

type Trade struct {
Expand Down Expand Up @@ -75,7 +76,7 @@ type Ticker struct {
type FutureTicker struct {
*Ticker
ContractType string `json:"omitempty"`
ContractId int `json:"contractId"`
ContractId string `json:"contractId"`
LimitHigh float64 `json:"limitHigh,string"`
LimitLow float64 `json:"limitLow,string"`
HoldAmount float64 `json:"hold_amount,string"`
Expand All @@ -102,7 +103,8 @@ func (dr DepthRecords) Less(i, j int) bool {
}

type Depth struct {
ContractType string //for future
ContractType string `json:"contract_type,omitempty"` //for futures
ContractId string `json:"contract_id,omitempty"` // for futures
Pair CurrencyPair
UTime time.Time
AskList DepthRecords // Descending order
Expand Down Expand Up @@ -164,6 +166,7 @@ type FutureOrder struct {
LeverRate int //倍数
Fee float64 //手续费
ContractName string
FinishedTime int64 // finished timestamp
}

type FuturePosition struct {
Expand Down Expand Up @@ -202,8 +205,8 @@ type TickSize struct {
type FuturesContractInfo struct {
*TickSize
ContractVal float64 //合约面值(美元)
Delivery string //交割日期
ContractType string // 本周 this_week 次周 next_week 季度 quarter
Delivery string //交割日期
ContractType string // 本周 this_week 次周 next_week 季度 quarter
}

//api parameter struct
Expand All @@ -218,3 +221,37 @@ type RepaymentParameter struct {
BorrowParameter
BorrowId string
}


type TransferParameter struct {
Currency string `json:"currency"`
From int `json:"from"`
To int `json:"to"`
Amount float64 `json:"amount"`
SubAccount string `json:"sub_account"`
InstrumentId string `json:"instrument_id"`
ToInstrumentId string `json:"to_instrument_id"`
}

type WithdrawParameter struct {
Currency string `json:"currency"`
Amount float64 `json:"amount,string"`
Destination int `json:"destination"` //提币到(2:OKCoin国际 3:OKEx 4:数字货币地址)
ToAddress string `json:"to_address"`
TradePwd string `json:"trade_pwd"`
Fee string `json:"fee"`
}


type DepositWithdrawHistory struct {
WithdrawalId string `json:"withdrawal_id,omitempty"`
Currency string `json:"currency"`
Txid string `json:"txid"`
Amount float64 `json:"amount,string"`
From string `json:"from,omitempty"`
To string `json:"to"`
Memo string `json:"memo,omitempty"`
Fee string `json:"fee"`
Status int `json:"status,string"`
Timestamp time.Time `json:"timestamp"`
}
93 changes: 8 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<div align="center">
<img width="409" heigth="205" src="https://upload-images.jianshu.io/upload_images/6760989-dec7dc747846880e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="goex">
<img src="https://travis-ci.org/nntaoli-project/goex.svg?branch=dev"/>
<br/>
[![](logo.png)] (https://www.jetbrains.com/?from=goex)
</div>

### goex目标
Expand All @@ -15,119 +13,44 @@ goex项目是为了统一并标准化各个数字资产交易平台的接口而

| 交易所 | 行情接口 | 交易接口 | 版本号 |
| --- | --- | --- | --- |
| hbg.com | Y | Y | 1 |
| hbdm.com | Y| Y | 1 |
| okex.com | Y | Y | 3 |
| huobi.pro | Y | Y | 1 |
| hbdm.com | Y (REST / WS)| Y | 1 |
| okex.com (spot/future)| Y (REST / WS) | Y | 1 |
| okex.com (swap future) | Y | Y | 2 |
| binance.com | Y | Y | 1 |
| kucoin.com | Y | Y | 1 |
| bitstamp.net | Y | Y | 1 |
| bitfinex.com | Y | Y | 1 |
| zb.com | Y | Y | 1 |
| kraken.com | Y | Y | * |
| poloniex.com | Y | Y | * |
| aacoin.com | Y | Y | 1 |
| allcoin.ca | Y | Y | * |
| poloniex.com | Y | Y | * |
| big.one | Y | Y | 2\|3 |
| fcoin.com | Y | Y | 2 |
| hitbtc.com | Y | Y | * |
| coinex.com | Y | Y | 1 |
| exx.com | Y | Y | 1 |
| bithumb.com | Y | Y | * |
| gate.io | Y | N | 1 |
| btcbox.co.jp | Y | N | * |
| coinbig.com | Y | Y | * |
|coinbene.com|Y|Y|*|
| bittrex.com | Y | N | 1.1 |

### 安装goex库
> go get
``` go get github.com/nntaoli-project/goex ```

>建议go mod 管理依赖
```
require (
github.com/nntaoli-project/goex v1.0.4
github.com/nntaoli-project/goex latest
)
```

### 例子

```golang

package main

import (
"github.com/nntaoli-project/goex"
"github.com/nntaoli-project/goex/builder"
"log"
"time"
)

func main() {
apiBuilder := builder.NewAPIBuilder().HttpTimeout(5 * time.Second)
//apiBuilder := builder.NewAPIBuilder().HttpTimeout(5 * time.Second).HttpProxy("socks5://127.0.0.1:1080")

//build spot api
//api := apiBuilder.APIKey("").APISecretkey("").ClientID("123").Build(goex.BITSTAMP)
api := apiBuilder.APIKey("").APISecretkey("").Build(goex.HUOBI_PRO)
log.Println(api.GetExchangeName())
log.Println(api.GetTicker(goex.BTC_USD))
log.Println(api.GetDepth(2, goex.BTC_USD))
//log.Println(api.GetAccount())
//log.Println(api.GetUnfinishOrders(goex.BTC_USD))

//build future api
futureApi := apiBuilder.APIKey("").APISecretkey("").BuildFuture(goex.HBDM)
log.Println(futureApi.GetExchangeName())
log.Println(futureApi.GetFutureTicker(goex.BTC_USD, goex.QUARTER_CONTRACT))
log.Println(futureApi.GetFutureDepth(goex.BTC_USD, goex.QUARTER_CONTRACT, 5))
//log.Println(futureApi.GetFutureUserinfo()) // account
//log.Println(futureApi.GetFuturePosition(goex.BTC_USD , goex.QUARTER_CONTRACT))//position info
}

```

### websocket 使用例子

```golang
import (
"github.com/nntaoli-project/goex"
"github.com/nntaoli-project/goex/huobi"
//"github.com/nntaoli-project/goex/okcoin"
"log"
)

func main() {

//ws := okcoin.NewOKExFutureWs() //ok期货
ws := huobi.NewHbdmWs() //huobi期货
//设置回调函数
ws.SetCallbacks(func(ticker *goex.FutureTicker) {
log.Println(ticker)
}, func(depth *goex.Depth) {
log.Println(depth)
}, func(trade *goex.Trade, contract string) {
log.Println(contract, trade)
})
//订阅行情
ws.SubscribeTrade(goex.BTC_USDT, goex.NEXT_WEEK_CONTRACT)
ws.SubscribeDepth(goex.BTC_USDT, goex.QUARTER_CONTRACT, 5)
ws.SubscribeTicker(goex.BTC_USDT, goex.QUARTER_CONTRACT)
}

```

### 更多文档

[goex.TOP](https://goex.top)

### 注意事项

1. 推荐使用GoLand开发。
2. 推荐关闭自动格式化功能,代码请使用go fmt 格式化.
3. 不建议对现已存在的文件进行重新格式化,这样会导致commit特别糟糕。
4. 请用OrderID2这个字段代替OrderID
5. 请不要使用deprecated关键字标注的方法和字段,后面版本可能随时删除的
6. 交流QQ群:574829125
-----------------

donate
Expand Down
Loading

0 comments on commit 5430118

Please sign in to comment.