How to use Swap method of order Package

Best Gauge code snippet using order.Swap

swap_api.go

Source:swap_api.go Github

copy

Full Screen

1package okex2/*3 OKEX Swap Api4 @author Lingting Fu5 @date 2018-12-276 @version 1.0.07*/8import (9 "errors"10 "strings"11)12/*13获取某个合约的持仓信息14GET /api/swap/v3/<instrument_id>/position15*/16func (client *Client) GetSwapPositionByInstrument(instrumentId string) (*SwapPosition, error) {17 sp := SwapPosition{}18 if _, err := client.Request(GET, GetInstrumentIdUri(SWAP_INSTRUMENT_POSITION, instrumentId), nil, &sp); err != nil {19 return nil, err20 }21 return &sp, nil22}23/*24所有合约持仓信息25获取所有合约的持仓信息26限速规则:1次/10s27GET /api/swap/v3/position28*/29func (client *Client) GetSwapPositions() (*SwapPositionList, error) {30 sp := SwapPositionList{}31 if _, err := client.Request(GET, SWAP_POSITION, nil, &sp); err != nil {32 return nil, err33 }34 return &sp, nil35}36func (client *Client) getSwapAccounts(uri string) (*SwapAccounts, error) {37 sa := SwapAccounts{}38 if _, err := client.Request(GET, uri, nil, &sa); err != nil {39 return nil, err40 }41 return &sa, nil42}43/*44获取所有币种合约的账户信息45HTTP请求46GET /api/swap/v3/accounts47*/48func (client *Client) GetSwapAccounts() (*SwapAccounts, error) {49 return client.getSwapAccounts(SWAP_ACCOUNTS)50}51/*52单个币种合约账户信息53HTTP请求54GET /api/swap/v3/<instrument_id>/accounts55*/56func (client *Client) GetSwapAccount(instrumentId string) (*SwapAccount, error) {57 sa := SwapAccount{}58 uri := GetInstrumentIdUri(SWAP_INSTRUMENT_ACCOUNT, instrumentId)59 if _, err := client.Request(GET, uri, nil, &sa); err != nil {60 return nil, err61 }62 return &sa, nil63}64/*65获取某个合约的杠杆倍数,持仓模式66HTTP请求67GET /api/swap/v3/accounts/<instrument_id>/settings68*/69func (client *Client) GetSwapAccountsSettingsByInstrument(instrumentId string) (*SwapAccountsSetting, error) {70 as := SwapAccountsSetting{}71 if _, err := client.Request(GET, GetInstrumentIdUri(SWAP_ACCOUNTS_SETTINGS, instrumentId), nil, &as); err != nil {72 return nil, err73 }74 return &as, nil75}76/*77设定某个合约的杠杆倍数78HTTP请求79POST /api/swap/v3/accounts/<instrument_id>/leverage80*/81func (client *Client) PostSwapAccountsLeverage(instrumentId string, leverage string, side string) (*SwapAccountsSetting, error) {82 params := make(map[string]string)83 params["leverage"] = leverage84 params["side"] = side85 as := SwapAccountsSetting{}86 if _, err := client.Request(POST, GetInstrumentIdUri(SWAP_ACCOUNTS_LEVERAGE, instrumentId), params, &as); err != nil {87 return nil, err88 }89 return &as, nil90}91/*92账单流水查询93列出账户资产流水,账户资产流水是指导致账户余额增加或减少的行为。流水会分页,每页100条数据,并且按照时间倒序排序和存储,最新的排在最前面。94HTTP请求95GET /api/swap/v3/accounts/<instrument_id>/ledger96*/97func (client *Client) GetSwapAccountLedger(instrumentId string, optionalParams map[string]string) (*SwapAccountsLedgerList, error) {98 baseUri := GetInstrumentIdUri(SWAP_ACCOUNTS_LEDGER, instrumentId)99 uri := baseUri100 if optionalParams != nil {101 uri = BuildParams(baseUri, optionalParams)102 }103 ll := SwapAccountsLedgerList{}104 if _, err := client.Request(GET, uri, nil, &ll); err != nil {105 return nil, err106 }107 return &ll, nil108}109/*110API交易提供限价单下单模式,只有当您的账户有足够的资金才能下单。一旦下单,您的账户资金将在订单生命周期内被冻结,被冻结的资金以及数量取决于订单指定的类型和参数。111HTTP请求112POST /api/swap/v3/order113*/114func (client *Client) PostSwapOrder(instrumentId string, order *BasePlaceOrderInfo) (*SwapOrderResult, error) {115 or := SwapOrderResult{}116 info := PlaceOrderInfo{*order, instrumentId}117 if _, err := client.Request(POST, SWAP_ORDER, info, &or); err != nil {118 return nil, err119 }120 return &or, nil121}122/*123批量进行下单请求。124HTTP请求125POST /api/swap/v3/orders126*/127func (client *Client) PostSwapOrders(instrumentId string, orders []*BasePlaceOrderInfo) (*SwapOrdersResult, error) {128 sor := SwapOrdersResult{}129 orderData := PlaceOrdersInfo{InstrumentId: instrumentId, OrderData: orders}130 if _, err := client.Request(POST, SWAP_ORDERS, orderData, &sor); err != nil {131 return nil, err132 }133 return &sor, nil134}135/*136撤销之前下的未完成订单。137HTTP请求138POST /api/swap/v3/cancel_order/<instrument_id>/<order_id>139*/140func (client *Client) PostSwapCancelOrder(instrumentId string, orderId string) (*SwapCancelOrderResult, error) {141 uri := "/api/swap/v3/cancel_order/" + instrumentId + "/" + orderId142 or := SwapCancelOrderResult{}143 if _, err := client.Request(POST, uri, nil, &or); err != nil {144 return nil, err145 }146 return &or, nil147}148/*149批量撤销之前下的未完成订单。150HTTP请求151POST /api/swap/v3/cancel_batch_orders/<instrument_id>152*/153func (client *Client) PostSwapBatchCancelOrders(instrumentId string, orderIds []string) (*SwapCancelOrderResult, error) {154 uri := GetInstrumentIdUri(SWAP_CANCEL_BATCH_ORDERS, instrumentId)155 or := SwapCancelOrderResult{}156 params := map[string]interface{}{}157 params["ids"] = orderIds158 if _, err := client.Request(POST, uri, params, &or); err != nil {159 return nil, err160 }161 return &or, nil162}163/*164列出您当前所有的订单信息。165HTTP请求166GET /api/swap/v3/orders/<instrument_id>167请求示例168GET /api/swap/v3/orders/BTC-USD-SWAP?status=2&from=4&limit=30169*/170func (client *Client) GetSwapOrderByInstrumentId(instrumentId string, paramMap map[string]string) (*SwapOrdersInfo, error) {171 if paramMap["status"] == "" || len(instrumentId) == 0 {172 return nil, errors.New("Request Parameter's not correct, instrument_id and status is required.")173 }174 baseUri := GetInstrumentIdUri(SWAP_INSTRUMENT_ORDER_LIST, instrumentId)175 kvParams := BuildOrderParams(paramMap)176 uri := baseUri + "?" + kvParams177 soi := SwapOrdersInfo{}178 if _, err := client.Request(GET, uri, nil, &soi); err != nil {179 return nil, err180 }181 return &soi, nil182}183/*184通过订单id获取单个订单信息。185HTTP请求186GET /api/swap/v3/orders/<instrument_id>/<order_id>187请求示例188GET /api/swap/v3/orders/BTC-USD-SWAP/64-2a-26132f931-3189*/190func (client *Client) GetSwapOrderByOrderId(instrumentId string, orderId string) (*BaseOrderInfo, error) {191 return client.GetSwapOrderById(instrumentId, orderId)192}193/*194获取订单信息195通过订单id获取单个订单信息。196限速规则:40次/2s197HTTP请求198GET /api/swap/v3/orders/<instrument_id>/<order_id>199or200GET /api/swap/v3/orders/<instrument_id>/<client_oid>201*/202func (client *Client) GetSwapOrderById(instrumentId, orderOrClientId string) (*BaseOrderInfo, error) {203 orderInfo := BaseOrderInfo{}204 baseUri := GetInstrumentIdUri(SWAP_INSTRUMENT_ORDER_BY_ID, instrumentId)205 uri := strings.Replace(baseUri, "{order_client_id}", orderOrClientId, -1)206 if _, err := client.Request(GET, uri, nil, &orderInfo); err != nil {207 return nil, err208 }209 return &orderInfo, nil210}211/*212获取最近的成交明细列表。213HTTP请求214GET /api/swap/v3/fills215请求示例216GET /api/swap/v3/fills?order_id=64-2b-16122f931-3&instrument_id=BTC-USD-SWAP&from=1&limit=50(返回BTC-USD-SWAP中order_id为64-2b-16122f931-3的订单中第1页前50笔成交信息)217*/218func (client *Client) GetSwapFills(instrumentId string, orderId string, options map[string]string) (interface{}, error) {219 m := make(map[string]string)220 m["instrument_id"] = instrumentId221 m["order_id"] = orderId222 m["from"] = options["from"]223 m["to"] = options["to"]224 m["limit"] = options["limit"]225 uri := BuildParams(SWAP_FILLS, m)226 sfi := SwapFillsInfo{}227 if _, err := client.Request(GET, uri, nil, &sfi); err != nil {228 return nil, err229 }230 return &sfi, nil231}232/*233获取可用合约的列表,这组公开接口提供了行情数据的快照,无需认证即可调用。 获取可用合约的列表,查询各合约的交易限制和价格步长等信息。234HTTP请求235GET /api/swap/v3/instruments236*/237func (client *Client) GetSwapInstruments() (*SwapInstrumentList, error) {238 sil := SwapInstrumentList{}239 if _, err := client.Request(GET, SWAP_INSTRUMENTS, nil, &sil); err != nil {240 return nil, err241 }242 return &sil, nil243}244/*245获取合约的深度列表。246HTTP请求247GET /api/swap/v3/instruments/<instrument_id>/depth248请求示例249GET /api/swap/v3/instruments/<instrument_id>/depth?size=50250*/251func (client *Client) GetSwapDepthByInstrumentId(instrumentId string, optionalSize string) (interface{}, error) {252 sid := SwapInstrumentDepth{}253 baseUri := GetInstrumentIdUri(SWAP_INSTRUMENT_DEPTH, instrumentId)254 if optionalSize != "" {255 baseUri = baseUri + "?size=" + optionalSize256 }257 if _, err := client.Request(GET, baseUri, nil, &sid); err != nil {258 return nil, err259 }260 return sid, nil261}262/*263获取平台全部合约的最新成交价、买一价、卖一价和24交易量。264HTTP请求265GET /api/swap/v3/instruments/ticker266*/267func (client *Client) GetSwapInstrumentsTicker() (*SwapTickerList, error) {268 stl := SwapTickerList{}269 if _, err := client.Request(GET, SWAP_INSTRUMENTS_TICKER, nil, &stl); err != nil {270 return nil, err271 }272 return &stl, nil273}274/*275获取合约的最新成交价、买一价、卖一价和24交易量。276HTTP请求277GET /api/swap/v3/instruments/<instrument_id>/ticker278*/279func (client *Client) GetSwapTickerByInstrument(instrumentId string) (*BaseTickerInfo, error) {280 bti := BaseTickerInfo{}281 uri := GetInstrumentIdUri(SWAP_INSTRUMENT_TICKER, instrumentId)282 if _, err := client.Request(GET, uri, nil, &bti); err != nil {283 return nil, err284 }285 bti.InstrumentId = instrumentId286 return &bti, nil287}288/*289获取合约的成交记录。290HTTP请求291GET /api/swap/v3/instruments/<instrument_id>/trades292请求示例293GET /api/swap/v3/instruments/BTC-USD-SWAP/trades?from=1&limit=50294*/295func (client *Client) GetSwapTradesByInstrument(instrumentId string, optionalParams map[string]string) (*SwapTradeList, error) {296 stl := SwapTradeList{}297 baseUri := GetInstrumentIdUri(SWAP_INSTRUMENT_TRADES, instrumentId)298 uri := BuildParams(baseUri, optionalParams)299 if _, err := client.Request(GET, uri, nil, &stl); err != nil {300 return nil, err301 }302 return &stl, nil303}304/*305获取合约的K线数据。306HTTP请求307GET /api/swap/v3/instruments/<instrument_id>/candles308请求示例309GET /api/swap/v3/instruments/BTC-USD-SWAP/candles?start=2018-10-26T02:31:00.000Z&end=2018-10-26T02:55:00.000Z&granularity=60(查询BTC-USD-SWAP的2018年10月26日02点31分到2018年10月26日02点55分的1分钟K线数据)310*/311func (client *Client) GetSwapCandlesByInstrument(instrumentId string, optionalParams map[string]string) (*SwapCandleList, error) {312 scl := SwapCandleList{}313 baseUri := GetInstrumentIdUri(SWAP_INSTRUMENT_CANDLES, instrumentId)314 uri := baseUri315 if len(optionalParams) > 0 {316 uri = BuildParams(baseUri, optionalParams)317 }318 if _, err := client.Request(GET, uri, nil, &scl); err != nil {319 return nil, err320 }321 return &scl, nil322}323/*324获取币种指数。325HTTP请求326GET /api/swap/v3/instruments/<instrument_id>/index327请求示例328GET /api/swap/v3/instruments/BTC-USD-SWAP/index329*/330func (client *Client) GetSwapIndexByInstrument(instrumentId string) (*SwapIndexInfo, error) {331 sii := SwapIndexInfo{}332 if _, err := client.Request(GET, GetInstrumentIdUri(SWAP_INSTRUMENT_INDEX, instrumentId), nil, &sii); err != nil {333 return nil, err334 }335 return &sii, nil336}337/*338获取合约整个平台的总持仓量。339HTTP请求340GET /api/swap/v3/instruments/<instrument_id>/open_interest341*/342func (client *Client) GetSwapOpenInterestByInstrument(instrumentId string) (*SwapOpenInterest, error) {343 sii := SwapOpenInterest{}344 if _, err := client.Request(GET, GetInstrumentIdUri(SWAP_INSTRUMENT_OPEN_INTEREST, instrumentId), nil, &sii); err != nil {345 return nil, err346 }347 return &sii, nil348}349/*350获取合约当前开仓的最高买价和最低卖价。351HTTP请求352GET /api/swap/v3/instruments/<instrument_id>/price_limit353*/354func (client *Client) GetSwapPriceLimitByInstrument(instrumentId string) (*SwapPriceLimit, error) {355 sii := SwapPriceLimit{}356 if _, err := client.Request(GET, GetInstrumentIdUri(SWAP_INSTRUMENT_PRICE_LIMIT, instrumentId), nil, &sii); err != nil {357 return nil, err358 }359 return &sii, nil360}361/*362获取合约爆仓单。363HTTP请求364GET /api/swap/v3/instruments/<instrument_id>/liquidation365请求示例366GET /api/swap/v3/instruments/BTC-USD-SWAP/liquidation?status=0&from=1&limit=50367*/368func (client *Client) GetSwapLiquidationByInstrument(instrumentId string, status string, optionalParams map[string]string) (*SwapLiquidationList, error) {369 scl := SwapLiquidationList{}370 baseUri := GetInstrumentIdUri(SWAP_INSTRUMENT_LIQUIDATION, instrumentId)371 uri := baseUri372 if optionalParams != nil {373 optionalParams["status"] = status374 uri = BuildParams(baseUri, optionalParams)375 } else {376 oParams := map[string]string{}377 oParams["status"] = status378 uri = BuildParams(baseUri, oParams)379 }380 if _, err := client.Request(GET, uri, nil, &scl); err != nil {381 return nil, err382 }383 return &scl, nil384}385/*386获取合约挂单冻结数量。387HTTP请求388GET /api/swap/v3/accounts/<instrument_id>/holds389*/390func (client *Client) GetSwapAccountsHoldsByInstrument(instrumentId string) (*SwapAccountHolds, error) {391 r := SwapAccountHolds{}392 if _, err := client.Request(GET, GetInstrumentIdUri(SWAP_ACCOUNTS_HOLDS, instrumentId), nil, &r); err != nil {393 return nil, err394 }395 return &r, nil396}397/*398获取合约下一次的结算时间。399HTTP请求400GET /api/swap/v3/instruments/<instrument_id>/funding_time401*/402func (client *Client) GetSwapFundingTimeByInstrument(instrumentId string) (*SwapFundingTime, error) {403 r := SwapFundingTime{}404 if _, err := client.Request(GET, GetInstrumentIdUri(SWAP_INSTRUMENT_FUNDING_TIME, instrumentId), nil, &r); err != nil {405 return nil, err406 }407 return &r, nil408}409/*410获取合约标记价格。411HTTP请求412GET /api/swap/v3/instruments/<instrument_id>/mark_price413*/414func (client *Client) GetSwapMarkPriceByInstrument(instrumentId string) (*SwapMarkPrice, error) {415 r := SwapMarkPrice{}416 if _, err := client.Request(GET, GetInstrumentIdUri(SWAP_INSTRUMENT_MARK_PRICE, instrumentId), nil, &r); err != nil {417 return nil, err418 }419 return &r, nil420}421/*422获取合约历史资金费率。423HTTP请求424GET /api/swap/v3/instruments/<instrument_id>/historical_funding_rate425请求示例426GET /api/swap/v3/instruments/BTC-USD-SWAP/historical_funding_rate?from=1&limit=50427*/428func (client *Client) GetSwapHistoricalFundingRateByInstrument(instrumentId string, optionalParams map[string]string) (*SwapHistoricalFundingRateList, error) {429 r := SwapHistoricalFundingRateList{}430 baseUri := GetInstrumentIdUri(SWAP_INSTRUMENT_HISTORICAL_FUNDING_RATE, instrumentId)431 uri := baseUri432 if optionalParams != nil {433 uri = BuildParams(baseUri, optionalParams)434 }435 if _, err := client.Request(GET, uri, nil, &r); err != nil {436 return nil, err437 }438 return &r, nil439}440/*441获取法币汇率。442HTTP请求443GET /api/swap/v3/rate444*/445func (client *Client) GetSwapRate() (*SwapRate, error) {446 sr := SwapRate{}447 if _, err := client.Request(GET, SWAP_RATE, nil, &sr); err != nil {448 return nil, err449 }450 return &sr, nil451}...

