FTX: Funding rates, payments & stats + order manager tracking (#976)

* Adds basic PoC for calculating/retrieving position data

* A very unfortunate day of miscalculations

* Adds position summary and funding rate details to RPC

* Offline funding rate calculations

* More helpers, more stats, refining data, automated retrieval

* Adds new rpc server commands and attempts some organisation

* lower string, lower stress

* Adds ordermanager config. Fleshes outcli. Tracks positions automatically

* Adds new separation for funding payments/rates

* Combines funding rates and payments

* Fun test coverage

* ALL THE TESTS... I hope

* Fixes

* polishes ftx tests. improves perp check. Loops rates

* Final touches before nit attax

* buff 💪

* Stops NotYetImplemented spam with one simple trick!

* Some lovely little niteroos

* linteroo

* Clarifies a couple of errors to help narrow likely end user problems

* Fixes asset type bug, fixes closed position order return, fixes unset status bug

* Fixes order manager handling when no rates are available yet

* Continues on no funding rates instead. Removes err

* Don't show predicted rate if the time is zero

* Addresses scenario with no funding rate payments

* Bug fixes and commentary before updating maps to use *currency.Item

* Adds a pair key type

* Polishes pKey, fixes map order bug

* key is not a property in the event someone changes the base/quote

* Adds improvements to order processing...Breaks it all

* Shakes up the design of things by removing a function

* Fixes issues with order manager positions. Limits update range

* Fixes build issues. Identification of bad tests.

* Merges and fixes features from master and this branch

* buff linter 💪

* re-gen

* proto regen

* Addresses some nits. But not all of them.

* Fixes issue where funding rates weren't returned 🎉

* completes transition futures tracking to map[*currency.Item]map[*currency.Item]

* who did that? not me

* removes redundant check on account of being redundant and unnecessary

* so buf

* addresses nits: duplications, startTime, loops, go tidy, typos

* fixes minor mistakes

* fixes 🍣 🐻 changes to int64
This commit is contained in:
Scott
2022-08-23 12:16:50 +10:00
committed by GitHub
parent e93ee83563
commit 46cadd6f15
50 changed files with 9249 additions and 3730 deletions

View File

@@ -1135,6 +1135,54 @@
]
}
},
"/v1/getallmanagedpositions": {
"get": {
"operationId": "GoCryptoTraderService_GetAllManagedPositions",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcGetManagedPositionsResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "includeFullOrderData",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "getFundingPayments",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "includeFullFundingRates",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "includePredictedRate",
"in": "query",
"required": false,
"type": "boolean"
}
],
"tags": [
"GoCryptoTraderService"
]
}
},
"/v1/getauditevent": {
"get": {
"operationId": "GoCryptoTraderService_GetAuditEvent",
@@ -1823,6 +1871,76 @@
]
}
},
"/v1/getfundingrates": {
"get": {
"operationId": "GoCryptoTraderService_GetFundingRates",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcGetFundingRatesResponse"
}
},
"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": "pairs",
"in": "query",
"required": false,
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "multi"
},
{
"name": "startDate",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "endDate",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "includePredicted",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "includePayments",
"in": "query",
"required": false,
"type": "boolean"
}
],
"tags": [
"GoCryptoTraderService"
]
}
},
"/v1/getfuturespositions": {
"get": {
"operationId": "GoCryptoTraderService_GetFuturesPositions",
@@ -1897,13 +2015,37 @@
"format": "int64"
},
{
"name": "verbose",
"name": "overwrite",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "overwrite",
"name": "getPositionStats",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "includeFullOrderData",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "getFundingPayments",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "includeFullFundingRates",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "includePredictedRate",
"in": "query",
"required": false,
"type": "boolean"
@@ -2176,6 +2318,84 @@
]
}
},
"/v1/getmanagedposition": {
"get": {
"operationId": "GoCryptoTraderService_GetManagedPosition",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcGetManagedPositionsResponse"
}
},
"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": "includeFullOrderData",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "getFundingPayments",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "includeFullFundingRates",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "includePredictedRate",
"in": "query",
"required": false,
"type": "boolean"
}
],
"tags": [
"GoCryptoTraderService"
]
}
},
"/v1/getmarginrateshistory": {
"get": {
"operationId": "GoCryptoTraderService_GetMarginRatesHistory",
@@ -4555,32 +4775,156 @@
}
}
},
"gctrpcFundingData": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"asset": {
"type": "string"
},
"pair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
},
"startDate": {
"type": "string"
},
"endDate": {
"type": "string"
},
"rates": {
"type": "array",
"items": {
"$ref": "#/definitions/gctrpcFundingRate"
}
},
"latestRate": {
"$ref": "#/definitions/gctrpcFundingRate"
},
"upcomingRate": {
"$ref": "#/definitions/gctrpcFundingRate"
},
"paymentSum": {
"type": "string"
}
}
},
"gctrpcFundingRate": {
"type": "object",
"properties": {
"date": {
"type": "string"
},
"rate": {
"type": "string"
},
"payment": {
"type": "string"
}
}
},
"gctrpcFuturePosition": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"asset": {
"type": "string"
},
"pair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
},
"status": {
"type": "string"
},
"openingDate": {
"type": "string"
},
"openingDirection": {
"type": "string"
},
"openingPrice": {
"type": "string"
},
"openingSize": {
"type": "string"
},
"currentDirection": {
"type": "string"
},
"currentPrice": {
"type": "string"
},
"currentSize": {
"type": "string"
},
"unrealisedPnl": {
"type": "string"
},
"realisedPnl": {
"type": "string"
},
"openingDate": {
"type": "string"
},
"closingDate": {
"type": "string"
},
"orderCount": {
"type": "string",
"format": "int64"
},
"orders": {
"type": "array",
"items": {
"$ref": "#/definitions/gctrpcOrderDetails"
}
},
"positionStats": {
"$ref": "#/definitions/gctrpcFuturesPositionStats"
},
"fundingData": {
"$ref": "#/definitions/gctrpcFundingData"
}
}
},
"gctrpcFuturesPositionStats": {
"type": "object",
"properties": {
"maintenanceMarginRequirement": {
"type": "string"
},
"initialMarginRequirement": {
"type": "string"
},
"estimatedLiquidationPrice": {
"type": "string"
},
"collateralUsed": {
"type": "string"
},
"markPrice": {
"type": "string"
},
"currentSize": {
"type": "string"
},
"breakEvenPrice": {
"type": "string"
},
"averageOpenPrice": {
"type": "string"
},
"recentPnl": {
"type": "string"
},
"marginFraction": {
"type": "string"
},
"freeCollateral": {
"type": "string"
},
"totalCollateral": {
"type": "string"
}
}
},
@@ -5004,6 +5348,17 @@
}
}
},
"gctrpcGetFundingRatesResponse": {
"type": "object",
"properties": {
"fundingPayments": {
"type": "array",
"items": {
"$ref": "#/definitions/gctrpcFundingData"
}
}
}
},
"gctrpcGetFuturesPositionsResponse": {
"type": "object",
"properties": {
@@ -5108,6 +5463,17 @@
}
}
},
"gctrpcGetManagedPositionsResponse": {
"type": "object",
"properties": {
"positions": {
"type": "array",
"items": {
"$ref": "#/definitions/gctrpcFuturePosition"
}
}
}
},
"gctrpcGetMarginRatesHistoryResponse": {
"type": "object",
"properties": {
@@ -5460,12 +5826,10 @@
"type": "string"
},
"creationTime": {
"type": "string",
"format": "int64"
"type": "string"
},
"updateTime": {
"type": "string",
"format": "int64"
"type": "string"
},
"status": {
"type": "string"