Binance,Okx: Add Leverage, MarginType, Positions and CollateralMode support (#1220)

* init

* surprise train commit

* basic distinctions

* the terms of binance are confusing

* renames and introduction of allocatedMargin

* add new margin funcs

* pulling out wires

* implement proper getposition stuff

* bad coding day

* investigate order manager next

* a broken mess, but a progressing one

* finally completes some usdtmargined stuff

* coinMfutures eludes me

* expand to okx

* imports fix

* completes okx wrapper implementations

* cleans and polishes before rpc implementations

* rpc setup, order manager features, exch features

* more rpc, collateral and margin things

* mini test

* looking at rpc response, expansion of features

* reorganising before the storm

* changing how futures requests work

* cleanup and tests of cli usage

* remove silly client side logic

* cleanup

* collateral package, typo fix, margin err, rpc derive

* uses convert.StringToFloat ONLY ON STRUCTS FROM THIS PR

* fix binance order history bug

* niteroos

* adds new funcs to exchange standards testing

* more post merge fixes

* fix binance

* replace simepletimeformat

* fix for merge

* merge fixes

* micro fixes

* order side now required for leverage

* fix up the rest

* global -> portfolio collateral

* Update exchanges/collateral/collateral_test.go

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

* adds fields and todos

* rm field redundancy

* lint fix oopsie daisy

* fixes panic, expands error and cli explanations (sorry shaz)

* ensures casing is appropriate for underlying

* Adds a shiny TODO

---------

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
Scott
2023-09-26 16:16:31 +10:00
committed by GitHub
parent a2ae99ed7f
commit 5f2f6f884b
67 changed files with 11558 additions and 4475 deletions

View File

@@ -176,6 +176,38 @@
]
}
},
"/v1/changepositionmargin": {
"post": {
"operationId": "GoCryptoTraderService_ChangePositionMargin",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcChangePositionMarginResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/gctrpcChangePositionMarginRequest"
}
}
],
"tags": [
"GoCryptoTraderService"
]
}
},
"/v1/converttradestocandles": {
"get": {
"operationId": "GoCryptoTraderService_ConvertTradesToCandles",
@@ -1325,6 +1357,72 @@
]
}
},
"/v1/getcollateralmode": {
"get": {
"operationId": "GoCryptoTraderService_GetCollateralMode",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcGetCollateralModeResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "exchange",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "asset",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
"GoCryptoTraderService"
]
},
"post": {
"operationId": "GoCryptoTraderService_SetCollateralMode",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcSetCollateralModeResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/gctrpcSetCollateralModeRequest"
}
}
],
"tags": [
"GoCryptoTraderService"
]
}
},
"/v1/getcommunicationrelayers": {
"get": {
"operationId": "GoCryptoTraderService_GetCommunicationRelayers",
@@ -1961,14 +2059,14 @@
]
}
},
"/v1/getfuturespositions": {
"/v1/getfuturespositionsorders": {
"get": {
"operationId": "GoCryptoTraderService_GetFuturesPositions",
"operationId": "GoCryptoTraderService_GetFuturesPositionsOrders",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcGetFuturesPositionsResponse"
"$ref": "#/definitions/gctrpcGetFuturesPositionsOrdersResponse"
}
},
"default": {
@@ -2009,6 +2107,24 @@
"required": false,
"type": "string"
},
{
"name": "underlyingPair.delimiter",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "underlyingPair.base",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "underlyingPair.quote",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "startDate",
"in": "query",
@@ -2022,53 +2138,88 @@
"type": "string"
},
{
"name": "status",
"name": "respectOrderHistoryLimits",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "syncWithOrderManager",
"in": "query",
"required": false,
"type": "boolean"
}
],
"tags": [
"GoCryptoTraderService"
]
}
},
"/v1/getfuturespositionssummary": {
"get": {
"operationId": "GoCryptoTraderService_GetFuturesPositionsSummary",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcGetFuturesPositionsSummaryResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "exchange",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "positionLimit",
"name": "asset",
"in": "query",
"required": false,
"type": "string",
"format": "int64"
"type": "string"
},
{
"name": "overwrite",
"name": "pair.delimiter",
"in": "query",
"required": false,
"type": "boolean"
"type": "string"
},
{
"name": "getPositionStats",
"name": "pair.base",
"in": "query",
"required": false,
"type": "boolean"
"type": "string"
},
{
"name": "includeFullOrderData",
"name": "pair.quote",
"in": "query",
"required": false,
"type": "boolean"
"type": "string"
},
{
"name": "getFundingPayments",
"name": "underlyingPair.delimiter",
"in": "query",
"required": false,
"type": "boolean"
"type": "string"
},
{
"name": "includeFullFundingRates",
"name": "underlyingPair.base",
"in": "query",
"required": false,
"type": "boolean"
"type": "string"
},
{
"name": "includePredictedRate",
"name": "underlyingPair.quote",
"in": "query",
"required": false,
"type": "boolean"
"type": "string"
}
],
"tags": [
@@ -2336,6 +2487,120 @@
]
}
},
"/v1/getleverage": {
"get": {
"operationId": "GoCryptoTraderService_GetLeverage",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcGetLeverageResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "exchange",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "asset",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "pair.delimiter",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "pair.base",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "pair.quote",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "underlyingPair.delimiter",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "underlyingPair.base",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "underlyingPair.quote",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "marginType",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "orderSide",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
"GoCryptoTraderService"
]
},
"post": {
"operationId": "GoCryptoTraderService_SetLeverage",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcSetLeverageResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/gctrpcSetLeverageRequest"
}
}
],
"tags": [
"GoCryptoTraderService"
]
}
},
"/v1/getloggerdetails": {
"get": {
"operationId": "GoCryptoTraderService_GetLoggerDetails",
@@ -2572,6 +2837,38 @@
]
}
},
"/v1/getmargintype": {
"post": {
"operationId": "GoCryptoTraderService_SetMarginType",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcSetMarginTypeResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/gctrpcSetMarginTypeRequest"
}
}
],
"tags": [
"GoCryptoTraderService"
]
}
},
"/v1/getorder": {
"post": {
"operationId": "GoCryptoTraderService_GetOrder",
@@ -4640,6 +4937,58 @@
}
}
},
"gctrpcChangePositionMarginRequest": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"asset": {
"type": "string"
},
"pair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
},
"marginType": {
"type": "string"
},
"originalAllocatedMargin": {
"type": "number",
"format": "double"
},
"newAllocatedMargin": {
"type": "number",
"format": "double"
},
"marginSide": {
"type": "string"
}
}
},
"gctrpcChangePositionMarginResponse": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"asset": {
"type": "string"
},
"pair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
},
"marginType": {
"type": "string"
},
"newAllocatedMargin": {
"type": "number",
"format": "double"
},
"marginSide": {
"type": "string"
}
}
},
"gctrpcCoin": {
"type": "object",
"properties": {
@@ -5251,6 +5600,42 @@
},
"totalCollateral": {
"type": "string"
},
"frozenBalance": {
"type": "string"
},
"equityOfCurrency": {
"type": "string"
},
"availableEquity": {
"type": "string"
},
"cashBalance": {
"type": "string"
},
"discountEquity": {
"type": "string"
},
"equityUsd": {
"type": "string"
},
"isolatedEquity": {
"type": "string"
},
"isolatedLiabilities": {
"type": "string"
},
"isolatedUpl": {
"type": "string"
},
"notionalLeverage": {
"type": "string"
},
"totalEquity": {
"type": "string"
},
"strategyEquity": {
"type": "string"
}
}
},
@@ -5422,6 +5807,20 @@
}
}
},
"gctrpcGetCollateralModeResponse": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"asset": {
"type": "string"
},
"collateralMode": {
"type": "string"
}
}
},
"gctrpcGetCollateralResponse": {
"type": "object",
"properties": {
@@ -5689,25 +6088,9 @@
}
}
},
"gctrpcGetFuturesPositionsResponse": {
"gctrpcGetFuturesPositionsOrdersResponse": {
"type": "object",
"properties": {
"totalOrders": {
"type": "string",
"format": "int64"
},
"subAccount": {
"type": "string"
},
"totalRealisedPnl": {
"type": "string"
},
"totalUnrealisedPnl": {
"type": "string"
},
"totalPnl": {
"type": "string"
},
"positions": {
"type": "array",
"items": {
@@ -5717,6 +6100,23 @@
}
}
},
"gctrpcGetFuturesPositionsSummaryResponse": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"asset": {
"type": "string"
},
"pair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
},
"positionStats": {
"$ref": "#/definitions/gctrpcFuturesPositionStats"
}
}
},
"gctrpcGetHistoricCandlesResponse": {
"type": "object",
"properties": {
@@ -5786,6 +6186,33 @@
}
}
},
"gctrpcGetLeverageResponse": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"asset": {
"type": "string"
},
"pair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
},
"underlyingPair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
},
"marginType": {
"type": "string"
},
"leverage": {
"type": "number",
"format": "double"
},
"orderSide": {
"type": "string"
}
}
},
"gctrpcGetLoggerDetailsResponse": {
"type": "object",
"properties": {
@@ -6543,6 +6970,34 @@
}
}
},
"gctrpcSetCollateralModeRequest": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"asset": {
"type": "string"
},
"collateralMode": {
"type": "string"
}
}
},
"gctrpcSetCollateralModeResponse": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"asset": {
"type": "string"
},
"success": {
"type": "boolean"
}
}
},
"gctrpcSetDataHistoryJobStatusRequest": {
"type": "object",
"properties": {
@@ -6579,6 +7034,59 @@
}
}
},
"gctrpcSetLeverageRequest": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"asset": {
"type": "string"
},
"pair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
},
"underlyingPair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
},
"marginType": {
"type": "string"
},
"leverage": {
"type": "number",
"format": "double"
},
"orderSide": {
"type": "string"
}
}
},
"gctrpcSetLeverageResponse": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"asset": {
"type": "string"
},
"pair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
},
"underlyingPair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
},
"marginType": {
"type": "string"
},
"orderSide": {
"type": "string"
},
"success": {
"type": "boolean"
}
}
},
"gctrpcSetLoggerDetailsRequest": {
"type": "object",
"properties": {
@@ -6590,6 +7098,40 @@
}
}
},
"gctrpcSetMarginTypeRequest": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"asset": {
"type": "string"
},
"pair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
},
"marginType": {
"type": "string"
}
}
},
"gctrpcSetMarginTypeResponse": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"asset": {
"type": "string"
},
"pair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
},
"success": {
"type": "boolean"
}
}
},
"gctrpcShutdownResponse": {
"type": "object"
},
@@ -6608,6 +7150,9 @@
},
"side": {
"type": "string"
},
"marginType": {
"type": "string"
}
}
},
@@ -6670,6 +7215,9 @@
},
"assetType": {
"type": "string"
},
"marginType": {
"type": "string"
}
}
},