Full Screen

Full Screen

uri_constants.go

Source:uri_constants.go Github

copy

Full Screen

1package okex2/*3 OKEX api config info4 @author Lingting Fu5 @date 2018-12-276 @version 1.0.07*/8const (9 OKEX_TIME_URI = "/api/general/v3/time"10 ACCOUNT_CURRENCIES = "/api/account/v3/currencies"11 ACCOUNT_DEPOSIT_ADDRESS = "/api/account/v3/deposit/address"12 ACCOUNT_DEPOSIT_HISTORY = "/api/account/v3/deposit/history"13 ACCOUNT_DEPOSIT_HISTORY_CURRENCY = "/api/account/v3/deposit/history/{currency}"14 ACCOUNT_LEDGER = "/api/account/v3/ledger"15 ACCOUNT_WALLET = "/api/account/v3/wallet"16 ACCOUNT_WALLET_CURRENCY = "/api/account/v3/wallet/{currency}"17 ACCOUNT_WITHRAWAL = "/api/account/v3/withdrawal"18 ACCOUNT_WITHRAWAL_FEE = "/api/account/v3/withdrawal/fee"19 ACCOUNT_WITHRAWAL_HISTORY = "/api/account/v3/withdrawal/history"20 ACCOUNT_WITHRAWAL_HISTORY_CURRENCY = "/api/account/v3/withdrawal/history/{currency}"21 ACCOUNT_TRANSFER = "/api/account/v3/transfer"22 FUTURES_RATE = "/api/futures/v3/rate"23 FUTURES_INSTRUMENTS = "/api/futures/v3/instruments"24 FUTURES_CURRENCIES = "/api/futures/v3/instruments/currencies"25 FUTURES_INSTRUMENT_BOOK = "/api/futures/v3/instruments/{instrument_id}/book"26 FUTURES_TICKERS = "/api/futures/v3/instruments/ticker"27 FUTURES_INSTRUMENT_TICKER = "/api/futures/v3/instruments/{instrument_id}/ticker"28 FUTURES_INSTRUMENT_TRADES = "/api/futures/v3/instruments/{instrument_id}/trades"29 FUTURES_INSTRUMENT_CANDLES = "/api/futures/v3/instruments/{instrument_id}/candles"30 FUTURES_INSTRUMENT_MARK_PRICE = "/api/futures/v3/instruments/{instrument_id}/mark_price"31 FUTURES_INSTRUMENT_INDEX = "/api/futures/v3/instruments/{instrument_id}/index"32 FUTURES_INSTRUMENT_ESTIMATED_PRICE = "/api/futures/v3/instruments/{instrument_id}/estimated_price"33 FUTURES_INSTRUMENT_OPEN_INTEREST = "/api/futures/v3/instruments/{instrument_id}/open_interest"34 FUTURES_INSTRUMENT_PRICE_LIMIT = "/api/futures/v3/instruments/{instrument_id}/price_limit"35 FUTURES_INSTRUMENT_LIQUIDATION = "/api/futures/v3/instruments/{instrument_id}/liquidation"36 FUTURES_POSITION = "/api/futures/v3/position"37 FUTURES_INSTRUMENT_POSITION = "/api/futures/v3/{instrument_id}/position"38 FUTURES_ACCOUNTS = "/api/futures/v3/accounts"39 FUTURES_ACCOUNT_CURRENCY_INFO = "/api/futures/v3/accounts/{currency}"40 FUTURES_ACCOUNT_CURRENCY_LEDGER = "/api/futures/v3/accounts/{currency}/ledger"41 FUTURES_ACCOUNT_CURRENCY_LEVERAGE = "/api/futures/v3/accounts/{currency}/leverage"42 FUTURES_ACCOUNT_INSTRUMENT_HOLDS = "/api/futures/v3/accounts/{instrument_id}/holds"43 FUTURES_ORDER = "/api/futures/v3/order"44 FUTURES_ORDERS = "/api/futures/v3/orders"45 FUTURES_INSTRUMENT_ORDER_LIST = "/api/futures/v3/orders/{instrument_id}"46 FUTURES_INSTRUMENT_ORDER_INFO = "/api/futures/v3/orders/{instrument_id}/{order_id}"47 FUTURES_INSTRUMENT_ORDER_CANCEL = "/api/futures/v3/cancel_order/{instrument_id}/{order_id}"48 FUTURES_INSTRUMENT_ORDER_BATCH_CANCEL = "/api/futures/v3/cancel_batch_orders/{instrument_id}"49 FUTURES_FILLS = "/api/futures/v3/fills"50 MARGIN_ACCOUNTS = "/api/margin/v3/accounts"51 MARGIN_ACCOUNTS_INSTRUMENT = "/api/margin/v3/accounts/{instrument_id}"52 MARGIN_ACCOUNTS_INSTRUMENT_LEDGER = "/api/margin/v3/accounts/{instrument_id}/ledger"53 MARGIN_ACCOUNTS_AVAILABILITY = "/api/margin/v3/accounts/availability"54 MARGIN_ACCOUNTS_INSTRUMENT_AVAILABILITY = "/api/margin/v3/accounts/{instrument_id}/availability"55 MARGIN_ACCOUNTS_BORROWED = "/api/margin/v3/accounts/borrowed"56 MARGIN_ACCOUNTS_INSTRUMENT_BORROWED = "/api/margin/v3/accounts/{instrument_id}/borrowed"57 MARGIN_ACCOUNTS_BORROW = "/api/margin/v3/accounts/borrow"58 MARGIN_ACCOUNTS_REPAYMENT = "/api/margin/v3/accounts/repayment"59 MARGIN_ORDERS = "/api/margin/v3/orders"60 MARGIN_BATCH_ORDERS = "/api/margin/v3/batch_orders"61 MARGIN_CANCEL_ORDERS_BY_ID = "/api/margin/v3/cancel_orders/{order_client_id}"62 MARGIN_CANCEL_BATCH_ORDERS = "/api/margin/v3/cancel_batch_orders"63 MARGIN_ORDERS_BY_ID = "/api/margin/v3/orders/{order_client_id}"64 MARGIN_ORDERS_PENDING = "/api/margin/v3/orders_pending"65 MARGIN_FILLS = "/api/margin/v3/fills"66 SPOT_ACCOUNTS = "/api/spot/v3/accounts"67 SPOT_ACCOUNTS_CURRENCY = "/api/spot/v3/accounts/{currency}"68 SPOT_ACCOUNTS_CURRENCY_LEDGER = "/api/spot/v3/accounts/{currency}/ledger"69 SPOT_ORDERS = "/api/spot/v3/orders"70 SPOT_BATCH_ORDERS = "/api/spot/v3/batch_orders"71 SPOT_CANCEL_ORDERS_BY_ID = "/api/spot/v3/cancel_orders/{order_client_id}"72 SPOT_CANCEL_BATCH_ORDERS = "/api/spot/v3/cancel_batch_orders"73 SPOT_ORDERS_PENDING = "/api/spot/v3/orders_pending"74 SPOT_ORDERS_BY_ID = "/api/spot/v3/orders/{order_client_id}"75 SPOT_FILLS = "/api/spot/v3/fills"76 SPOT_INSTRUMENTS = "/api/spot/v3/instruments"77 SPOT_INSTRUMENT_BOOK = "/api/spot/v3/instruments/{instrument_id}/book"78 SPOT_INSTRUMENTS_TICKER = "/api/spot/v3/instruments/ticker"79 SPOT_INSTRUMENT_TICKER = "/api/spot/v3/instruments/{instrument_id}/ticker"80 SPOT_INSTRUMENT_TRADES = "/api/spot/v3/instruments/{instrument_id}/trades"81 SPOT_INSTRUMENT_CANDLES = "/api/spot/v3/instruments/{instrument_id}/candles"82 SWAP_INSTRUMENT_ACCOUNT = "/api/swap/v3/{instrument_id}/accounts"83 SWAP_INSTRUMENT_POSITION = "/api/swap/v3/{instrument_id}/position"84 SWAP_ACCOUNTS = "/api/swap/v3/accounts"85 SWAP_ACCOUNTS_HOLDS = "/api/swap/v3/accounts/{instrument_id}/holds"86 SWAP_ACCOUNTS_LEDGER = "/api/swap/v3/accounts/{instrument_id}/ledger"87 SWAP_ACCOUNTS_LEVERAGE = "/api/swap/v3/accounts/{instrument_id}/leverage"88 SWAP_ACCOUNTS_SETTINGS = "/api/swap/v3/accounts/{instrument_id}/settings"89 SWAP_FILLS = "/api/swap/v3/fills"90 SWAP_INSTRUMENTS = "/api/swap/v3/instruments"91 SWAP_INSTRUMENTS_TICKER = "/api/swap/v3/instruments/ticker"92 SWAP_INSTRUMENT_CANDLES = "/api/swap/v3/instruments/{instrument_id}/candles"93 SWAP_INSTRUMENT_DEPTH = "/api/swap/v3/instruments/{instrument_id}/depth"94 SWAP_INSTRUMENT_FUNDING_TIME = "/api/swap/v3/instruments/{instrument_id}/funding_time"95 SWAP_INSTRUMENT_HISTORICAL_FUNDING_RATE = "/api/swap/v3/instruments/{instrument_id}/historical_funding_rate"96 SWAP_INSTRUMENT_INDEX = "/api/swap/v3/instruments/{instrument_id}/index"97 SWAP_INSTRUMENT_LIQUIDATION = "/api/swap/v3/instruments/{instrument_id}/liquidation"98 SWAP_INSTRUMENT_MARK_PRICE = "/api/swap/v3/instruments/{instrument_id}/mark_price"99 SWAP_INSTRUMENT_OPEN_INTEREST = "/api/swap/v3/instruments/{instrument_id}/open_interest"100 SWAP_INSTRUMENT_PRICE_LIMIT = "/api/swap/v3/instruments/{instrument_id}/price_limit"101 SWAP_INSTRUMENT_TICKER = "/api/swap/v3/instruments/{instrument_id}/ticker"102 SWAP_INSTRUMENT_TRADES = "/api/swap/v3/instruments/{instrument_id}/trades"103 SWAP_INSTRUMENT_ORDER_LIST = "/api/swap/v3/orders/{instrument_id}"104 SWAP_INSTRUMENT_ORDER_BY_ID = "/api/swap/v3/orders/{instrument_id}/{order_client_id}"105 SWAP_RATE = "/api/swap/v3/rate"106 SWAP_ORDER = "/api/swap/v3/order"107 SWAP_ORDERS = "/api/swap/v3/orders"108 SWAP_POSITION = "/api/swap/v3/position"109 SWAP_CANCEL_BATCH_ORDERS = "/api/swap/v3/cancel_batch_orders/{instrument_id}"110 SWAP_CANCEL_ORDER = "/api/swap/v3/cancel_order/{instrument_id}/{order_id}"111)...

Full Screen

Full Screen

swap_test.go

Source:swap_test.go Github

copy

Full Screen

1package okex2/*3 OKEX Swap Rest Api. Unit test4 @author Lingting Fu5 @date 2018-12-276 @version 1.0.07*/8import (9 "fmt"10 "github.com/stretchr/testify/assert"11 "os"12 "reflect"13 "testing"14 "time"15)16func TestGetSwapInstrumentPosition(t *testing.T) {17 c := NewTestClient()18 sp, err := c.GetSwapPositionByInstrument("BTC-USD-SWAP")19 assert.True(t, err == nil)20 jstr, _ := Struct2JsonString(sp)21 println(jstr)22}23func TestGetSwapPositions(t *testing.T) {24 c := NewTestClient()25 sp, err := c.GetSwapPositions()26 simpleAssertTrue(sp, err, t, false)27}28func TestGetSwapAccount(t *testing.T) {29 c := NewTestClient()30 sa, err := c.GetSwapAccount("BTC-USD-SWAP")31 simpleAssertTrue(sa, err, t, false)32}33type JsonTestType struct {34 Asks [][]interface{} `json:"asks"`35}36func TestJson(t *testing.T) {37 a := string(`{"asks" : [["411.5","9",4,3]]}`)38 i := JsonTestType{}39 JsonString2Struct(a, &i)40 simpleAssertTrue(i, nil, t, false)41 str, _ := Struct2JsonString(i)42 println(str)43}44func TestMap(t *testing.T) {45 m := map[string]string{}46 m["a"] = "1999"47 r := m["b"]48 assert.True(t, r == "" && len(r) == 0)49 r2 := m["a"]50 assert.True(t, r2 == "1999")51}52func TestClient_PublicAPI(t *testing.T) {53 c := NewTestClient()54 instrumentId := "BTC-USD-SWAP"55 histList, err := c.GetSwapHistoricalFundingRateByInstrument(instrumentId, nil)56 fmt.Printf("%+v", err)57 assert.True(t, histList != nil && err == nil)58 fmt.Printf("%+v", histList)59 r, err := c.GetSwapMarkPriceByInstrument(instrumentId)60 fmt.Printf("Result: %+v, Error: %+v", r, err)61 assert.True(t, r != nil && err == nil)62 r1, err := c.GetSwapFundingTimeByInstrument(instrumentId)63 fmt.Printf("Result: %+v, Error: %+v", r1, err)64 assert.True(t, r1 != nil && err == nil)65 r2, err := c.GetSwapAccountsHoldsByInstrument(instrumentId)66 fmt.Printf("Result: %+v, Error: %+v", r2, err)67 assert.True(t, r2 != nil && err == nil)68 r3, err := c.GetSwapLiquidationByInstrument(instrumentId, "1", nil)69 fmt.Printf("Result: %+v, Error: %+v", r3, err)70 assert.True(t, r3 != nil && err == nil)71 optionalParams := map[string]string{}72 optionalParams["from"] = "1"73 optionalParams["to"] = "5"74 optionalParams["limit"] = "50"75 r4, err := c.GetSwapLiquidationByInstrument(instrumentId, "0", optionalParams)76 fmt.Printf("Result: %+v, Error: %+v", r4, err)77 assert.True(t, r4 != nil && err == nil)78 r5, err := c.GetSwapPriceLimitByInstrument(instrumentId)79 fmt.Printf("Result: %+v, Error: %+v", r5, err)80 assert.True(t, r5 != nil && err == nil)81 r6, err := c.GetSwapOpenInterestByInstrument(instrumentId)82 fmt.Printf("Result: %+v, Error: %+v", r6, err)83 assert.True(t, r6 != nil && err == nil)84 r7, err := c.GetSwapIndexByInstrument(instrumentId)85 fmt.Printf("Result: %+v, Error: %+v", r7, err)86 assert.True(t, r7 != nil && err == nil)87 //lingting.fu. 20190225. No Kline in test enviroment, contact LiWei to solve env problem.88 //r8, err := c.GetSwapCandlesByInstrument(instrumentId, nil)89 //fmt.Printf("Result: %+v, Error: %+v", r8, err)90 //assert.True(t, r8 != nil && err == nil)91 r9, err := c.GetSwapTradesByInstrument(instrumentId, nil)92 fmt.Printf("Result: %+v, Error: %+v", r9, err)93 assert.True(t, r9 != nil && err == nil)94 r10, err := c.GetSwapTickerByInstrument(instrumentId)95 fmt.Printf("Result: %+v, Error: %+v", r10, err)96 assert.True(t, r10 != nil && err == nil)97 r11, err := c.GetSwapInstruments()98 fmt.Printf("Result: %+v, Error: %+v", r11, err)99 assert.True(t, r11 != nil && err == nil)100 r12, err := c.GetSwapRate()101 fmt.Printf("Result: %+v, Error: %+v", r12, err)102 assert.True(t, r12 != nil && err == nil)103 r13, err := c.GetSwapInstrumentsTicker()104 simpleAssertTrue(r13, err, t, false)105 r14, err := c.GetSwapDepthByInstrumentId(instrumentId, "1")106 simpleAssertTrue(r14, err, t, false)107}108func simpleAssertTrue(result interface{}, err error, t *testing.T, doprint bool) bool {109 if doprint {110 fmt.Fprintf(os.Stderr, "Result: %+v, Error: %+v", result, err)111 }112 assert.True(t, result != nil && err == nil)113 return result != nil && err == nil114}115func TestClient_PrivateAPI(t *testing.T) {116 c := NewTestClient()117 instrumentId := "BTC-USD-SWAP"118 // Fore. 20190225. CleanUp history test order before new test start.119 cleanUpOrders(c, instrumentId)120 r1, err := c.GetSwapPositionByInstrument(instrumentId)121 simpleAssertTrue(r1, err, t, false)122 r2, err := c.GetSwapAccounts()123 simpleAssertTrue(r2, err, t, false)124 r3, err := c.GetSwapAccountsSettingsByInstrument(instrumentId)125 simpleAssertTrue(r3, err, t, false)126 r4, err := c.PostSwapAccountsLeverage(instrumentId, "20", "3")127 simpleAssertTrue(r4, err, t, false)128 r5, err := c.PostSwapAccountsLeverage(instrumentId, "50", "3")129 simpleAssertTrue(r5, err, t, false)130 assert.True(t, int(r5.Code) > 30000)131 r6, err := c.GetSwapAccountLedger(instrumentId, nil)132 simpleAssertTrue(r6, err, t, false)133 order := BasePlaceOrderInfo{}134 order.Size = "1"135 order.Type = "1"136 order.MatchPrice = "1"137 order.Price = "100"138 r7, err := c.PostSwapOrder(instrumentId, &order)139 simpleAssertTrue(r7, err, t, false)140 order2 := BasePlaceOrderInfo{}141 order2.Size = "1"142 order2.Type = "1"143 order2.MatchPrice = "1"144 order2.Price = "200"145 r8, err := c.PostSwapOrders(instrumentId, []*BasePlaceOrderInfo{&order, &order2})146 simpleAssertTrue(r8, err, t, false)147 r81, err := c.GetSwapOrderByOrderId(instrumentId, r8.OrderInfo[0].OrderId)148 simpleAssertTrue(r81, err, t, false)149 orderId := r8.OrderInfo[0].OrderId150 r9, err := c.PostSwapCancelOrder(instrumentId, orderId)151 simpleAssertTrue(r9, err, t, false)152 ids := []string{r8.OrderInfo[0].OrderId, r8.OrderInfo[1].OrderId}153 r10, err := c.PostSwapBatchCancelOrders(instrumentId, ids)154 simpleAssertTrue(r10, err, t, false)155 params := map[string]string{}156 params["status"] = "1"157 params["from"] = "1"158 params["to"] = "4"159 params["limit"] = "100"160 r11, err := c.GetSwapOrderByInstrumentId(instrumentId, params)161 simpleAssertTrue(r11, err, t, false)162 r12, err := c.GetSwapFills(instrumentId, orderId, nil)163 simpleAssertTrue(r12, err, t, false)164}165func cleanUpOrders(c *Client, instrumentId string) {166 params := NewParams()167 currentPage := 1168 params["status"] = "6"169 params["limit"] = "100"170 params["from"] = Int2String(currentPage)171 orders := []string{}172 rNotDealed, _ := c.GetSwapOrderByInstrumentId(instrumentId, params)173 for rNotDealed != nil && len(rNotDealed.OrderInfo) > 0 {174 for i := 0; i < len(rNotDealed.OrderInfo); i++ {175 if rNotDealed.OrderInfo[i].OrderId != "" && len(rNotDealed.OrderInfo[i].OrderId) > 0 {176 orders = append(orders, rNotDealed.OrderInfo[i].OrderId)177 }178 }179 delta := 10180 for i := 0; i < len(orders); i = i + delta {181 upper := i + delta182 if upper > len(orders)-1 {183 upper = len(orders) - 1184 }185 c.PostSwapBatchCancelOrders(instrumentId, orders[i:upper])186 time.Sleep(time.Millisecond * 200)187 println(i, i+delta)188 }189 currentPage += 1190 params["from"] = Int2String(currentPage)191 rNotDealed, _ = c.GetSwapOrderByInstrumentId(instrumentId, params)192 }193}194func TestClient_Err(t *testing.T) {195 c := NewTestClient()196 c.Config.Endpoint = "http://192.168.80.113:930/"197 r1, err := c.GetSwapRate()198 assert.True(t, r1 == nil && err != nil)199}200func TestClient_SwapHistoricalFundingRate(t *testing.T) {201 s := `[202 {203 "instrument_id": "BTC-USD-SWAP",204 "funding_rate": "0.00250000",205 "realized_rate": "0.00249999",206 "interest_rate": "0.00000000",207 "funding_time": "2018-12-17T12:40:26.000Z"208 }209]`210 r := SwapHistoricalFundingRateList{}211 JsonString2Struct(s, &r)212 assert.True(t, r != nil)213 assert.True(t, len(r) >= 1)214}215func TestClient_reflect(t *testing.T) {216 i := BasePlaceOrderInfo{}217 tp := reflect.TypeOf(i)218 fmt.Println(tp)219}...

Full Screen

Full Screen

Swap

Using AI Code Generation

copy

Full Screen

1import "fmt"2type order struct {3}4func (ord order) updateOrder() {5}6func (ord *order) updateOrderId() {7}8func (ord order) updateOrderIdByValue() {9}10func (ord *order) updateOrderIdByRef() {11}12func main() {13 ord := order{14 }15 ordp := &order{16 }17 update1.updateOrder()18 update2.updateOrder()19 update3.updateOrder()20 update4.updateOrder()21 fmt.Println("Order Id:", ord.ordId, "Customer Id:", ord.customerId)22 fmt.Println("Order Id:", ordp.ordId, "Customer Id:", ordp.customerId)23 fmt.Println("Order Id:", update1.ordId, "Customer Id:", update1.customerId)24 fmt.Println("Order Id:", update2.ordId, "Customer Id:", update2.customerId)25 fmt.Println("Order Id:", update3.ordId, "Customer Id:", update3.customerId)26 fmt.Println("Order Id:", update4.ordId, "Customer Id:", update4.customerId)27 fmt.Println("Order Id:", ord.ordId, "Customer Id:", ord.customerId)28 fmt.Println("Order Id:", ordp.ordId, "Customer Id:", ordp.customerId)29}30The updateOrder() method is called on the value of the order type. The updateOrder() method doesn’t

Full Screen

Full Screen

Swap

Using AI Code Generation

copy

Full Screen

1import "fmt"2type order struct {3}4func (ord order) updateOrder() {5}6func (ord *order) updateOrder1() {7}8func (ord order) updateOrder2() {9}10func main() {11ord := order{12}13fmt.Printf("Order before updation %v14ord.updateOrder()15fmt.Printf("Order after updation %v16ord.updateOrder1()17fmt.Printf("Order after updation %v18ord.updateOrder2()19fmt.Printf("Order after updation %v20}21Order before updation {1 56}22Order after updation {1 56}23Order after updation {1 56}24Order after updation {1 56}

Full Screen

Full Screen

Swap

Using AI Code Generation

copy

Full Screen

1import "fmt"2type Order struct {3}4func (order *Order) Swap(other *Order) {5}6func main() {7 order1 := Order{OrderId: 1, Quantity: 2, Price: 10}8 order2 := Order{OrderId: 2, Quantity: 4, Price: 20}9 order1.Swap(&order2)10 fmt.Println(order1)11 fmt.Println(order2)12}13{2 4

Full Screen

Full Screen

Swap

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 o := order{price: 5, quantity: 10}4 fmt.Println("Before Swap", o)5 o.swap()6 fmt.Println("After Swap", o)7}8import (9func main() {10 o := order{price: 5, quantity: 10}11 fmt.Println("Before Swap", o)12 o.swap()13 fmt.Println("After Swap", o)14}15import (16func main() {17 o := order{price: 5, quantity: 10}18 fmt.Println("Before Swap", o)19 o.swap()20 fmt.Println("After Swap", o)21}22import (23func main() {24 o := order{price: 5, quantity: 10}25 fmt.Println("Before Swap", o)26 o.swap()27 fmt.Println("After Swap", o)28}29import (30func main() {31 o := order{price: 5, quantity: 10}32 fmt.Println("Before Swap", o)33 o.swap()34 fmt.Println("After Swap", o)35}36import (37func main() {38 o := order{price: 5, quantity: 10}39 fmt.Println("Before Swap", o)40 o.swap()41 fmt.Println("After Swap", o)42}

Full Screen

Full Screen

Swap

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter two numbers")4 fmt.Scan(&a, &b)5 order := Order{a, b}6 fmt.Println("Before Swap")7 fmt.Println("a:", order.a)8 fmt.Println("b:", order.b)9 order.Swap()10 fmt.Println("After Swap")11 fmt.Println("a:", order.a)12 fmt.Println("b:", order.b)13}14type Order struct {15}16func (o *Order) Swap() {17}

Full Screen

Full Screen

Swap

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter the two numbers")4 fmt.Scan(&a)5 fmt.Scan(&b)6 fmt.Println("Before swapping")7 fmt.Println("a=", a)8 fmt.Println("b=", b)9 fmt.Println("After swapping")10 fmt.Println("a=", a)11 fmt.Println("b=", b)12}13import (14func main() {15 fmt.Println("Enter the two numbers")16 fmt.Scan(&a)17 fmt.Scan(&b)18 fmt.Println("Before swapping")19 fmt.Println("a=", a)20 fmt.Println("b=", b)21 fmt.Println("After swapping")22 fmt.Println("a=", a)23 fmt.Println("b=", b)24}

Full Screen

Full Screen

Swap

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 order1 = Order{1, 2}4 order2 = Order{3, 4}5 fmt.Println("Before Swapping")6 fmt.Println("order1: ", order1)7 fmt.Println("order2: ", order2)8 order1.Swap(order2)9 fmt.Println("After Swapping")10 fmt.Println("order1: ", order1)11 fmt.Println("order2: ", order2)12}13order1: {1 2}14order2: {3 4}15order1: {3 4}16order2: {3 4}17import "fmt"18type Order struct {19}20func (order *Order) Swap(other *Order) {21}22func main() {23 order1 = Order{1, 2}24 order2 = Order{3, 4}25 fmt.Println("Before Swapping")26 fmt.Println("order1: ", order1)27 fmt.Println("order2: ", order2)28 order1.Swap(&order2)29 fmt.Println("After Swapping")30 fmt.Println("order1: ", order1)31 fmt.Println("order2: ", order2)32}33order1: {1 2}34order2: {3 4}35order1: {3 4}36order2: {1 2}

Full Screen

Full Screen

Swap

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 order1 = Order{1, "Laptop", 1, 50000}4 order2 = Order{2, "Pen", 10, 10}5 fmt.Println("Before swapping")6 fmt.Println("Order1:", order1)7 fmt.Println("Order2:", order2)8 order1.Swap(order2)9 fmt.Println("After swapping")10 fmt.Println("Order1:", order1)11 fmt.Println("Order2:", order2)12}13import "fmt"14func main() {15 order1 = Order{1, "Laptop", 1, 50000}16 order2 = Order{2, "Pen", 10, 10}17 fmt.Println("Before swapping")18 fmt.Println("Order1:", order1)19 fmt.Println("Order2:", order2)20 order1.Swap(&order2)21 fmt.Println("After swapping")22 fmt.Println("Order1:", order1)23 fmt.Println("Order2:", order2)24}25import "fmt"26func main() {27 order1 = Order{1, "Laptop", 1, 50000}28 order2 = Order{2, "Pen", 10, 10}29 fmt.Println("Before swapping")30 fmt.Println("Order1:", order1)31 fmt.Println("Order2:", order2)32 order1.Swap(order2)33 fmt.Println("After swapping")34 fmt.Println("Order1:", order1)35 fmt.Println("Order2:", order2)36}37import "fmt"38func main() {39 order1 = Order{1, "Laptop", 1, 50000}40 order2 = Order{2, "Pen", 10, 10}41 fmt.Println("Before swapping")42 fmt.Println("Order1:", order1)43 fmt.Println("

Full Screen

Full Screen

Swap

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 order := new(Order)4 order2 := new(Order)5 order.Swap(order2)6 fmt.Printf("order = %v7 fmt.Printf("order2 = %v8}

Full Screen

Full Screen

Swap

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 order := new(Order)4 fmt.Println("Before swap")5 order.PrintOrder()6 order.Swap()7 fmt.Println("After swap")8 order.PrintOrder()9}10import (11type Order struct {12}13func (order *Order) Swap() {14 order.Price, order.Quantity = float64(order.Quantity), int(order.Price)15}16func (order *Order) PrintOrder() {17 fmt.Printf("Item: %s, Price: %f, Quantity: %d18}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful