diff --git a/oeml-sdk/go-ws/README.md b/oeml-sdk/go-ws/README.md new file mode 100644 index 0000000000..cbda3f850a --- /dev/null +++ b/oeml-sdk/go-ws/README.md @@ -0,0 +1,345 @@ + +## Requirements + +* Valid coin API key. Note, the free key does NOT work with OEML. +* Ensure OMEL [version 1.8789 or higher](http://coinapi-releases.s3-website-us-east-1.amazonaws.com/?prefix=oeml-api/) is used. +* Ensure OMEL is deployed to Kubernetes. See helm chart [instructions for details](https://github.com/coinapi/helm-charts) +* Ensure websocat is installed for local testing. See [instructions for details](https://github.com/vi/websocat) + + +## Installation + + +```shell +cd /path/to/workspace +go get github.com/CoinAPI/coinapi-sdk/oeml-sdk/go-ws +go mod download github.com/marvin-hansen/coinapi-sdk/oeml-sdk/go-ws +``` + +## Port-forward to Kubernetes + +In a separate terminal, run: + +```bash +kubectl port-forward svc/oeml-api-composite 8080:80 +``` + + +## Run examples: + +```bash +wget -v https://raw.githubusercontent.com/coinapi-sdk/master/oeml-sdk/go-ws/main.go + +go run main.go +``` + +## Test outgoing messages: + +Ensure Kubernetes forwarding has been disabled. +In a separate terminal, run: + +```bash +websocat -s 8080 +``` + +In the example main set the websocat to true. Set verbose only to true for very detailed loggin as it tends to flood the terminal with heartbeat messages issued every second from each connected exchange. + +```go +const ( + url = "ws://127.0.0.1:8080" + websocat = true + verbose = false + ... +) + + +``` + +Runt the example again and watch the websocket terminal logging all messages it receives. + +## Development: + + +The SDK handles each message type from OEML through an individual InvokeFunction that processes the specific message. +Therefore, an invoke function for all message types must be implemented and set during init. For example, a component handling only +account balances and positions would require an init process as outlined below: + +### Init + +```go +func NewAccountHandler(coinApi *coinapi.CoinApi) *AccountHandler { + amx := &AccountHandler{coinApi: coinApi} + amx.init() + return amx +} + +func (a *AccountHandler) init() { + balanceSnapshotInvoke := a.getBalanceSnapshotInvoke() + a.coinApi.OemlSDK.SetBalanceSnapshotInvoke(balanceSnapshotInvoke) + balanceUpdateInvoke := a.getBalanceUpdateInvoke() + a.coinApi.OemlSDK.SetBalanceUpdateInvoke(balanceUpdateInvoke) + + positionSnapshotInvoke := a.getPositionSnapshotInvoke() + a.coinApi.OemlSDK.SetPositionSnapshotInvoke(positionSnapshotInvoke) + positionUpdateInvoke := a.getPositionUpdateInvoke() + a.coinApi.OemlSDK.SetPositionUpdateInvoke(positionUpdateInvoke) +} +``` + +### InvokeFunctions + +Let's suppose the AccountHandler only extracts certain information and then sends a response message forward to another service. +Doing so requires two different Invoke functions, one for snapshots usually send following a connect or reconnect, and a second one for updates +that are received in real-time following a change. For example, the code below illustrates the InvokeFunctions required for +message forwarding: + +```go +func (a *AccountHandler) getBalanceSnapshotInvoke() t.InvokeFunction { + return func(message *t.OemlMessage) (err error) { + snapshot := message.BalanceSnapshot + exchangeID := snapshot.GetExchangeId() + rsp := a.getBalanceMessage(snapshot, false) + + if !active { // client has not been connected ... + a.addBufferEntry(rsp) // must be implemented in case snapshots arrive before a client has been connected. + return nil + } + + replyChannel := a.getReplyChannel(exchangeID) // must be implemented to send to the right channel + err = a.encConn.Publish(replyChannel, rsp) // must be implemented to send out the message + shared.LogError(err) // must be implemented to only log errors + return err + } +} +``` + +The SDK receives snapshots immediately after connection and in case system or the connected client is not immediately ready, +message buffering is required. + +### Lookup symbols + +The OEML SDK relies on two symbol identifiers. The exchange specific symbolID only applies to the connected exchange is invalid on any other exchange. +The coinAPISymbolID essentially consists of the exchange ID and the symbol ID and, as such, is a unique identifier even though the symbol can only be used +on its specific exchange. If the integration requires exchange agnostic symbol handling, for example when routing the same order to different exchanges, +then the SDK function LookupSymbolData() needs to be used to locate the actual symbol ID. The LookupSymbolData takes three arguments: + +* Exchange ID - string +* SymbolBase - string +* SymbolQuote - string + +Usage is shown in the code below: + +```go + exchangeID := msg.SymbolData.Exchange + baseID := msg.SymbolData.SymbolBase + quoteID := msg.SymbolData.SymbolQuote + + symbolData, ok := sdk.LookupSymbolData(exchangeID, baseID, quoteID) + if ok{ + symbolID := *symbolData.Symbol_id_coinapi + } +``` + +The lookup method returns a SymbolData object containing both, the exchange and coinAPI symbol, and some more details such as price and size precision. + + +### Place order + +Placing an order consists of three steps: +1. Collect parameters +2. Construct order request +3. Place request + +Because the method to construct order request takes a fair amount of parameters, it is advised to wrap these into a struct, as shown below: + +```go +type OrderConfig struct { + ExchangeID string + SymbolIdCoinApi string + ClientOrderID string + AmountOrder float64 + Price float64 + OrderSide types.OrdSide + OrderType types.OrdType + TimeInForce types.TimeInForce +} +``` + +The SDK does not provide an order configuration object because it stays as close to the OEML message specification as possible. +Furthermore, in many cases, order configuration depends on the actual integration and as such custom configuration objects usually +help to encode default values or specific parameters required during order processing and routing. The method below illustrates placing and order by using +constructing a custom order configuration: + + +```go +func (h ExecutionHandler) reqSingleOrder(msg m.EmxRequest) error { + + // lookup symbol + exchangeID := msg.SymbolData.Exchange + baseID := msg.SymbolData.SymbolBase + quoteID := msg.SymbolData.SymbolQuote + symbolData, _ := coinOeml.LookupSymbolData(exchangeID, baseID, quoteID) + symbolID := *symbolData.Symbol_id_coinapi + + // generate order using an UUID https://pkg.go.dev/github.com/google/uuid#New + id := uuid.New() + orderID := exchangeID + "-" + id.String() + cfg := h.GetCoinOrderConfig(exchangeID, symbolID, orderID, msg.OrderConfig) // must be implemented to configure custom order + return h.placeOrder(*cfg) +} +``` + +Once the order configuration is ready, then the system needs to create a request message and sends it out as shown below. + + +```go +func (h ExecutionHandler) placeOrder(oc CoinOrder) (err error) { + + exchangeID := oc.ExchangeID + symbolIdCoinApi := oc.SymbolIdCoinApi + clientOrderID := oc.ClientOrderID + amountOrder := oc.AmountOrder + price := oc.Price + orderSide := oc.OrderSide + orderType := oc.OrderType + timeInForce := oc.TimeInForce + + // build request + reqOrder := sdk.NewSingleOrderRequest(exchangeID, symbolIdCoinApi, clientOrderID, amountOrder, price, orderSide, orderType, timeInForce) + + // send order request to OEML + err = coinOeml.PlaceSingleOrder(reqOrder) + + return err +} +``` + +### Cancel order + +Canceling a single order requires only the order ID assigned in the initial request and the exchange id, as shown in the code example below. + +```go +func (h ExecutionHandler) reqCancelOrder(msg m.EmxRequest) { + exchangeID := msg.SymbolData.Exchange + clientOrderID := msg.OrderConfig.OrderRefTag + + // build request. + reqCancel := coinOeml.NewCancelSingleOrderRequest(exchangeID, clientOrderID) + + // send request + err := coinOeml.CancelSingleOrder(reqCancel) +} +``` + +When cancelling all orders, only the exchange id must be provided. + +```go +func (h ExecutionHandler) reqGlobalCancel(exchangeID string) { + + // build request. + reqCancelAll := coinOeml.NewCancelAllOrdersRequest(exchangeID) + + // send request + err := coinOeml.CancelAllOrders(reqCancelAll) +} +``` + +### Order Updates + +For processing updates on orders, two invoke functions must be implemented and set in the SDK. The Snapshot handler +and the update handler. Both must be set during init to prevent a panic caused by null dereferences. A typical execution handler +would construct the invoke functions and assigned during init as shown below. + +```go +func NewEmxHandler(coinApi *coinapi.CoinApi,) (emx *ExecutionHandler) { + emx = &ExecutionHandler{coinApi: coinApi} + emx.init() + return emx +} + +func (h ExecutionHandler) init() { + executionSnapshotInvoke = h.getExecutionSnapshotInvoke() + h.coinApi.OemlSDK.SetExecSnapshotInvoke(executionSnapshotInvoke) + + executionUpdateInvoke = h.getExecutionUpdateInvoke() + h.coinApi.OemlSDK.SetExecUpdateInvoke(executionUpdateInvoke) +} +``` + +As the snapshot message arrives relatively seldom and usually only during (re) connects, +the order update invoke function really becomes the main handler to process order updates in real-time. + +```go +func (h ExecutionHandler) getExecutionUpdateInvoke() t.InvokeFunction { + return func(message *t.OemlMessage) (err error) { + execReport := message.OrderExecutionReportSnapshot + + // extract fields + symbol := execReport.GetSymbolIdCoinapi() + status : execReport.GetStatus() + avgPrice := execReport.GetAvgPx() + + // process order update + err = h.process(...) + return err + } +} +``` + +Because nearly fields in the message structs are pointers, it is important to use the corresponding Get...() methods +that derefence the pointers, and in case of a nil pointer, set a default value i.e. empty string to prevent crashes. + + +### Error handling + +In case an order gets rejected, a MessageReject will be issued and needs to be processed in the Error Invoke Function which, +again, must be set during SDK init. The reject_reason field contains an enum with one of the following values: + +* EXCHANGE_UNREACHABLE +* EXCHANGE_RESPONSE_TIMEOUT +* ORDER_ID_NOT_FOUND +* INVALID_TYPE +* METHOD_NOT_SUPPORTED +* JSON_ERROR + +The API doc specify the reject reasons and thus can be used for control flow, although converting them into a proper go / iota enum is advised. + +Also note the message that triggered the error is stored in the rejected_message field for further inspection. + +```go +func GetErrorInvoke() types.InvokeFunction { + // You need to be prepared to receive an error message from us when you send something wrong; + // Good practice is to store all error messages in a persistent log i.e. DB / Reddis for further manual review. + // https://docs.coinapi.io/#error-handling + return func(message *types.OemlMessage) (err error) { + mtd := "ErrorHandler: " + println(mtd) + // RejectMessage is used to communicate rejection of user order request. + // https://docs.coinapi.io/oeml.html#message_reject-in + msg := message.MessageReject + reason := msg.GetRejectReason() + + log.Println("RejectMessage") + log.Println("Reject_reason: ", reason) + log.Println("Exchange_id: ", msg.GetExchangeId()) + log.Println("Message: ", msg.GetMessage()) + log.Println("RejectedMessage: ", msg.GetRejectedMessage()) + + + if reason == "EXCHANGE_UNREACHABLE"{ + ... + } + + if reason == "EXCHANGE_RESPONSE_TIMEOUT"{ + ... + } + + return err + } +} +``` + + +## Contact + +For questions, please contact: support@coinapi.io diff --git a/oeml-sdk/go-ws/go.mod b/oeml-sdk/go-ws/go.mod new file mode 100644 index 0000000000..6ca2cf0429 --- /dev/null +++ b/oeml-sdk/go-ws/go.mod @@ -0,0 +1,11 @@ +module github.com/marvin-hansen/coinapi-sdk/oeml-sdk/go-ws + +go 1.16 + +require ( + github.com/bitly/go-simplejson v0.5.0 + github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect + github.com/gorilla/websocket v1.4.2 + github.com/iancoleman/orderedmap v0.2.0 + github.com/kr/pretty v0.2.1 // indirect +) diff --git a/oeml-sdk/go-ws/go.sum b/oeml-sdk/go-ws/go.sum new file mode 100644 index 0000000000..30315ea4ec --- /dev/null +++ b/oeml-sdk/go-ws/go.sum @@ -0,0 +1,13 @@ +github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y= +github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= +github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA= +github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= diff --git a/oeml-sdk/go-ws/main.go b/oeml-sdk/go-ws/main.go new file mode 100644 index 0000000000..d85b0433cf --- /dev/null +++ b/oeml-sdk/go-ws/main.go @@ -0,0 +1,327 @@ +package main + +import ( + "github.com/marvin-hansen/coinapi-sdk/oeml-sdk/go-ws/sdk" + "github.com/marvin-hansen/coinapi-sdk/oeml-sdk/go-ws/sdk/types" + "log" + "time" +) + +// kubectl port-forward svc/oeml-api-composite 8080:80 +// websocat -s 8080 +const ( + url = "ws://127.0.0.1:8080" + wait = 5 + websocat = false + verbose = false + exchangeID = "BINANCE" + clientOrderID = "BINANCE-7d8a-4888" +) + +func main() { + sdk := getSDK(url) + TestSymbolLookup(sdk) + + TestPlaceSingleOrder(sdk) + time.Sleep(wait * time.Second) + + TestCancelSingleOrder(sdk) + time.Sleep(wait * time.Second) + + TestCancelAll(sdk) + time.Sleep(wait * time.Second) + + TestCancelSingleOrderError(sdk) + time.Sleep(wait * time.Second) + + TestCancelAllError(sdk) + time.Sleep(wait * time.Second) + + CloseSocket(sdk) +} + +func getSDK(url string) (oemlSDK types.SDK) { + println(" * NewSDK!") + oemlSDK = sdk.NewOemlSDK(url, types.Version(1)) + + println(" * SetSysInvoke!") + sysInvoke := GetSysInvoke() + oemlSDK.SetSystemInvoke(sysInvoke) + + println(" * SetSysSnapshotInvoke!") + snapInvoke := GetSnapshotInvoke() + oemlSDK.SetSnapshotInvoke(snapInvoke) + + println(" * SetSysSnapshotInvoke!") + updInvoke := GetUpdateInvoke() + oemlSDK.SetUpdateInvoke(updInvoke) + + return oemlSDK +} + +func TestSymbolLookup(sdk types.SDK) { + + if websocat { + return // cannot test symbol lookup against mock socket + } + time.Sleep(1 * time.Second) + + printHeader(" * Lookup symbol!") + // https://www.binance.com/en/trade/ATOM_BUSD?theme=dark&type=spot + baseID := "ATOM" + quoteID := "BUSD" + printSymbol(sdk, exchangeID, baseID, quoteID) + time.Sleep(1 * time.Second) + + // https://www.binance.com/en/trade/BTC_USDT?theme=dark&type=spot + baseID = "BTC" + quoteID = "USDT" + printSymbol(sdk, exchangeID, baseID, quoteID) + + time.Sleep(1 * time.Second) +} + +func TestPlaceSingleOrder(sdk types.SDK) { + + printHeader(" * Lookup order symbol!") + + var symbolIdCoinApi string + if websocat { + // cannot lookup symbol on mock web socket + symbolIdCoinApi = "BINANCE_SPOT_BTC_USDT" + } else { + baseID := "BTC" + quoteID := "USDT" + symbolData, _ := sdk.LookupSymbolData(exchangeID, baseID, quoteID) + symbolIdCoinApi = *symbolData.Symbol_id_coinapi + } + + printHeader(" Symbol: " + symbolIdCoinApi) + + printHeader(" * Construct order request!") + amountOrder := 0.045 + price := 0.0783 + orderSide := types.BUY + orderType := types.LIMIT + timeInForce := types.GOOD_TILL_CANCEL + reqOrder := sdk.NewSingleOrderRequest(exchangeID, symbolIdCoinApi, clientOrderID, amountOrder, price, orderSide, orderType, timeInForce) + b, _ := reqOrder.MarshalJSON() + println(string(b)) + + printHeader("Place single order!") + err := sdk.PlaceSingleOrder(reqOrder) + logError(err) + time.Sleep(wait * time.Second) +} + +func TestCancelSingleOrder(sdk types.SDK) { + printHeader(" * Construct cancel request!") + reqCancel := sdk.NewCancelSingleOrderRequest(exchangeID, clientOrderID) + b, _ := reqCancel.MarshalJSON() + println(string(b)) + + printHeader(" * Cancel order!") + err := sdk.CancelSingleOrder(reqCancel) + logError(err) + time.Sleep(wait * time.Second) +} + +func TestCancelAll(sdk types.SDK) { + time.Sleep(1 * time.Second) + + printHeader(" * Construct cancel all request!") + reqCancelAll := sdk.NewCancelAllOrdersRequest(exchangeID) + b, _ := reqCancelAll.MarshalJSON() + println(string(b)) + + printHeader("Cancel all orders!") + err := sdk.CancelAllOrders(reqCancelAll) + logError(err) + time.Sleep(wait * time.Second) +} + +func TestCancelSingleOrderError(sdk types.SDK) { + printHeader(" * Construct cancel request!") + reqCancel := sdk.NewCancelSingleOrderRequest(exchangeID, "Not-An-Order-ID") + b, _ := reqCancel.MarshalJSON() + println(string(b)) + + printHeader(" * Cancel order!") + err := sdk.CancelSingleOrder(reqCancel) + logError(err) + time.Sleep(wait * time.Second) +} + +func TestCancelAllError(sdk types.SDK) { + time.Sleep(1 * time.Second) + + printHeader(" * Construct broken cancel request to trigger MESSAGE_REJECT!") + reqCancelAll := sdk.NewCancelAllOrdersRequest("Not-An-Exchange") + b, _ := reqCancelAll.MarshalJSON() + println(string(b)) + + printHeader("Send broken broken cancel requests!") + err := sdk.CancelAllOrders(reqCancelAll) + logError(err) + time.Sleep(wait * time.Second) +} + +func CloseSocket(sdk types.SDK) { + println(" * Close websocket!") + if websocat { + return // Don't close connection of a local mock socket + } + println() + println(" * CloseConnection!") + _ = sdk.CloseConnection() + println("Goodbye!") +} + +func logError(err error) { + if err != nil { + log.Println(err) + } +} + +func printHeader(msg string) { + println() + println("=====================") + println(msg) + println("=====================") + println() +} + +func printSymbol(sdk types.SDK, exchangeID, baseID, quoteID string) { + println("") + println("Lookup symbol for: " + baseID + "/" + quoteID) + symbol, ok := sdk.LookupSymbolData(exchangeID, baseID, quoteID) + if ok { + println(symbol.String()) + } + println("") + +} + +func GetSnapshotInvoke() (snapInv types.SnapshotInvoke) { + snapInv = types.SnapshotInvoke{ + ExecutionSnapshotInvoke: GetInvokeFunction(types.ORDER_EXEC_REPORT_SNAPSHOT), + BalanceSnapshotInvoke: GetInvokeFunction(types.BALANCE_SNAPSHOT), + PositionSnapshotInvoke: GetInvokeFunction(types.POSITION_SNAPSHOT), + SymbolSnapshotInvoke: GetInvokeFunction(types.SYMBOLS_SNAPSHOT), + } + return snapInv +} + +func GetUpdateInvoke() (updInv types.UpdateInvoke) { + updInv = types.UpdateInvoke{ + ExecutionUpdateInvoke: GetInvokeFunction(types.ORDER_EXEC_REPORT_UPDATE), + BalanceUpdateInvoke: GetInvokeFunction(types.BALANCE_UPDATE), + PositionUpdateInvoke: GetInvokeFunction(types.POSITION_UPDATE), + } + return updInv +} + +func GetSysInvoke() (sysInv types.SystemInvoke) { + sysInv = types.SystemInvoke{ + ErrorMessageInvoke: GetErrorInvoke(), + ServerInfoInvoke: GetInvokeFunction(types.SERVER_INFO), + } + return sysInv +} + +func GetErrorInvoke() types.InvokeFunction { + // You need to be prepared to receive an error message from us when you send something wrong; + // all errors are permanent and you should expect that the underlying + // WebSocket connection will be closed by us after sending an error message. + // Good practice is to store all error messages somewhere for further manual review. + // https://docs.coinapi.io/#error-handling + return func(message *types.OemlMessage) (err error) { + mtd := "ErrorHandler: " + println(mtd) + // RejectMessage is used to communicate rejection of user order request. + // https://docs.coinapi.io/oeml.html#message_reject-in + msg := message.MessageReject + log.Println("RejectMessage") + log.Println("Reject_reason: ", msg.GetRejectReason()) + log.Println("Exchange_id: ", msg.GetExchangeId()) + log.Println("Message: ", msg.GetMessage()) + log.Println("RejectedMessage: ", msg.GetRejectedMessage()) + + return nil + } +} + +func GetInvokeFunction(msgType types.MessageType) types.InvokeFunction { + return func(message *types.OemlMessage) (err error) { + printMessage(msgType, message) + return nil + } +} + +func printMessage(msgType types.MessageType, message *types.OemlMessage) { + switch msgType { + case types.SERVER_INFO: + //log.Println("ServerInfo/Heartbeat: " + *message.ServerInfo.ExchangeId) + if verbose { + msg := message + log.Println(msg.ServerInfo) + println() + } + + case types.ORDER_EXEC_REPORT_SNAPSHOT: + log.Println("OrderExecutionReportSnapshot: " + message.OrderExecutionReportSnapshot.ExchangeId) + if verbose { + msg := message + log.Println(msg.OrderExecutionReportSnapshot) + println() + } + + case types.ORDER_EXEC_REPORT_UPDATE: + log.Println("OrderExecutionReportUpdate") + msg := message + log.Println(msg.OrderExecutionReportUpdate) + println() + case types.BALANCE_SNAPSHOT: + msg := message + if verbose { + log.Println("BalanceSnapshot" + *message.BalanceSnapshot.ExchangeId) + log.Println(msg.BalanceSnapshot) + println() + } + case types.BALANCE_UPDATE: + msg := message + log.Println("BalanceUpdate") + log.Println(msg.BalanceUpdate.String()) + println() + + case types.POSITION_SNAPSHOT: + log.Println("PositionSnapshot: " + *message.PositionSnapshot.ExchangeId) + if verbose { + msg := message + log.Println(msg.PositionSnapshot) + println() + } + case types.POSITION_UPDATE: + log.Println("PositionUpdate") + msg := message + log.Println(msg.PositionUpdate) + println() + case types.SYMBOLS_SNAPSHOT: + log.Println("SymbolSnapshot: " + *message.SymbolSnapshot.ExchangeId) + if verbose { + msg := message + log.Println(msg.SymbolSnapshot) + println() + } + case types.MESSAGE_REJECT: + log.Println("Message") + msg := message.MessageReject + log.Println("RejectMessage") + log.Println("Reject_reason: ", msg.GetRejectReason()) + log.Println("Exchange_id: ", msg.GetExchangeId()) + log.Println("Message: ", msg.GetMessage()) + log.Println("RejectedMessage: ", msg.GetRejectedMessage()) + + println() + } +} diff --git a/oeml-sdk/go-ws/sdk/sdk.go b/oeml-sdk/go-ws/sdk/sdk.go new file mode 100644 index 0000000000..8e32b0a0e6 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/sdk.go @@ -0,0 +1,22 @@ +package sdk + +import ( + "github.com/marvin-hansen/coinapi-sdk/oeml-sdk/go-ws/sdk/types" + v1 "github.com/marvin-hansen/coinapi-sdk/oeml-sdk/go-ws/sdk/v1" +) + +func NewOemlSDK(url string, version types.Version) (sdk types.SDK) { + sdk = getSDK(version, url) + return sdk +} + +func getSDK(version types.Version, url string) (sdk types.SDK) { + switch version { + case types.V1: + // Bind interface to implementation matching the selected API version. + sdk = v1.NewOemlSdkV1(url) + default: + sdk = v1.NewOemlSdkV1(url) + } + return sdk +} diff --git a/oeml-sdk/go-ws/sdk/types/api_do_not_edit.md b/oeml-sdk/go-ws/sdk/types/api_do_not_edit.md new file mode 100644 index 0000000000..6b2c1b94af --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/api_do_not_edit.md @@ -0,0 +1,8 @@ +API version: v1 + +Contact: support@coinapi.io + +Code generated by OpenAPI Generator (https://openapi-generator.tech); + +DO NOT EDIT. + diff --git a/oeml-sdk/go-ws/sdk/types/balance.go b/oeml-sdk/go-ws/sdk/types/balance.go new file mode 100644 index 0000000000..2e1c1953be --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/balance.go @@ -0,0 +1,131 @@ +package types + +import ( + "encoding/json" + "fmt" +) + +// Balance struct for Balance +type Balance struct { + // Exchange identifier used to identify the routing destination. + ExchangeId *string `json:"exchange_id,omitempty"` + Data *[]BalanceData `json:"data,omitempty"` +} + +func (o *Balance) String() string { + return fmt.Sprintf(" ExchangeId: %v, Data: %v", + o.GetExchangeId(), + o.GetData(), + ) +} + +// GetExchangeId returns the ExchangeId field value if set, zero value otherwise. +func (o *Balance) GetExchangeId() string { + if o == nil || o.ExchangeId == nil { + var ret string + return ret + } + return *o.ExchangeId +} + +// GetExchangeIdOk returns a tuple with the ExchangeId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Balance) GetExchangeIdOk() (*string, bool) { + if o == nil || o.ExchangeId == nil { + return nil, false + } + return o.ExchangeId, true +} + +// HasExchangeId returns a boolean if a field has been set. +func (o *Balance) HasExchangeId() bool { + if o != nil && o.ExchangeId != nil { + return true + } + + return false +} + +// SetExchangeId gets a reference to the given string and assigns it to the ExchangeId field. +func (o *Balance) SetExchangeId(v string) { + o.ExchangeId = &v +} + +// GetData returns the Data field value if set, zero value otherwise. +func (o *Balance) GetData() []BalanceData { + if o == nil || o.Data == nil { + var ret []BalanceData + return ret + } + return *o.Data +} + +// GetDataOk returns a tuple with the Data field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Balance) GetDataOk() (*[]BalanceData, bool) { + if o == nil || o.Data == nil { + return nil, false + } + return o.Data, true +} + +// HasData returns a boolean if a field has been set. +func (o *Balance) HasData() bool { + if o != nil && o.Data != nil { + return true + } + + return false +} + +// SetData gets a reference to the given []BalanceData and assigns it to the Data field. +func (o *Balance) SetData(v []BalanceData) { + o.Data = &v +} + +func (o Balance) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.ExchangeId != nil { + toSerialize["exchange_id"] = o.ExchangeId + } + if o.Data != nil { + toSerialize["data"] = o.Data + } + return json.Marshal(toSerialize) +} + +type NullableBalance struct { + value *Balance + isSet bool +} + +func (v NullableBalance) Get() *Balance { + return v.value +} + +func (v *NullableBalance) Set(val *Balance) { + v.value = val + v.isSet = true +} + +func (v NullableBalance) IsSet() bool { + return v.isSet +} + +func (v *NullableBalance) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBalance(val *Balance) *NullableBalance { + return &NullableBalance{value: val, isSet: true} +} + +func (v NullableBalance) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBalance) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/balance_data.go b/oeml-sdk/go-ws/sdk/types/balance_data.go new file mode 100644 index 0000000000..da8afcd944 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/balance_data.go @@ -0,0 +1,384 @@ +package types + +import ( + "encoding/json" + "fmt" + "strconv" +) + +// BalanceData struct for BalanceData +type BalanceData struct { + // Exchange currency code. + AssetIdExchange *string `json:"asset_id_exchange,omitempty"` + // CoinAPI currency code. + AssetIdCoinapi *string `json:"asset_id_coinapi,omitempty"` + // Value of the current total currency balance on the exchange. + Balance *float64 `json:"balance,omitempty"` + // Value of the current available currency balance on the exchange that can be used as collateral. + Available *float64 `json:"available,omitempty"` + // Value of the current locked currency balance by the exchange. + Locked *float64 `json:"locked,omitempty"` + // Source of the last modification. + LastUpdatedBy *string `json:"last_updated_by,omitempty"` + // Current exchange rate to the USD for the single unit of the currency. + RateUsd *float64 `json:"rate_usd,omitempty"` + // Value of the current total traded. + Traded *float64 `json:"traded,omitempty"` +} + +func (o BalanceData) String() string { + return fmt.Sprintf(" AssetIdExchange: %v, AssetIdCoinapi: %v, Balance: %v, Available: %v, Locked: %v, LastUpdatedBy: %v, RateUsd: %v, Traded: %v", + o.GetAssetIdExchange(), + o.GetAssetIdCoinapi(), + convertFloatToString(o.GetBalance()), + convertFloatToString(o.GetAvailable()), + convertFloatToString(o.GetLocked()), + o.GetLastUpdatedBy(), + convertFloatToString(o.GetRateUsd()), + convertFloatToString(o.GetTraded()), + ) +} + +func convertFloatToString(f float64) (s string) { + s = strconv.FormatFloat(float64(f), 'f', 8, 64) + //s = fmt.Sprintf("%.8f", f) + return s +} + +// NewBalanceData instantiates a new BalanceData object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewBalanceData() *BalanceData { + this := BalanceData{} + return &this +} + +// NewBalanceDataWithDefaults instantiates a new BalanceData object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewBalanceDataWithDefaults() *BalanceData { + this := BalanceData{} + return &this +} + +// GetAssetIdExchange returns the AssetIdExchange field value if set, zero value otherwise. +func (o *BalanceData) GetAssetIdExchange() string { + if o == nil || o.AssetIdExchange == nil { + var ret = "" + return ret + } + return *o.AssetIdExchange +} + +// GetAssetIdExchangeOk returns a tuple with the AssetIdExchange field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BalanceData) GetAssetIdExchangeOk() (*string, bool) { + if o == nil || o.AssetIdExchange == nil { + return nil, false + } + return o.AssetIdExchange, true +} + +// HasAssetIdExchange returns a boolean if a field has been set. +func (o *BalanceData) HasAssetIdExchange() bool { + if o != nil && o.AssetIdExchange != nil { + return true + } + + return false +} + +// SetAssetIdExchange gets a reference to the given string and assigns it to the AssetIdExchange field. +func (o *BalanceData) SetAssetIdExchange(v string) { + o.AssetIdExchange = &v +} + +// GetAssetIdCoinapi returns the AssetIdCoinapi field value if set, zero value otherwise. +func (o *BalanceData) GetAssetIdCoinapi() string { + if o == nil || o.AssetIdCoinapi == nil { + var ret = "" + return ret + } + return *o.AssetIdCoinapi +} + +// GetAssetIdCoinapiOk returns a tuple with the AssetIdCoinapi field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BalanceData) GetAssetIdCoinapiOk() (*string, bool) { + if o == nil || o.AssetIdCoinapi == nil { + return nil, false + } + return o.AssetIdCoinapi, true +} + +// HasAssetIdCoinapi returns a boolean if a field has been set. +func (o *BalanceData) HasAssetIdCoinapi() bool { + if o != nil && o.AssetIdCoinapi != nil { + return true + } + + return false +} + +// SetAssetIdCoinapi gets a reference to the given string and assigns it to the AssetIdCoinapi field. +func (o *BalanceData) SetAssetIdCoinapi(v string) { + o.AssetIdCoinapi = &v +} + +// GetBalance returns the Balance field value if set, zero value otherwise. +func (o *BalanceData) GetBalance() float64 { + if o == nil || o.Balance == nil { + var ret = 0.0 + return ret + } + return *o.Balance +} + +// GetBalanceOk returns a tuple with the Balance field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BalanceData) GetBalanceOk() (*float64, bool) { + if o == nil || o.Balance == nil { + return nil, false + } + return o.Balance, true +} + +// HasBalance returns a boolean if a field has been set. +func (o *BalanceData) HasBalance() bool { + if o != nil && o.Balance != nil { + return true + } + + return false +} + +// SetBalance gets a reference to the given float64 and assigns it to the Balance field. +func (o *BalanceData) SetBalance(v float64) { + o.Balance = &v +} + +// GetAvailable returns the Available field value if set, zero value otherwise. +func (o *BalanceData) GetAvailable() float64 { + if o == nil || o.Available == nil { + var ret = 0.0 + return ret + } + return *o.Available +} + +// GetAvailableOk returns a tuple with the Available field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BalanceData) GetAvailableOk() (*float64, bool) { + if o == nil || o.Available == nil { + return nil, false + } + return o.Available, true +} + +// HasAvailable returns a boolean if a field has been set. +func (o *BalanceData) HasAvailable() bool { + if o != nil && o.Available != nil { + return true + } + + return false +} + +// SetAvailable gets a reference to the given float64 and assigns it to the Available field. +func (o *BalanceData) SetAvailable(v float64) { + o.Available = &v +} + +// GetLocked returns the Locked field value if set, zero value otherwise. +func (o *BalanceData) GetLocked() float64 { + if o == nil || o.Locked == nil { + var ret = 0.0 + return ret + } + return *o.Locked +} + +// GetLockedOk returns a tuple with the Locked field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BalanceData) GetLockedOk() (*float64, bool) { + if o == nil || o.Locked == nil { + return nil, false + } + return o.Locked, true +} + +// HasLocked returns a boolean if a field has been set. +func (o *BalanceData) HasLocked() bool { + if o != nil && o.Locked != nil { + return true + } + + return false +} + +// SetLocked gets a reference to the given float64 and assigns it to the Locked field. +func (o *BalanceData) SetLocked(v float64) { + o.Locked = &v +} + +// GetLastUpdatedBy returns the LastUpdatedBy field value if set, zero value otherwise. +func (o *BalanceData) GetLastUpdatedBy() string { + if o == nil || o.LastUpdatedBy == nil { + var ret = "" + return ret + } + return *o.LastUpdatedBy +} + +// GetLastUpdatedByOk returns a tuple with the LastUpdatedBy field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BalanceData) GetLastUpdatedByOk() (*string, bool) { + if o == nil || o.LastUpdatedBy == nil { + return nil, false + } + return o.LastUpdatedBy, true +} + +// HasLastUpdatedBy returns a boolean if a field has been set. +func (o *BalanceData) HasLastUpdatedBy() bool { + if o != nil && o.LastUpdatedBy != nil { + return true + } + + return false +} + +// SetLastUpdatedBy gets a reference to the given string and assigns it to the LastUpdatedBy field. +func (o *BalanceData) SetLastUpdatedBy(v string) { + o.LastUpdatedBy = &v +} + +// GetRateUsd returns the RateUsd field value if set, zero value otherwise. +func (o *BalanceData) GetRateUsd() float64 { + if o == nil || o.RateUsd == nil { + var ret = 0.0 + return ret + } + return *o.RateUsd +} + +// GetRateUsdOk returns a tuple with the RateUsd field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BalanceData) GetRateUsdOk() (*float64, bool) { + if o == nil || o.RateUsd == nil { + return nil, false + } + return o.RateUsd, true +} + +// HasRateUsd returns a boolean if a field has been set. +func (o *BalanceData) HasRateUsd() bool { + if o != nil && o.RateUsd != nil { + return true + } + + return false +} + +// SetRateUsd gets a reference to the given float64 and assigns it to the RateUsd field. +func (o *BalanceData) SetRateUsd(v float64) { + o.RateUsd = &v +} + +// GetTraded returns the Traded field value if set, zero value otherwise. +func (o *BalanceData) GetTraded() float64 { + if o == nil || o.Traded == nil { + var ret = 0.0 + return ret + } + return *o.Traded +} + +// GetTradedOk returns a tuple with the Traded field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BalanceData) GetTradedOk() (*float64, bool) { + if o == nil || o.Traded == nil { + return nil, false + } + return o.Traded, true +} + +// HasTraded returns a boolean if a field has been set. +func (o *BalanceData) HasTraded() bool { + if o != nil && o.Traded != nil { + return true + } + + return false +} + +// SetTraded gets a reference to the given float64 and assigns it to the Traded field. +func (o *BalanceData) SetTraded(v float64) { + o.Traded = &v +} + +func (o BalanceData) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.AssetIdExchange != nil { + toSerialize["asset_id_exchange"] = o.AssetIdExchange + } + if o.AssetIdCoinapi != nil { + toSerialize["asset_id_coinapi"] = o.AssetIdCoinapi + } + if o.Balance != nil { + toSerialize["balance"] = o.Balance + } + if o.Available != nil { + toSerialize["available"] = o.Available + } + if o.Locked != nil { + toSerialize["locked"] = o.Locked + } + if o.LastUpdatedBy != nil { + toSerialize["last_updated_by"] = o.LastUpdatedBy + } + if o.RateUsd != nil { + toSerialize["rate_usd"] = o.RateUsd + } + if o.Traded != nil { + toSerialize["traded"] = o.Traded + } + return json.Marshal(toSerialize) +} + +type NullableBalanceData struct { + value *BalanceData + isSet bool +} + +func (v NullableBalanceData) Get() *BalanceData { + return v.value +} + +func (v *NullableBalanceData) Set(val *BalanceData) { + v.value = val + v.isSet = true +} + +func (v NullableBalanceData) IsSet() bool { + return v.isSet +} + +func (v *NullableBalanceData) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBalanceData(val *BalanceData) *NullableBalanceData { + return &NullableBalanceData{value: val, isSet: true} +} + +func (v NullableBalanceData) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBalanceData) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/data_message.go b/oeml-sdk/go-ws/sdk/types/data_message.go new file mode 100644 index 0000000000..4fec627aa5 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/data_message.go @@ -0,0 +1,14 @@ +package types + +type OemlMessage struct { + BalanceSnapshot *Balance + BalanceUpdate *Balance + MessageType *MessageType + OrderExecutionReportSnapshot *OrderExecutionReport + OrderExecutionReportUpdate *OrderExecutionReport + PositionSnapshot *Position + PositionUpdate *Position + ServerInfo *ServerInfo + SymbolSnapshot *Symbols + MessageReject *MessageReject +} diff --git a/oeml-sdk/go-ws/sdk/types/enums.go b/oeml-sdk/go-ws/sdk/types/enums.go new file mode 100644 index 0000000000..891dc9df9e --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/enums.go @@ -0,0 +1,27 @@ +package types + +// ApiVersion custom ENUM for SDK forward compatibility +type Version int + +const ( + V1 Version = iota +) + +// MessageType replicates the official incoming message types as (kinda) string enum. +// https://docs.coinapi.io/#messages +type MessageType string + +const ( + SERVER_INFO MessageType = "SERVER_INFO" + ORDER_NEW_SINGLE_REQUEST MessageType = "ORDER_NEW_SINGLE_REQUEST" + ORDER_CANCEL_SINGLE_REQUEST MessageType = "ORDER_CANCEL_SINGLE_REQUEST" + ORDER_CANCEL_ALL_REQUEST MessageType = "ORDER_CANCEL_ALL_REQUEST" + ORDER_EXEC_REPORT_SNAPSHOT MessageType = "ORDER_EXEC_REPORT_SNAPSHOT" + ORDER_EXEC_REPORT_UPDATE MessageType = "ORDER_EXEC_REPORT_UPDATE" + BALANCE_SNAPSHOT MessageType = "BALANCE_SNAPSHOT" + BALANCE_UPDATE MessageType = "BALANCE_UPDATE" + POSITION_SNAPSHOT MessageType = "POSITION_SNAPSHOT" + POSITION_UPDATE MessageType = "POSITION_UPDATE" + SYMBOLS_SNAPSHOT MessageType = "SYMBOLS_SNAPSHOT" + MESSAGE_REJECT MessageType = "MESSAGE_REJECT" +) diff --git a/oeml-sdk/go-ws/sdk/types/error.go b/oeml-sdk/go-ws/sdk/types/error.go new file mode 100644 index 0000000000..18911f7554 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/error.go @@ -0,0 +1,8 @@ +package types + +import "fmt" + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} diff --git a/oeml-sdk/go-ws/sdk/types/functions.go b/oeml-sdk/go-ws/sdk/types/functions.go new file mode 100644 index 0000000000..51cfd103bd --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/functions.go @@ -0,0 +1,24 @@ +package types + +type UpdateInvoke struct { + ExecutionUpdateInvoke InvokeFunction + BalanceUpdateInvoke InvokeFunction + PositionUpdateInvoke InvokeFunction +} + +type SnapshotInvoke struct { + ExecutionSnapshotInvoke InvokeFunction + BalanceSnapshotInvoke InvokeFunction + PositionSnapshotInvoke InvokeFunction + SymbolSnapshotInvoke InvokeFunction +} + +// SystemInvoke just bundles all system invoke functions +type SystemInvoke struct { + ErrorMessageInvoke InvokeFunction + ServerInfoInvoke InvokeFunction +} + +// InvokeFunction is a unified function type for all event handlers. +// https://yourbasic.org/golang/function-pointer-type-declaration/ +type InvokeFunction func(message *OemlMessage) (err error) diff --git a/oeml-sdk/go-ws/sdk/types/interface.go b/oeml-sdk/go-ws/sdk/types/interface.go new file mode 100644 index 0000000000..b2e5d43b5d --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/interface.go @@ -0,0 +1,27 @@ +package types + +type SDK interface { + OpenConnection() (err error) + CloseConnection() (err error) + ResetConnection() (err error) + // + LookupSymbolData(exchangeID, baseSymbolCoinApi, quoteSymbolCoinApi string) (symbolData SymbolData, ok bool) + NewSingleOrderRequest(exchangeId, SymbolIdCoinapi string, clientOrderId string, amountOrder float64, price float64, side OrdSide, orderType OrdType, timeInForce TimeInForce) (req *OrderNewSingleRequest) + NewCancelSingleOrderRequest(exchangeId, clientOrderId string) (req *OrderCancelSingleRequest) + NewCancelAllOrdersRequest(exchangeId string) (req *OrderCancelAllRequest) + // + PlaceSingleOrder(req *OrderNewSingleRequest) (err error) + CancelSingleOrder(req *OrderCancelSingleRequest) (err error) + CancelAllOrders(req *OrderCancelAllRequest) (err error) + // + SetSystemInvoke(function SystemInvoke) + SetSnapshotInvoke(function SnapshotInvoke) + SetUpdateInvoke(function UpdateInvoke) + // + SetExecUpdateInvoke(function InvokeFunction) + SetExecSnapshotInvoke(function InvokeFunction) + SetBalanceUpdateInvoke(function InvokeFunction) + SetBalanceSnapshotInvoke(function InvokeFunction) + SetPositionUpdateInvoke(function InvokeFunction) + SetPositionSnapshotInvoke(function InvokeFunction) +} diff --git a/oeml-sdk/go-ws/sdk/types/message.go b/oeml-sdk/go-ws/sdk/types/message.go new file mode 100644 index 0000000000..f35ca6a18b --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/message.go @@ -0,0 +1,219 @@ +package types + +import ( + "encoding/json" +) + +// Message struct for Message +type Message struct { + // Type of message. + Type *string `json:"type,omitempty"` + Severity *Severity `json:"severity,omitempty"` + // If the message related to exchange, then the identifier of the exchange will be provided. + ExchangeId *string `json:"exchange_id,omitempty"` + // Message text. + Message *string `json:"message,omitempty"` +} + +func (o *Message) String() string { + s := "Type " + string(*o.Type) + "Message: " + *o.Message + return s +} + +// NewMessage instantiates a new Message object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMessage() *Message { + this := Message{} + return &this +} + +// NewMessageWithDefaults instantiates a new Message object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMessageWithDefaults() *Message { + this := Message{} + return &this +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *Message) GetType() string { + if o == nil || o.Type == nil { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Message) GetTypeOk() (*string, bool) { + if o == nil || o.Type == nil { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *Message) HasType() bool { + if o != nil && o.Type != nil { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *Message) SetType(v string) { + o.Type = &v +} + +// GetSeverity returns the Severity field value if set, zero value otherwise. +func (o *Message) GetSeverity() Severity { + if o == nil || o.Severity == nil { + var ret Severity + return ret + } + return *o.Severity +} + +// GetSeverityOk returns a tuple with the Severity field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Message) GetSeverityOk() (*Severity, bool) { + if o == nil || o.Severity == nil { + return nil, false + } + return o.Severity, true +} + +// HasSeverity returns a boolean if a field has been set. +func (o *Message) HasSeverity() bool { + if o != nil && o.Severity != nil { + return true + } + + return false +} + +// SetSeverity gets a reference to the given Severity and assigns it to the Severity field. +func (o *Message) SetSeverity(v Severity) { + o.Severity = &v +} + +// GetExchangeId returns the ExchangeId field value if set, zero value otherwise. +func (o *Message) GetExchangeId() string { + if o == nil || o.ExchangeId == nil { + var ret string + return ret + } + return *o.ExchangeId +} + +// GetExchangeIdOk returns a tuple with the ExchangeId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Message) GetExchangeIdOk() (*string, bool) { + if o == nil || o.ExchangeId == nil { + return nil, false + } + return o.ExchangeId, true +} + +// HasExchangeId returns a boolean if a field has been set. +func (o *Message) HasExchangeId() bool { + if o != nil && o.ExchangeId != nil { + return true + } + + return false +} + +// SetExchangeId gets a reference to the given string and assigns it to the ExchangeId field. +func (o *Message) SetExchangeId(v string) { + o.ExchangeId = &v +} + +// GetMessage returns the Message field value if set, zero value otherwise. +func (o *Message) GetMessage() string { + if o == nil || o.Message == nil { + var ret string + return ret + } + return *o.Message +} + +// GetMessageOk returns a tuple with the Message field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Message) GetMessageOk() (*string, bool) { + if o == nil || o.Message == nil { + return nil, false + } + return o.Message, true +} + +// HasMessage returns a boolean if a field has been set. +func (o *Message) HasMessage() bool { + if o != nil && o.Message != nil { + return true + } + + return false +} + +// SetMessage gets a reference to the given string and assigns it to the Message field. +func (o *Message) SetMessage(v string) { + o.Message = &v +} + +func (o Message) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.Type != nil { + toSerialize["type"] = o.Type + } + if o.Severity != nil { + toSerialize["severity"] = o.Severity + } + if o.ExchangeId != nil { + toSerialize["exchange_id"] = o.ExchangeId + } + if o.Message != nil { + toSerialize["message"] = o.Message + } + return json.Marshal(toSerialize) +} + +type NullableMessage struct { + value *Message + isSet bool +} + +func (v NullableMessage) Get() *Message { + return v.value +} + +func (v *NullableMessage) Set(val *Message) { + v.value = val + v.isSet = true +} + +func (v NullableMessage) IsSet() bool { + return v.isSet +} + +func (v *NullableMessage) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMessage(val *Message) *NullableMessage { + return &NullableMessage{value: val, isSet: true} +} + +func (v NullableMessage) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMessage) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/model_message_reject.go b/oeml-sdk/go-ws/sdk/types/model_message_reject.go new file mode 100644 index 0000000000..cf74856df1 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/model_message_reject.go @@ -0,0 +1,262 @@ +/* + * OEML - REST API + * + * This section will provide necessary information about the `CoinAPI OEML REST API` protocol. This API is also available in the Postman application: https://postman.coinapi.io/ + * + * API version: v1 + * Contact: support@coinapi.io + */ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package types + +import ( + "encoding/json" +) + +// MessageReject struct for MessageReject +type MessageReject struct { + // Message type, constant. + Type *string `json:"type,omitempty"` + RejectReason *RejectReason `json:"reject_reason,omitempty"` + // If the message related to exchange, then the identifier of the exchange will be provided. + ExchangeId *string `json:"exchange_id,omitempty"` + // Message text. + Message *string `json:"message,omitempty"` + // Value of rejected request, if available. + RejectedMessage *string `json:"rejected_message,omitempty"` +} + +// NewMessageReject instantiates a new MessageReject object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMessageReject() *MessageReject { + this := MessageReject{} + return &this +} + +// NewMessageRejectWithDefaults instantiates a new MessageReject object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMessageRejectWithDefaults() *MessageReject { + this := MessageReject{} + return &this +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *MessageReject) GetType() string { + if o == nil || o.Type == nil { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MessageReject) GetTypeOk() (*string, bool) { + if o == nil || o.Type == nil { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *MessageReject) HasType() bool { + if o != nil && o.Type != nil { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *MessageReject) SetType(v string) { + o.Type = &v +} + +// GetRejectReason returns the RejectReason field value if set, zero value otherwise. +func (o *MessageReject) GetRejectReason() RejectReason { + if o == nil || o.RejectReason == nil { + var ret RejectReason + return ret + } + return *o.RejectReason +} + +// GetRejectReasonOk returns a tuple with the RejectReason field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MessageReject) GetRejectReasonOk() (*RejectReason, bool) { + if o == nil || o.RejectReason == nil { + return nil, false + } + return o.RejectReason, true +} + +// HasRejectReason returns a boolean if a field has been set. +func (o *MessageReject) HasRejectReason() bool { + if o != nil && o.RejectReason != nil { + return true + } + + return false +} + +// SetRejectReason gets a reference to the given RejectReason and assigns it to the RejectReason field. +func (o *MessageReject) SetRejectReason(v RejectReason) { + o.RejectReason = &v +} + +// GetExchangeId returns the ExchangeId field value if set, zero value otherwise. +func (o *MessageReject) GetExchangeId() string { + if o == nil || o.ExchangeId == nil { + var ret string + return ret + } + return *o.ExchangeId +} + +// GetExchangeIdOk returns a tuple with the ExchangeId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MessageReject) GetExchangeIdOk() (*string, bool) { + if o == nil || o.ExchangeId == nil { + return nil, false + } + return o.ExchangeId, true +} + +// HasExchangeId returns a boolean if a field has been set. +func (o *MessageReject) HasExchangeId() bool { + if o != nil && o.ExchangeId != nil { + return true + } + + return false +} + +// SetExchangeId gets a reference to the given string and assigns it to the ExchangeId field. +func (o *MessageReject) SetExchangeId(v string) { + o.ExchangeId = &v +} + +// GetMessage returns the Message field value if set, zero value otherwise. +func (o *MessageReject) GetMessage() string { + if o == nil || o.Message == nil { + var ret string + return ret + } + return *o.Message +} + +// GetMessageOk returns a tuple with the Message field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MessageReject) GetMessageOk() (*string, bool) { + if o == nil || o.Message == nil { + return nil, false + } + return o.Message, true +} + +// HasMessage returns a boolean if a field has been set. +func (o *MessageReject) HasMessage() bool { + if o != nil && o.Message != nil { + return true + } + + return false +} + +// SetMessage gets a reference to the given string and assigns it to the Message field. +func (o *MessageReject) SetMessage(v string) { + o.Message = &v +} + +// GetRejectedMessage returns the RejectedMessage field value if set, zero value otherwise. +func (o *MessageReject) GetRejectedMessage() string { + if o == nil || o.RejectedMessage == nil { + var ret string + return ret + } + return *o.RejectedMessage +} + +// GetRejectedMessageOk returns a tuple with the RejectedMessage field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MessageReject) GetRejectedMessageOk() (*string, bool) { + if o == nil || o.RejectedMessage == nil { + return nil, false + } + return o.RejectedMessage, true +} + +// HasRejectedMessage returns a boolean if a field has been set. +func (o *MessageReject) HasRejectedMessage() bool { + if o != nil && o.RejectedMessage != nil { + return true + } + + return false +} + +// SetRejectedMessage gets a reference to the given string and assigns it to the RejectedMessage field. +func (o *MessageReject) SetRejectedMessage(v string) { + o.RejectedMessage = &v +} + +func (o MessageReject) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.Type != nil { + toSerialize["type"] = o.Type + } + if o.RejectReason != nil { + toSerialize["reject_reason"] = o.RejectReason + } + if o.ExchangeId != nil { + toSerialize["exchange_id"] = o.ExchangeId + } + if o.Message != nil { + toSerialize["message"] = o.Message + } + if o.RejectedMessage != nil { + toSerialize["rejected_message"] = o.RejectedMessage + } + return json.Marshal(toSerialize) +} + +type NullableMessageReject struct { + value *MessageReject + isSet bool +} + +func (v NullableMessageReject) Get() *MessageReject { + return v.value +} + +func (v *NullableMessageReject) Set(val *MessageReject) { + v.value = val + v.isSet = true +} + +func (v NullableMessageReject) IsSet() bool { + return v.isSet +} + +func (v *NullableMessageReject) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMessageReject(val *MessageReject) *NullableMessageReject { + return &NullableMessageReject{value: val, isSet: true} +} + +func (v NullableMessageReject) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMessageReject) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/model_reject_reason.go b/oeml-sdk/go-ws/sdk/types/model_reject_reason.go new file mode 100644 index 0000000000..38e330c80b --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/model_reject_reason.go @@ -0,0 +1,111 @@ +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package types + +import ( + "encoding/json" + "fmt" +) + +// RejectReason Cause of rejection. +type RejectReason string + +// List of RejectReason +const ( + OTHER RejectReason = "OTHER" + EXCHANGE_UNREACHABLE RejectReason = "EXCHANGE_UNREACHABLE" + EXCHANGE_RESPONSE_TIMEOUT RejectReason = "EXCHANGE_RESPONSE_TIMEOUT" + ORDER_ID_NOT_FOUND RejectReason = "ORDER_ID_NOT_FOUND" + INVALID_TYPE RejectReason = "INVALID_TYPE" + METHOD_NOT_SUPPORTED RejectReason = "METHOD_NOT_SUPPORTED" + JSON_ERROR RejectReason = "JSON_ERROR" +) + +var allowedRejectReasonEnumValues = []RejectReason{ + "OTHER", + "EXCHANGE_UNREACHABLE", + "EXCHANGE_RESPONSE_TIMEOUT", + "ORDER_ID_NOT_FOUND", + "INVALID_TYPE", + "METHOD_NOT_SUPPORTED", + "JSON_ERROR", +} + +func (v *RejectReason) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + enumTypeValue := RejectReason(value) + for _, existing := range allowedRejectReasonEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid RejectReason", value) +} + +// NewRejectReasonFromValue returns a pointer to a valid RejectReason +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewRejectReasonFromValue(v string) (*RejectReason, error) { + ev := RejectReason(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for RejectReason: valid values are %v", v, allowedRejectReasonEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v RejectReason) IsValid() bool { + for _, existing := range allowedRejectReasonEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to RejectReason value +func (v RejectReason) Ptr() *RejectReason { + return &v +} + +type NullableRejectReason struct { + value *RejectReason + isSet bool +} + +func (v NullableRejectReason) Get() *RejectReason { + return v.value +} + +func (v *NullableRejectReason) Set(val *RejectReason) { + v.value = val + v.isSet = true +} + +func (v NullableRejectReason) IsSet() bool { + return v.isSet +} + +func (v *NullableRejectReason) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableRejectReason(val *RejectReason) *NullableRejectReason { + return &NullableRejectReason{value: val, isSet: true} +} + +func (v NullableRejectReason) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableRejectReason) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/order_cancel_all.go b/oeml-sdk/go-ws/sdk/types/order_cancel_all.go new file mode 100644 index 0000000000..7954a06db8 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/order_cancel_all.go @@ -0,0 +1,40 @@ +package types + +import ( + "bytes" + "encoding/json" + "github.com/iancoleman/orderedmap" + "log" +) + +type OrderCancelAllRequest struct { + // Message type to identity the request + Type MessageType `json:"type"` + // Identifier of the exchange from which active orders should be canceled. + ExchangeId string `json:"exchange_id"` +} + +func (o OrderCancelAllRequest) MarshalJSON() (b []byte, err error) { + + oMap := orderedmap.New() + oMap.SetEscapeHTML(false) + oMap.Set("type", o.Type) + oMap.Set("exchange_id", o.ExchangeId) + + b, err = json.Marshal(oMap) + if err != nil { + log.Println("Error marshaling Hello object") + log.Println(err) + return nil, err + } + + var prettyJSON bytes.Buffer + err = json.Indent(&prettyJSON, b, "", "\t") + if err != nil { + log.Println("Error making JSON pretty") + log.Println(err) + return nil, err + } + + return b, err +} diff --git a/oeml-sdk/go-ws/sdk/types/order_cancel_single.go b/oeml-sdk/go-ws/sdk/types/order_cancel_single.go new file mode 100644 index 0000000000..96fe702672 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/order_cancel_single.go @@ -0,0 +1,156 @@ +package types + +import ( + "bytes" + "encoding/json" + "github.com/iancoleman/orderedmap" + "log" +) + +// OrderCancelSingleRequest Cancel single order request object. +type OrderCancelSingleRequest struct { + // Message type to identity the request + Type MessageType `json:"type"` + // Exchange identifier used to identify the routing destination. + ExchangeId string `json:"exchange_id"` + // Unique identifier of the order assigned by the exchange or executing system. One of the properties (`exchange_order_id`, `client_order_id`) is required to identify the new order. + ExchangeOrderId *string `json:"exchange_order_id,omitempty"` + // The unique identifier of the order assigned by the client. One of the properties (`exchange_order_id`, `client_order_id`) is required to identify the new order. + ClientOrderId *string `json:"client_order_id,omitempty"` +} + +// NewOrderCancelSingleRequest instantiates a new OrderCancelSingleRequest object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewOrderCancelSingleRequest(exchangeId string) *OrderCancelSingleRequest { + this := OrderCancelSingleRequest{} + this.ExchangeId = exchangeId + return &this +} + +// NewOrderCancelSingleRequestWithDefaults instantiates a new OrderCancelSingleRequest object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewOrderCancelSingleRequestWithDefaults() *OrderCancelSingleRequest { + this := OrderCancelSingleRequest{} + return &this +} + +// GetExchangeId returns the ExchangeId field value +func (o *OrderCancelSingleRequest) GetExchangeId() string { + if o == nil { + var ret string + return ret + } + + return o.ExchangeId +} + +// GetExchangeIdOk returns a tuple with the ExchangeId field value +// and a boolean to check if the value has been set. +func (o *OrderCancelSingleRequest) GetExchangeIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ExchangeId, true +} + +// SetExchangeId sets field value +func (o *OrderCancelSingleRequest) SetExchangeId(v string) { + o.ExchangeId = v +} + +// GetExchangeOrderId returns the ExchangeOrderId field value if set, zero value otherwise. +func (o *OrderCancelSingleRequest) GetExchangeOrderId() string { + if o == nil || o.ExchangeOrderId == nil { + var ret string + return ret + } + return *o.ExchangeOrderId +} + +// GetExchangeOrderIdOk returns a tuple with the ExchangeOrderId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderCancelSingleRequest) GetExchangeOrderIdOk() (*string, bool) { + if o == nil || o.ExchangeOrderId == nil { + return nil, false + } + return o.ExchangeOrderId, true +} + +// HasExchangeOrderId returns a boolean if a field has been set. +func (o *OrderCancelSingleRequest) HasExchangeOrderId() bool { + if o != nil && o.ExchangeOrderId != nil { + return true + } + + return false +} + +// SetExchangeOrderId gets a reference to the given string and assigns it to the ExchangeOrderId field. +func (o *OrderCancelSingleRequest) SetExchangeOrderId(v string) { + o.ExchangeOrderId = &v +} + +// GetClientOrderId returns the ClientOrderId field value if set, zero value otherwise. +func (o *OrderCancelSingleRequest) GetClientOrderId() string { + if o == nil || o.ClientOrderId == nil { + var ret string + return ret + } + return *o.ClientOrderId +} + +// GetClientOrderIdOk returns a tuple with the ClientOrderId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderCancelSingleRequest) GetClientOrderIdOk() (*string, bool) { + if o == nil || o.ClientOrderId == nil { + return nil, false + } + return o.ClientOrderId, true +} + +// HasClientOrderId returns a boolean if a field has been set. +func (o *OrderCancelSingleRequest) HasClientOrderId() bool { + if o != nil && o.ClientOrderId != nil { + return true + } + + return false +} + +// SetClientOrderId gets a reference to the given string and assigns it to the ClientOrderId field. +func (o *OrderCancelSingleRequest) SetClientOrderId(v string) { + o.ClientOrderId = &v +} + +func (o OrderCancelSingleRequest) MarshalJSON() (b []byte, err error) { + oMap := orderedmap.New() + oMap.SetEscapeHTML(false) + oMap.Set("type", o.Type) + oMap.Set("exchange_id", o.ExchangeId) + if o.ExchangeOrderId == nil { + oMap.Set("client_order_id", o.ClientOrderId) + } + if o.ClientOrderId == nil { + oMap.Set("exchange_order_id", o.ExchangeOrderId) + } + + b, err = json.Marshal(oMap) + if err != nil { + log.Println("Error marshaling Hello object") + log.Println(err) + return nil, err + } + + var prettyJSON bytes.Buffer + err = json.Indent(&prettyJSON, b, "", "\t") + if err != nil { + log.Println("Error making JSON pretty") + log.Println(err) + return nil, err + } + + return b, err +} diff --git a/oeml-sdk/go-ws/sdk/types/order_execution_report.go b/oeml-sdk/go-ws/sdk/types/order_execution_report.go new file mode 100644 index 0000000000..2172141fa3 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/order_execution_report.go @@ -0,0 +1,747 @@ +package types + +import ( + "encoding/json" + "fmt" +) + +// OrderExecutionReport The order execution report object. +type OrderExecutionReport struct { + // Exchange identifier used to identify the routing destination. + ExchangeId string `json:"exchange_id"` + // The unique identifier of the order assigned by the client. + ClientOrderId string `json:"client_order_id"` + // Exchange symbol. One of the properties (`symbol_id_exchange`, `symbol_id_coinapi`) is required to identify the market for the new order. + SymbolIdExchange *string `json:"symbol_id_exchange,omitempty"` + // CoinAPI symbol. One of the properties (`symbol_id_exchange`, `symbol_id_coinapi`) is required to identify the market for the new order. + SymbolIdCoinapi *string `json:"symbol_id_coinapi,omitempty"` + // Order quantity. + AmountOrder float64 `json:"amount_order"` + // Order price. + Price float64 `json:"price"` + Side OrdSide `json:"side"` + OrderType OrdType `json:"order_type"` + TimeInForce TimeInForce `json:"time_in_force"` + // Expiration time. Conditionaly required for orders with time_in_force = `GOOD_TILL_TIME_EXCHANGE` or `GOOD_TILL_TIME_OEML`. + ExpireTime *string `json:"expire_time,omitempty"` + // Order execution instructions are documented in the separate section: OEML / Starter Guide / Order parameters / Execution instructions + ExecInst *[]string `json:"exec_inst,omitempty"` + // The unique identifier of the order assigned by the client converted to the exchange order tag format for the purpose of tracking it. + ClientOrderIdFormatExchange string `json:"client_order_id_format_exchange"` + // Unique identifier of the order assigned by the exchange or executing system. + ExchangeOrderId *string `json:"exchange_order_id,omitempty"` + // Quantity open for further execution. `amount_open` = `amount_order` - `amount_filled` + AmountOpen float64 `json:"amount_open"` + // Total quantity filled. + AmountFilled float64 `json:"amount_filled"` + // Calculated average price of all fills on this order. + AvgPx *float64 `json:"avg_px,omitempty"` + Status OrdStatus `json:"status"` + // Timestamped history of order status changes. + StatusHistory *[][]string `json:"status_history,omitempty"` + // Error message. + ErrorMessage *string `json:"error_message,omitempty"` + // Relay fill information on working orders. + Fills *[]Fills `json:"fills,omitempty"` +} + +func (o *OrderExecutionReport) String() string { + return fmt.Sprintf(" \n ExchangeId: %v, \n ClientOrderId: %v, \n SymbolIdExchange: %v, \n SymbolIdCoinapi: %v, \n AmountOrder: %v, \n Price: %v, \n Side: %v, \n OrderType: %v, \n TimeInForce: %v, \n ExpireTime: %v, \n ExecInst: %v, \n ClientOrderIdFormatExchange: %v, \n ExchangeOrderId: %v, \n AmountOpen: %v, \n AmountFilled: %v, \n AvgPrice: %v, \n Status: %v, \n StatusHistory: %v, \n ErrorMessage: %v, \n Fills: %v", + o.GetExchangeId(), + o.GetClientOrderId(), + o.GetSymbolIdExchange(), + o.GetSymbolIdCoinapi(), + o.GetAmountOrder(), + o.GetPrice(), + o.GetSide(), + o.GetOrderType(), + o.GetTimeInForce(), + o.GetExpireTime(), + o.GetExecInst(), + o.GetClientOrderIdFormatExchange(), + o.GetExchangeOrderId(), + o.GetAmountOpen(), + o.GetAmountFilled(), + o.GetAvgPx(), + o.GetStatus(), + o.GetStatusHistory(), + o.GetErrorMessage(), + o.GetFills(), + ) +} + +// NewOrderExecutionReport instantiates a new OrderExecutionReport object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewOrderExecutionReport(exchangeId string, clientOrderId string, amountOrder float64, price float64, side OrdSide, orderType OrdType, timeInForce TimeInForce, clientOrderIdFormatExchange string, amountOpen float64, amountFilled float64, status OrdStatus) *OrderExecutionReport { + this := OrderExecutionReport{} + this.ExchangeId = exchangeId + this.ClientOrderId = clientOrderId + this.AmountOrder = amountOrder + this.Price = price + this.Side = side + this.OrderType = orderType + this.TimeInForce = timeInForce + this.ClientOrderIdFormatExchange = clientOrderIdFormatExchange + this.AmountOpen = amountOpen + this.AmountFilled = amountFilled + this.Status = status + return &this +} + +// NewOrderExecutionReportWithDefaults instantiates a new OrderExecutionReport object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewOrderExecutionReportWithDefaults() *OrderExecutionReport { + this := OrderExecutionReport{} + return &this +} + +// GetExchangeId returns the ExchangeId field value +func (o *OrderExecutionReport) GetExchangeId() string { + if o == nil { + var ret string + return ret + } + return o.ExchangeId +} + +// GetExchangeIdOk returns a tuple with the ExchangeId field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetExchangeIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ExchangeId, true +} + +// SetExchangeId sets field value +func (o *OrderExecutionReport) SetExchangeId(v string) { + o.ExchangeId = v +} + +// GetClientOrderId returns the ClientOrderId field value +func (o *OrderExecutionReport) GetClientOrderId() string { + if o == nil { + var ret string + return ret + } + return o.ClientOrderId +} + +// GetClientOrderIdOk returns a tuple with the ClientOrderId field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetClientOrderIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ClientOrderId, true +} + +// SetClientOrderId sets field value +func (o *OrderExecutionReport) SetClientOrderId(v string) { + o.ClientOrderId = v +} + +// GetSymbolIdExchange returns the SymbolIdExchange field value if set, zero value otherwise. +func (o *OrderExecutionReport) GetSymbolIdExchange() string { + if o == nil || o.SymbolIdExchange == nil { + var ret string + return ret + } + return *o.SymbolIdExchange +} + +// GetSymbolIdExchangeOk returns a tuple with the SymbolIdExchange field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetSymbolIdExchangeOk() (*string, bool) { + if o == nil || o.SymbolIdExchange == nil { + return nil, false + } + return o.SymbolIdExchange, true +} + +// HasSymbolIdExchange returns a boolean if a field has been set. +func (o *OrderExecutionReport) HasSymbolIdExchange() bool { + if o != nil && o.SymbolIdExchange != nil { + return true + } + + return false +} + +// SetSymbolIdExchange gets a reference to the given string and assigns it to the SymbolIdExchange field. +func (o *OrderExecutionReport) SetSymbolIdExchange(v string) { + o.SymbolIdExchange = &v +} + +// GetSymbolIdCoinapi returns the SymbolIdCoinapi field value if set, zero value otherwise. +func (o *OrderExecutionReport) GetSymbolIdCoinapi() string { + if o == nil || o.SymbolIdCoinapi == nil { + var ret string + return ret + } + return *o.SymbolIdCoinapi +} + +// GetSymbolIdCoinapiOk returns a tuple with the SymbolIdCoinapi field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetSymbolIdCoinapiOk() (*string, bool) { + if o == nil || o.SymbolIdCoinapi == nil { + return nil, false + } + return o.SymbolIdCoinapi, true +} + +// HasSymbolIdCoinapi returns a boolean if a field has been set. +func (o *OrderExecutionReport) HasSymbolIdCoinapi() bool { + if o != nil && o.SymbolIdCoinapi != nil { + return true + } + return false +} + +// SetSymbolIdCoinapi gets a reference to the given string and assigns it to the SymbolIdCoinapi field. +func (o *OrderExecutionReport) SetSymbolIdCoinapi(v string) { + o.SymbolIdCoinapi = &v +} + +// GetAmountOrder returns the AmountOrder field value +func (o *OrderExecutionReport) GetAmountOrder() float64 { + if o == nil { + var ret float64 + return ret + } + return o.AmountOrder +} + +// GetAmountOrderOk returns a tuple with the AmountOrder field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetAmountOrderOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.AmountOrder, true +} + +// SetAmountOrder sets field value +func (o *OrderExecutionReport) SetAmountOrder(v float64) { + o.AmountOrder = v +} + +// GetPrice returns the Price field value +func (o *OrderExecutionReport) GetPrice() float64 { + if o == nil { + var ret float64 + return ret + } + return o.Price +} + +// GetPriceOk returns a tuple with the Price field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetPriceOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.Price, true +} + +// SetPrice sets field value +func (o *OrderExecutionReport) SetPrice(v float64) { + o.Price = v +} + +// GetSide returns the Side field value +func (o *OrderExecutionReport) GetSide() OrdSide { + if o == nil { + var ret OrdSide + return ret + } + + return o.Side +} + +// GetSideOk returns a tuple with the Side field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetSideOk() (*OrdSide, bool) { + if o == nil { + return nil, false + } + return &o.Side, true +} + +// SetSide sets field value +func (o *OrderExecutionReport) SetSide(v OrdSide) { + o.Side = v +} + +// GetOrderType returns the OrderType field value +func (o *OrderExecutionReport) GetOrderType() OrdType { + if o == nil { + var ret OrdType + return ret + } + + return o.OrderType +} + +// GetOrderTypeOk returns a tuple with the OrderType field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetOrderTypeOk() (*OrdType, bool) { + if o == nil { + return nil, false + } + return &o.OrderType, true +} + +// SetOrderType sets field value +func (o *OrderExecutionReport) SetOrderType(v OrdType) { + o.OrderType = v +} + +// GetTimeInForce returns the TimeInForce field value +func (o *OrderExecutionReport) GetTimeInForce() TimeInForce { + if o == nil { + var ret TimeInForce + return ret + } + + return o.TimeInForce +} + +// GetTimeInForceOk returns a tuple with the TimeInForce field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetTimeInForceOk() (*TimeInForce, bool) { + if o == nil { + return nil, false + } + return &o.TimeInForce, true +} + +// SetTimeInForce sets field value +func (o *OrderExecutionReport) SetTimeInForce(v TimeInForce) { + o.TimeInForce = v +} + +// GetExpireTime returns the ExpireTime field value if set, zero value otherwise. +func (o *OrderExecutionReport) GetExpireTime() string { + if o == nil || o.ExpireTime == nil { + var ret string + return ret + } + return *o.ExpireTime +} + +// GetExpireTimeOk returns a tuple with the ExpireTime field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetExpireTimeOk() (*string, bool) { + if o == nil || o.ExpireTime == nil { + return nil, false + } + return o.ExpireTime, true +} + +// HasExpireTime returns a boolean if a field has been set. +func (o *OrderExecutionReport) HasExpireTime() bool { + if o != nil && o.ExpireTime != nil { + return true + } + + return false +} + +// SetExpireTime gets a reference to the given string and assigns it to the ExpireTime field. +func (o *OrderExecutionReport) SetExpireTime(v string) { + o.ExpireTime = &v +} + +// GetExecInst returns the ExecInst field value if set, zero value otherwise. +func (o *OrderExecutionReport) GetExecInst() []string { + if o == nil || o.ExecInst == nil { + var ret []string + return ret + } + return *o.ExecInst +} + +// GetExecInstOk returns a tuple with the ExecInst field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetExecInstOk() (*[]string, bool) { + if o == nil || o.ExecInst == nil { + return nil, false + } + return o.ExecInst, true +} + +// HasExecInst returns a boolean if a field has been set. +func (o *OrderExecutionReport) HasExecInst() bool { + if o != nil && o.ExecInst != nil { + return true + } + + return false +} + +// SetExecInst gets a reference to the given []string and assigns it to the ExecInst field. +func (o *OrderExecutionReport) SetExecInst(v []string) { + o.ExecInst = &v +} + +// GetClientOrderIdFormatExchange returns the ClientOrderIdFormatExchange field value +func (o *OrderExecutionReport) GetClientOrderIdFormatExchange() string { + if o == nil { + var ret string + return ret + } + + return o.ClientOrderIdFormatExchange +} + +// GetClientOrderIdFormatExchangeOk returns a tuple with the ClientOrderIdFormatExchange field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetClientOrderIdFormatExchangeOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ClientOrderIdFormatExchange, true +} + +// SetClientOrderIdFormatExchange sets field value +func (o *OrderExecutionReport) SetClientOrderIdFormatExchange(v string) { + o.ClientOrderIdFormatExchange = v +} + +// GetExchangeOrderId returns the ExchangeOrderId field value if set, zero value otherwise. +func (o *OrderExecutionReport) GetExchangeOrderId() string { + if o == nil || o.ExchangeOrderId == nil { + var ret string + return ret + } + return *o.ExchangeOrderId +} + +// GetExchangeOrderIdOk returns a tuple with the ExchangeOrderId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetExchangeOrderIdOk() (*string, bool) { + if o == nil || o.ExchangeOrderId == nil { + return nil, false + } + return o.ExchangeOrderId, true +} + +// HasExchangeOrderId returns a boolean if a field has been set. +func (o *OrderExecutionReport) HasExchangeOrderId() bool { + if o != nil && o.ExchangeOrderId != nil { + return true + } + + return false +} + +// SetExchangeOrderId gets a reference to the given string and assigns it to the ExchangeOrderId field. +func (o *OrderExecutionReport) SetExchangeOrderId(v string) { + o.ExchangeOrderId = &v +} + +// GetAmountOpen returns the AmountOpen field value +func (o *OrderExecutionReport) GetAmountOpen() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.AmountOpen +} + +// GetAmountOpenOk returns a tuple with the AmountOpen field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetAmountOpenOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.AmountOpen, true +} + +// SetAmountOpen sets field value +func (o *OrderExecutionReport) SetAmountOpen(v float64) { + o.AmountOpen = v +} + +// GetAmountFilled returns the AmountFilled field value +func (o *OrderExecutionReport) GetAmountFilled() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.AmountFilled +} + +// GetAmountFilledOk returns a tuple with the AmountFilled field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetAmountFilledOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.AmountFilled, true +} + +// SetAmountFilled sets field value +func (o *OrderExecutionReport) SetAmountFilled(v float64) { + o.AmountFilled = v +} + +// GetAvgPx returns the AvgPx field value if set, zero value otherwise. +func (o *OrderExecutionReport) GetAvgPx() float64 { + if o == nil || o.AvgPx == nil { + var ret float64 + return ret + } + return *o.AvgPx +} + +// GetAvgPxOk returns a tuple with the AvgPx field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetAvgPxOk() (*float64, bool) { + if o == nil || o.AvgPx == nil { + return nil, false + } + return o.AvgPx, true +} + +// HasAvgPx returns a boolean if a field has been set. +func (o *OrderExecutionReport) HasAvgPx() bool { + if o != nil && o.AvgPx != nil { + return true + } + + return false +} + +// SetAvgPx gets a reference to the given float64 and assigns it to the AvgPx field. +func (o *OrderExecutionReport) SetAvgPx(v float64) { + o.AvgPx = &v +} + +// GetStatus returns the Status field value +func (o *OrderExecutionReport) GetStatus() OrdStatus { + if o == nil { + var ret OrdStatus + return ret + } + + return o.Status +} + +// GetStatusOk returns a tuple with the Status field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetStatusOk() (*OrdStatus, bool) { + if o == nil { + return nil, false + } + return &o.Status, true +} + +// SetStatus sets field value +func (o *OrderExecutionReport) SetStatus(v OrdStatus) { + o.Status = v +} + +// GetStatusHistory returns the StatusHistory field value if set, zero value otherwise. +func (o *OrderExecutionReport) GetStatusHistory() [][]string { + if o == nil || o.StatusHistory == nil { + var ret [][]string + return ret + } + return *o.StatusHistory +} + +// GetStatusHistoryOk returns a tuple with the StatusHistory field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetStatusHistoryOk() (*[][]string, bool) { + if o == nil || o.StatusHistory == nil { + return nil, false + } + return o.StatusHistory, true +} + +// HasStatusHistory returns a boolean if a field has been set. +func (o *OrderExecutionReport) HasStatusHistory() bool { + if o != nil && o.StatusHistory != nil { + return true + } + + return false +} + +// SetStatusHistory gets a reference to the given [][]string and assigns it to the StatusHistory field. +func (o *OrderExecutionReport) SetStatusHistory(v [][]string) { + o.StatusHistory = &v +} + +// GetErrorMessage returns the ErrorMessage field value if set, zero value otherwise. +func (o *OrderExecutionReport) GetErrorMessage() string { + if o == nil || o.ErrorMessage == nil { + var ret string + return ret + } + return *o.ErrorMessage +} + +// GetErrorMessageOk returns a tuple with the ErrorMessage field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetErrorMessageOk() (*string, bool) { + if o == nil || o.ErrorMessage == nil { + return nil, false + } + return o.ErrorMessage, true +} + +// HasErrorMessage returns a boolean if a field has been set. +func (o *OrderExecutionReport) HasErrorMessage() bool { + if o != nil && o.ErrorMessage != nil { + return true + } + + return false +} + +// SetErrorMessage gets a reference to the given string and assigns it to the ErrorMessage field. +func (o *OrderExecutionReport) SetErrorMessage(v string) { + o.ErrorMessage = &v +} + +// GetFills returns the Fills field value if set, zero value otherwise. +func (o *OrderExecutionReport) GetFills() []Fills { + if o == nil || o.Fills == nil { + var ret []Fills + return ret + } + return *o.Fills +} + +// GetFillsOk returns a tuple with the Fills field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderExecutionReport) GetFillsOk() (*[]Fills, bool) { + if o == nil || o.Fills == nil { + return nil, false + } + return o.Fills, true +} + +// HasFills returns a boolean if a field has been set. +func (o *OrderExecutionReport) HasFills() bool { + if o != nil && o.Fills != nil { + return true + } + + return false +} + +// SetFills gets a reference to the given []Fills and assigns it to the Fills field. +func (o *OrderExecutionReport) SetFills(v []Fills) { + o.Fills = &v +} + +func (o OrderExecutionReport) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if true { + toSerialize["exchange_id"] = o.ExchangeId + } + if true { + toSerialize["client_order_id"] = o.ClientOrderId + } + if o.SymbolIdExchange != nil { + toSerialize["symbol_id_exchange"] = o.SymbolIdExchange + } + if o.SymbolIdCoinapi != nil { + toSerialize["symbol_id_coinapi"] = o.SymbolIdCoinapi + } + if true { + toSerialize["amount_order"] = o.AmountOrder + } + if true { + toSerialize["price"] = o.Price + } + if true { + toSerialize["side"] = o.Side + } + if true { + toSerialize["order_type"] = o.OrderType + } + if true { + toSerialize["time_in_force"] = o.TimeInForce + } + if o.ExpireTime != nil { + toSerialize["expire_time"] = o.ExpireTime + } + if o.ExecInst != nil { + toSerialize["exec_inst"] = o.ExecInst + } + if true { + toSerialize["client_order_id_format_exchange"] = o.ClientOrderIdFormatExchange + } + if o.ExchangeOrderId != nil { + toSerialize["exchange_order_id"] = o.ExchangeOrderId + } + if true { + toSerialize["amount_open"] = o.AmountOpen + } + if true { + toSerialize["amount_filled"] = o.AmountFilled + } + if o.AvgPx != nil { + toSerialize["avg_px"] = o.AvgPx + } + if true { + toSerialize["status"] = o.Status + } + if o.StatusHistory != nil { + toSerialize["status_history"] = o.StatusHistory + } + if o.ErrorMessage != nil { + toSerialize["error_message"] = o.ErrorMessage + } + if o.Fills != nil { + toSerialize["fills"] = o.Fills + } + return json.Marshal(toSerialize) +} + +type NullableOrderExecutionReport struct { + value *OrderExecutionReport + isSet bool +} + +func (v NullableOrderExecutionReport) Get() *OrderExecutionReport { + return v.value +} + +func (v *NullableOrderExecutionReport) Set(val *OrderExecutionReport) { + v.value = val + v.isSet = true +} + +func (v NullableOrderExecutionReport) IsSet() bool { + return v.isSet +} + +func (v *NullableOrderExecutionReport) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableOrderExecutionReport(val *OrderExecutionReport) *NullableOrderExecutionReport { + return &NullableOrderExecutionReport{value: val, isSet: true} +} + +func (v NullableOrderExecutionReport) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableOrderExecutionReport) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/order_execution_report_all.go b/oeml-sdk/go-ws/sdk/types/order_execution_report_all.go new file mode 100644 index 0000000000..6d1a16109d --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/order_execution_report_all.go @@ -0,0 +1,371 @@ +package types + +import ( + "encoding/json" +) + +// OrderExecutionReportAllOf The order execution report message. +type OrderExecutionReportAllOf struct { + // The unique identifier of the order assigned by the client converted to the exchange order tag format for the purpose of tracking it. + ClientOrderIdFormatExchange string `json:"client_order_id_format_exchange"` + // Unique identifier of the order assigned by the exchange or executing system. + ExchangeOrderId *string `json:"exchange_order_id,omitempty"` + // Quantity open for further execution. `amount_open` = `amount_order` - `amount_filled` + AmountOpen float64 `json:"amount_open"` + // Total quantity filled. + AmountFilled float64 `json:"amount_filled"` + // Calculated average price of all fills on this order. + AvgPx *float64 `json:"avg_px,omitempty"` + Status OrdStatus `json:"status"` + // Timestamped history of order status changes. + StatusHistory *[][]string `json:"status_history,omitempty"` + // Error message. + ErrorMessage *string `json:"error_message,omitempty"` + // Relay fill information on working orders. + Fills *[]Fills `json:"fills,omitempty"` +} + +// NewOrderExecutionReportAllOf instantiates a new OrderExecutionReportAllOf object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewOrderExecutionReportAllOf(clientOrderIdFormatExchange string, amountOpen float64, amountFilled float64, status OrdStatus) *OrderExecutionReportAllOf { + this := OrderExecutionReportAllOf{} + this.ClientOrderIdFormatExchange = clientOrderIdFormatExchange + this.AmountOpen = amountOpen + this.AmountFilled = amountFilled + this.Status = status + return &this +} + +// NewOrderExecutionReportAllOfWithDefaults instantiates a new OrderExecutionReportAllOf object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewOrderExecutionReportAllOfWithDefaults() *OrderExecutionReportAllOf { + this := OrderExecutionReportAllOf{} + return &this +} + +// GetClientOrderIdFormatExchange returns the ClientOrderIdFormatExchange field value +func (o *OrderExecutionReportAllOf) GetClientOrderIdFormatExchange() string { + if o == nil { + var ret string + return ret + } + + return o.ClientOrderIdFormatExchange +} + +// GetClientOrderIdFormatExchangeOk returns a tuple with the ClientOrderIdFormatExchange field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReportAllOf) GetClientOrderIdFormatExchangeOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ClientOrderIdFormatExchange, true +} + +// SetClientOrderIdFormatExchange sets field value +func (o *OrderExecutionReportAllOf) SetClientOrderIdFormatExchange(v string) { + o.ClientOrderIdFormatExchange = v +} + +// GetExchangeOrderId returns the ExchangeOrderId field value if set, zero value otherwise. +func (o *OrderExecutionReportAllOf) GetExchangeOrderId() string { + if o == nil || o.ExchangeOrderId == nil { + var ret string + return ret + } + return *o.ExchangeOrderId +} + +// GetExchangeOrderIdOk returns a tuple with the ExchangeOrderId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderExecutionReportAllOf) GetExchangeOrderIdOk() (*string, bool) { + if o == nil || o.ExchangeOrderId == nil { + return nil, false + } + return o.ExchangeOrderId, true +} + +// HasExchangeOrderId returns a boolean if a field has been set. +func (o *OrderExecutionReportAllOf) HasExchangeOrderId() bool { + if o != nil && o.ExchangeOrderId != nil { + return true + } + + return false +} + +// SetExchangeOrderId gets a reference to the given string and assigns it to the ExchangeOrderId field. +func (o *OrderExecutionReportAllOf) SetExchangeOrderId(v string) { + o.ExchangeOrderId = &v +} + +// GetAmountOpen returns the AmountOpen field value +func (o *OrderExecutionReportAllOf) GetAmountOpen() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.AmountOpen +} + +// GetAmountOpenOk returns a tuple with the AmountOpen field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReportAllOf) GetAmountOpenOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.AmountOpen, true +} + +// SetAmountOpen sets field value +func (o *OrderExecutionReportAllOf) SetAmountOpen(v float64) { + o.AmountOpen = v +} + +// GetAmountFilled returns the AmountFilled field value +func (o *OrderExecutionReportAllOf) GetAmountFilled() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.AmountFilled +} + +// GetAmountFilledOk returns a tuple with the AmountFilled field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReportAllOf) GetAmountFilledOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.AmountFilled, true +} + +// SetAmountFilled sets field value +func (o *OrderExecutionReportAllOf) SetAmountFilled(v float64) { + o.AmountFilled = v +} + +// GetAvgPx returns the AvgPx field value if set, zero value otherwise. +func (o *OrderExecutionReportAllOf) GetAvgPx() float64 { + if o == nil || o.AvgPx == nil { + var ret float64 + return ret + } + return *o.AvgPx +} + +// GetAvgPxOk returns a tuple with the AvgPx field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderExecutionReportAllOf) GetAvgPxOk() (*float64, bool) { + if o == nil || o.AvgPx == nil { + return nil, false + } + return o.AvgPx, true +} + +// HasAvgPx returns a boolean if a field has been set. +func (o *OrderExecutionReportAllOf) HasAvgPx() bool { + if o != nil && o.AvgPx != nil { + return true + } + + return false +} + +// SetAvgPx gets a reference to the given float64 and assigns it to the AvgPx field. +func (o *OrderExecutionReportAllOf) SetAvgPx(v float64) { + o.AvgPx = &v +} + +// GetStatus returns the Status field value +func (o *OrderExecutionReportAllOf) GetStatus() OrdStatus { + if o == nil { + var ret OrdStatus + return ret + } + + return o.Status +} + +// GetStatusOk returns a tuple with the Status field value +// and a boolean to check if the value has been set. +func (o *OrderExecutionReportAllOf) GetStatusOk() (*OrdStatus, bool) { + if o == nil { + return nil, false + } + return &o.Status, true +} + +// SetStatus sets field value +func (o *OrderExecutionReportAllOf) SetStatus(v OrdStatus) { + o.Status = v +} + +// GetStatusHistory returns the StatusHistory field value if set, zero value otherwise. +func (o *OrderExecutionReportAllOf) GetStatusHistory() [][]string { + if o == nil || o.StatusHistory == nil { + var ret [][]string + return ret + } + return *o.StatusHistory +} + +// GetStatusHistoryOk returns a tuple with the StatusHistory field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderExecutionReportAllOf) GetStatusHistoryOk() (*[][]string, bool) { + if o == nil || o.StatusHistory == nil { + return nil, false + } + return o.StatusHistory, true +} + +// HasStatusHistory returns a boolean if a field has been set. +func (o *OrderExecutionReportAllOf) HasStatusHistory() bool { + if o != nil && o.StatusHistory != nil { + return true + } + + return false +} + +// SetStatusHistory gets a reference to the given [][]string and assigns it to the StatusHistory field. +func (o *OrderExecutionReportAllOf) SetStatusHistory(v [][]string) { + o.StatusHistory = &v +} + +// GetErrorMessage returns the ErrorMessage field value if set, zero value otherwise. +func (o *OrderExecutionReportAllOf) GetErrorMessage() string { + if o == nil || o.ErrorMessage == nil { + var ret string + return ret + } + return *o.ErrorMessage +} + +// GetErrorMessageOk returns a tuple with the ErrorMessage field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderExecutionReportAllOf) GetErrorMessageOk() (*string, bool) { + if o == nil || o.ErrorMessage == nil { + return nil, false + } + return o.ErrorMessage, true +} + +// HasErrorMessage returns a boolean if a field has been set. +func (o *OrderExecutionReportAllOf) HasErrorMessage() bool { + if o != nil && o.ErrorMessage != nil { + return true + } + + return false +} + +// SetErrorMessage gets a reference to the given string and assigns it to the ErrorMessage field. +func (o *OrderExecutionReportAllOf) SetErrorMessage(v string) { + o.ErrorMessage = &v +} + +// GetFills returns the Fills field value if set, zero value otherwise. +func (o *OrderExecutionReportAllOf) GetFills() []Fills { + if o == nil || o.Fills == nil { + var ret []Fills + return ret + } + return *o.Fills +} + +// GetFillsOk returns a tuple with the Fills field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderExecutionReportAllOf) GetFillsOk() (*[]Fills, bool) { + if o == nil || o.Fills == nil { + return nil, false + } + return o.Fills, true +} + +// HasFills returns a boolean if a field has been set. +func (o *OrderExecutionReportAllOf) HasFills() bool { + if o != nil && o.Fills != nil { + return true + } + + return false +} + +// SetFills gets a reference to the given []Fills and assigns it to the Fills field. +func (o *OrderExecutionReportAllOf) SetFills(v []Fills) { + o.Fills = &v +} + +func (o OrderExecutionReportAllOf) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if true { + toSerialize["client_order_id_format_exchange"] = o.ClientOrderIdFormatExchange + } + if o.ExchangeOrderId != nil { + toSerialize["exchange_order_id"] = o.ExchangeOrderId + } + if true { + toSerialize["amount_open"] = o.AmountOpen + } + if true { + toSerialize["amount_filled"] = o.AmountFilled + } + if o.AvgPx != nil { + toSerialize["avg_px"] = o.AvgPx + } + if true { + toSerialize["status"] = o.Status + } + if o.StatusHistory != nil { + toSerialize["status_history"] = o.StatusHistory + } + if o.ErrorMessage != nil { + toSerialize["error_message"] = o.ErrorMessage + } + if o.Fills != nil { + toSerialize["fills"] = o.Fills + } + return json.Marshal(toSerialize) +} + +type NullableOrderExecutionReportAllOf struct { + value *OrderExecutionReportAllOf + isSet bool +} + +func (v NullableOrderExecutionReportAllOf) Get() *OrderExecutionReportAllOf { + return v.value +} + +func (v *NullableOrderExecutionReportAllOf) Set(val *OrderExecutionReportAllOf) { + v.value = val + v.isSet = true +} + +func (v NullableOrderExecutionReportAllOf) IsSet() bool { + return v.isSet +} + +func (v *NullableOrderExecutionReportAllOf) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableOrderExecutionReportAllOf(val *OrderExecutionReportAllOf) *NullableOrderExecutionReportAllOf { + return &NullableOrderExecutionReportAllOf{value: val, isSet: true} +} + +func (v NullableOrderExecutionReportAllOf) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableOrderExecutionReportAllOf) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/order_fill.go b/oeml-sdk/go-ws/sdk/types/order_fill.go new file mode 100644 index 0000000000..97e37ca19a --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/order_fill.go @@ -0,0 +1,187 @@ +package types + +import ( + "encoding/json" + "fmt" +) + +// Fills struct for Fills +type Fills struct { + // Execution time. + Time *string `json:"time,omitempty"` + // Execution price. + Price *float64 `json:"price,omitempty"` + // Executed quantity. + Amount *float64 `json:"amount,omitempty"` +} + +func (o *Fills) String() string { + return fmt.Sprintf(" Time: %v, Price: %v, Amount: %v", + o.Time, + o.Price, + o.Amount, + ) +} + +// NewFills instantiates a new Fills object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewFills() *Fills { + this := Fills{} + return &this +} + +// NewFillsWithDefaults instantiates a new Fills object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewFillsWithDefaults() *Fills { + this := Fills{} + return &this +} + +// GetTime returns the Time field value if set, zero value otherwise. +func (o *Fills) GetTime() string { + if o == nil || o.Time == nil { + var ret string + return ret + } + return *o.Time +} + +// GetTimeOk returns a tuple with the Time field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Fills) GetTimeOk() (*string, bool) { + if o == nil || o.Time == nil { + return nil, false + } + return o.Time, true +} + +// HasTime returns a boolean if a field has been set. +func (o *Fills) HasTime() bool { + if o != nil && o.Time != nil { + return true + } + + return false +} + +// SetTime gets a reference to the given string and assigns it to the Time field. +func (o *Fills) SetTime(v string) { + o.Time = &v +} + +// GetPrice returns the Price field value if set, zero value otherwise. +func (o *Fills) GetPrice() float64 { + if o == nil || o.Price == nil { + var ret float64 + return ret + } + return *o.Price +} + +// GetPriceOk returns a tuple with the Price field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Fills) GetPriceOk() (*float64, bool) { + if o == nil || o.Price == nil { + return nil, false + } + return o.Price, true +} + +// HasPrice returns a boolean if a field has been set. +func (o *Fills) HasPrice() bool { + if o != nil && o.Price != nil { + return true + } + + return false +} + +// SetPrice gets a reference to the given float64 and assigns it to the Price field. +func (o *Fills) SetPrice(v float64) { + o.Price = &v +} + +// GetAmount returns the Amount field value if set, zero value otherwise. +func (o *Fills) GetAmount() float64 { + if o == nil || o.Amount == nil { + var ret float64 + return ret + } + return *o.Amount +} + +// GetAmountOk returns a tuple with the Amount field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Fills) GetAmountOk() (*float64, bool) { + if o == nil || o.Amount == nil { + return nil, false + } + return o.Amount, true +} + +// HasAmount returns a boolean if a field has been set. +func (o *Fills) HasAmount() bool { + if o != nil && o.Amount != nil { + return true + } + + return false +} + +// SetAmount gets a reference to the given float64 and assigns it to the Amount field. +func (o *Fills) SetAmount(v float64) { + o.Amount = &v +} + +func (o Fills) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.Time != nil { + toSerialize["time"] = o.Time + } + if o.Price != nil { + toSerialize["price"] = o.Price + } + if o.Amount != nil { + toSerialize["amount"] = o.Amount + } + return json.Marshal(toSerialize) +} + +type NullableFills struct { + value *Fills + isSet bool +} + +func (v NullableFills) Get() *Fills { + return v.value +} + +func (v *NullableFills) Set(val *Fills) { + v.value = val + v.isSet = true +} + +func (v NullableFills) IsSet() bool { + return v.isSet +} + +func (v *NullableFills) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFills(val *Fills) *NullableFills { + return &NullableFills{value: val, isSet: true} +} + +func (v NullableFills) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFills) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/order_new_single.go b/oeml-sdk/go-ws/sdk/types/order_new_single.go new file mode 100644 index 0000000000..26eefbb20a --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/order_new_single.go @@ -0,0 +1,376 @@ +package types + +import ( + "bytes" + "encoding/json" + "github.com/iancoleman/orderedmap" +) + +// OrderNewSingleRequest The new order message. +type OrderNewSingleRequest struct { + // Message type to identity the request + Type MessageType `json:"type"` + // Exchange identifier used to identify the routing destination. + ExchangeId string `json:"exchange_id"` + // The unique identifier of the order assigned by the client. + ClientOrderId string `json:"client_order_id"` + // Exchange symbol. One of the properties (`symbol_id_exchange`, `symbol_id_coinapi`) is required to identify the market for the new order. + SymbolIdExchange *string `json:"symbol_id_exchange,omitempty"` + // CoinAPI symbol. One of the properties (`symbol_id_exchange`, `symbol_id_coinapi`) is required to identify the market for the new order. + SymbolIdCoinapi *string `json:"symbol_id_coinapi,omitempty"` + // Order quantity. + AmountOrder float64 `json:"amount_order"` + // Order price. + Price float64 `json:"price"` + Side OrdSide `json:"side"` + OrderType OrdType `json:"order_type"` + TimeInForce TimeInForce `json:"time_in_force"` + // Expiration time. Conditionaly required for orders with time_in_force = `GOOD_TILL_TIME_EXCHANGE` or `GOOD_TILL_TIME_OEML`. + ExpireTime *string `json:"expire_time,omitempty"` + // Order execution instructions are documented in the separate section: OEML / Starter Guide / Order parameters / Execution instructions + ExecInst *[]string `json:"exec_inst,omitempty"` +} + +// GetExchangeId returns the ExchangeId field value +func (o *OrderNewSingleRequest) GetExchangeId() string { + if o == nil { + var ret string + return ret + } + + return o.ExchangeId +} + +// GetExchangeIdOk returns a tuple with the ExchangeId field value +// and a boolean to check if the value has been set. +func (o *OrderNewSingleRequest) GetExchangeIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ExchangeId, true +} + +// SetExchangeId sets field value +func (o *OrderNewSingleRequest) SetExchangeId(v string) { + o.ExchangeId = v +} + +// GetClientOrderId returns the ClientOrderId field value +func (o *OrderNewSingleRequest) GetClientOrderId() string { + if o == nil { + var ret string + return ret + } + + return o.ClientOrderId +} + +// GetClientOrderIdOk returns a tuple with the ClientOrderId field value +// and a boolean to check if the value has been set. +func (o *OrderNewSingleRequest) GetClientOrderIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ClientOrderId, true +} + +// SetClientOrderId sets field value +func (o *OrderNewSingleRequest) SetClientOrderId(v string) { + o.ClientOrderId = v +} + +// GetSymbolIdExchange returns the SymbolIdExchange field value if set, zero value otherwise. +func (o *OrderNewSingleRequest) GetSymbolIdExchange() string { + if o == nil || o.SymbolIdExchange == nil { + var ret string + return ret + } + return *o.SymbolIdExchange +} + +// GetSymbolIdExchangeOk returns a tuple with the SymbolIdExchange field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderNewSingleRequest) GetSymbolIdExchangeOk() (*string, bool) { + if o == nil || o.SymbolIdExchange == nil { + return nil, false + } + return o.SymbolIdExchange, true +} + +// HasSymbolIdExchange returns a boolean if a field has been set. +func (o *OrderNewSingleRequest) HasSymbolIdExchange() bool { + if o != nil && o.SymbolIdExchange != nil { + return true + } + + return false +} + +// SetSymbolIdExchange gets a reference to the given string and assigns it to the SymbolIdExchange field. +func (o *OrderNewSingleRequest) SetSymbolIdExchange(v string) { + o.SymbolIdExchange = &v +} + +// GetSymbolIdCoinapi returns the SymbolIdCoinapi field value if set, zero value otherwise. +func (o *OrderNewSingleRequest) GetSymbolIdCoinapi() string { + if o == nil || o.SymbolIdCoinapi == nil { + var ret string + return ret + } + return *o.SymbolIdCoinapi +} + +// GetSymbolIdCoinapiOk returns a tuple with the SymbolIdCoinapi field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderNewSingleRequest) GetSymbolIdCoinapiOk() (*string, bool) { + if o == nil || o.SymbolIdCoinapi == nil { + return nil, false + } + return o.SymbolIdCoinapi, true +} + +// HasSymbolIdCoinapi returns a boolean if a field has been set. +func (o *OrderNewSingleRequest) HasSymbolIdCoinapi() bool { + if o != nil && o.SymbolIdCoinapi != nil { + return true + } + + return false +} + +// SetSymbolIdCoinapi gets a reference to the given string and assigns it to the SymbolIdCoinapi field. +func (o *OrderNewSingleRequest) SetSymbolIdCoinapi(v string) { + o.SymbolIdCoinapi = &v +} + +// GetAmountOrder returns the AmountOrder field value +func (o *OrderNewSingleRequest) GetAmountOrder() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.AmountOrder +} + +// GetAmountOrderOk returns a tuple with the AmountOrder field value +// and a boolean to check if the value has been set. +func (o *OrderNewSingleRequest) GetAmountOrderOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.AmountOrder, true +} + +// SetAmountOrder sets field value +func (o *OrderNewSingleRequest) SetAmountOrder(v float64) { + o.AmountOrder = v +} + +// GetPrice returns the Price field value +func (o *OrderNewSingleRequest) GetPrice() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.Price +} + +// GetPriceOk returns a tuple with the Price field value +// and a boolean to check if the value has been set. +func (o *OrderNewSingleRequest) GetPriceOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.Price, true +} + +// SetPrice sets field value +func (o *OrderNewSingleRequest) SetPrice(v float64) { + o.Price = v +} + +// GetSide returns the Side field value +func (o *OrderNewSingleRequest) GetSide() OrdSide { + if o == nil { + var ret OrdSide + return ret + } + + return o.Side +} + +// GetSideOk returns a tuple with the Side field value +// and a boolean to check if the value has been set. +func (o *OrderNewSingleRequest) GetSideOk() (*OrdSide, bool) { + if o == nil { + return nil, false + } + return &o.Side, true +} + +// SetSide sets field value +func (o *OrderNewSingleRequest) SetSide(v OrdSide) { + o.Side = v +} + +// GetOrderType returns the OrderType field value +func (o *OrderNewSingleRequest) GetOrderType() OrdType { + if o == nil { + var ret OrdType + return ret + } + + return o.OrderType +} + +// GetOrderTypeOk returns a tuple with the OrderType field value +// and a boolean to check if the value has been set. +func (o *OrderNewSingleRequest) GetOrderTypeOk() (*OrdType, bool) { + if o == nil { + return nil, false + } + return &o.OrderType, true +} + +// SetOrderType sets field value +func (o *OrderNewSingleRequest) SetOrderType(v OrdType) { + o.OrderType = v +} + +// GetTimeInForce returns the TimeInForce field value +func (o *OrderNewSingleRequest) GetTimeInForce() TimeInForce { + if o == nil { + var ret TimeInForce + return ret + } + + return o.TimeInForce +} + +// GetTimeInForceOk returns a tuple with the TimeInForce field value +// and a boolean to check if the value has been set. +func (o *OrderNewSingleRequest) GetTimeInForceOk() (*TimeInForce, bool) { + if o == nil { + return nil, false + } + return &o.TimeInForce, true +} + +// SetTimeInForce sets field value +func (o *OrderNewSingleRequest) SetTimeInForce(v TimeInForce) { + o.TimeInForce = v +} + +// GetExpireTime returns the ExpireTime field value if set, zero value otherwise. +func (o *OrderNewSingleRequest) GetExpireTime() string { + if o == nil || o.ExpireTime == nil { + var ret string + return ret + } + return *o.ExpireTime +} + +// GetExpireTimeOk returns a tuple with the ExpireTime field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderNewSingleRequest) GetExpireTimeOk() (*string, bool) { + if o == nil || o.ExpireTime == nil { + return nil, false + } + return o.ExpireTime, true +} + +// HasExpireTime returns a boolean if a field has been set. +func (o *OrderNewSingleRequest) HasExpireTime() bool { + if o != nil && o.ExpireTime != nil { + return true + } + + return false +} + +// SetExpireTime gets a reference to the given string and assigns it to the ExpireTime field. +func (o *OrderNewSingleRequest) SetExpireTime(v string) { + o.ExpireTime = &v +} + +// GetExecInst returns the ExecInst field value if set, zero value otherwise. +func (o *OrderNewSingleRequest) GetExecInst() []string { + if o == nil || o.ExecInst == nil { + var ret []string + return ret + } + return *o.ExecInst +} + +// GetExecInstOk returns a tuple with the ExecInst field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *OrderNewSingleRequest) GetExecInstOk() (*[]string, bool) { + if o == nil || o.ExecInst == nil { + return nil, false + } + return o.ExecInst, true +} + +// HasExecInst returns a boolean if a field has been set. +func (o *OrderNewSingleRequest) HasExecInst() bool { + if o != nil && o.ExecInst != nil { + return true + } + + return false +} + +// SetExecInst gets a reference to the given []string and assigns it to the ExecInst field. +func (o *OrderNewSingleRequest) SetExecInst(v []string) { + o.ExecInst = &v +} + +func (o OrderNewSingleRequest) MarshalJSON() ([]byte, error) { + toSerialize := orderedmap.New() + toSerialize.SetEscapeHTML(false) + if true { + toSerialize.Set("type", o.Type) + } + if true { + toSerialize.Set("exchange_id", o.ExchangeId) + } + if true { + toSerialize.Set("client_order_id", o.ClientOrderId) + } + if o.SymbolIdExchange != nil { + toSerialize.Set("symbol_id_exchange", o.SymbolIdExchange) + } + if o.SymbolIdCoinapi != nil { + toSerialize.Set("symbol_id_coinapi", o.SymbolIdCoinapi) + } + if true { + toSerialize.Set("amount_order", o.AmountOrder) + } + if true { + toSerialize.Set("price", o.Price) + } + if true { + toSerialize.Set("side", o.Side) + } + if true { + toSerialize.Set("order_type", o.OrderType) + } + if true { + toSerialize.Set("time_in_force", o.TimeInForce) + } + if o.ExpireTime != nil { + toSerialize.Set("expire_time", o.ExpireTime) + } + if o.ExecInst != nil { + toSerialize.Set("exec_inst", o.ExecInst) + } + + var b []byte + b, err := json.Marshal(toSerialize) + var prettyJSON bytes.Buffer + err = json.Indent(&prettyJSON, b, "", "\t") + + return b, err +} diff --git a/oeml-sdk/go-ws/sdk/types/order_side.go b/oeml-sdk/go-ws/sdk/types/order_side.go new file mode 100644 index 0000000000..f3508fc0bc --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/order_side.go @@ -0,0 +1,110 @@ +package types + +import ( + "encoding/json" + "fmt" +) + +// OrdSide Side of order. +type OrdSide string + +// List of OrdSide +const ( + BUY OrdSide = "BUY" + SELL OrdSide = "SELL" +) + +var allowedOrdSideEnumValues = []OrdSide{ + "BUY", + "SELL", +} + +func (v *OrdSide) String() string { + switch *v { + case BUY: + return "BUY" + case SELL: + return "SELL" + default: + return "UNKNOWN OrdSide" + } +} + +func (v *OrdSide) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + enumTypeValue := OrdSide(value) + for _, existing := range allowedOrdSideEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid OrdSide", value) +} + +// NewOrdSideFromValue returns a pointer to a valid OrdSide +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewOrdSideFromValue(v string) (*OrdSide, error) { + ev := OrdSide(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for OrdSide: valid values are %v", v, allowedOrdSideEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v OrdSide) IsValid() bool { + for _, existing := range allowedOrdSideEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to OrdSide value +func (v OrdSide) Ptr() *OrdSide { + return &v +} + +type NullableOrdSide struct { + value *OrdSide + isSet bool +} + +func (v NullableOrdSide) Get() *OrdSide { + return v.value +} + +func (v *NullableOrdSide) Set(val *OrdSide) { + v.value = val + v.isSet = true +} + +func (v NullableOrdSide) IsSet() bool { + return v.isSet +} + +func (v *NullableOrdSide) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableOrdSide(val *OrdSide) *NullableOrdSide { + return &NullableOrdSide{value: val, isSet: true} +} + +func (v NullableOrdSide) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableOrdSide) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/order_status.go b/oeml-sdk/go-ws/sdk/types/order_status.go new file mode 100644 index 0000000000..41c6a35a14 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/order_status.go @@ -0,0 +1,138 @@ +package types + +import ( + "encoding/json" + "fmt" +) + +// OrdStatus Order statuses and the lifecycle are documented in the separate section: OEML / Starter Guide / Order Lifecycle +type OrdStatus string + +// List of OrdStatus +const ( + RECEIVED OrdStatus = "RECEIVED" + ROUTING OrdStatus = "ROUTING" + ROUTED OrdStatus = "ROUTED" + NEW OrdStatus = "NEW" + PENDING_CANCEL OrdStatus = "PENDING_CANCEL" + PARTIALLY_FILLED OrdStatus = "PARTIALLY_FILLED" + FILLED OrdStatus = "FILLED" + CANCELED OrdStatus = "CANCELED" + REJECTED OrdStatus = "REJECTED" +) + +var allowedOrdStatusEnumValues = []OrdStatus{ + "RECEIVED", + "ROUTING", + "ROUTED", + "NEW", + "PENDING_CANCEL", + "PARTIALLY_FILLED", + "FILLED", + "CANCELED", + "REJECTED", +} + +func (v *OrdStatus) String() string { + switch *v { + case RECEIVED: + return "RECEIVED" + case ROUTING: + return "ROUTING" + case ROUTED: + return "ROUTED" + case NEW: + return "NEW" + case PENDING_CANCEL: + return "PENDING_CANCEL" + case PARTIALLY_FILLED: + return "PARTIALLY_FILLED" + case FILLED: + return "FILLED" + case CANCELED: + return "CANCELED" + case REJECTED: + return "REJECTED" + default: + return "UNKNOWN OrdStatus" + } +} + +func (v *OrdStatus) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + enumTypeValue := OrdStatus(value) + for _, existing := range allowedOrdStatusEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid OrdStatus", value) +} + +// NewOrdStatusFromValue returns a pointer to a valid OrdStatus +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewOrdStatusFromValue(v string) (*OrdStatus, error) { + ev := OrdStatus(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for OrdStatus: valid values are %v", v, allowedOrdStatusEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v OrdStatus) IsValid() bool { + for _, existing := range allowedOrdStatusEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to OrdStatus value +func (v OrdStatus) Ptr() *OrdStatus { + return &v +} + +type NullableOrdStatus struct { + value *OrdStatus + isSet bool +} + +func (v NullableOrdStatus) Get() *OrdStatus { + return v.value +} + +func (v *NullableOrdStatus) Set(val *OrdStatus) { + v.value = val + v.isSet = true +} + +func (v NullableOrdStatus) IsSet() bool { + return v.isSet +} + +func (v *NullableOrdStatus) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableOrdStatus(val *OrdStatus) *NullableOrdStatus { + return &NullableOrdStatus{value: val, isSet: true} +} + +func (v NullableOrdStatus) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableOrdStatus) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/order_type.go b/oeml-sdk/go-ws/sdk/types/order_type.go new file mode 100644 index 0000000000..3c49f0d6e9 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/order_type.go @@ -0,0 +1,106 @@ +package types + +import ( + "encoding/json" + "fmt" +) + +// OrdType Order types are documented in the separate section: OEML / Starter Guide / Order parameters / Order type +type OrdType string + +// List of OrdType +const ( + LIMIT OrdType = "LIMIT" +) + +var allowedOrdTypeEnumValues = []OrdType{ + "LIMIT", +} + +func (v *OrdType) String() string { + switch *v { + case LIMIT: + return "LIMIT" + default: + return "UNKNOWN OrdType" + } +} + +func (v *OrdType) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + enumTypeValue := OrdType(value) + for _, existing := range allowedOrdTypeEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid OrdType", value) +} + +// NewOrdTypeFromValue returns a pointer to a valid OrdType +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewOrdTypeFromValue(v string) (*OrdType, error) { + ev := OrdType(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for OrdType: valid values are %v", v, allowedOrdTypeEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v OrdType) IsValid() bool { + for _, existing := range allowedOrdTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to OrdType value +func (v OrdType) Ptr() *OrdType { + return &v +} + +type NullableOrdType struct { + value *OrdType + isSet bool +} + +func (v NullableOrdType) Get() *OrdType { + return v.value +} + +func (v *NullableOrdType) Set(val *OrdType) { + v.value = val + v.isSet = true +} + +func (v NullableOrdType) IsSet() bool { + return v.isSet +} + +func (v *NullableOrdType) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableOrdType(val *OrdType) *NullableOrdType { + return &NullableOrdType{value: val, isSet: true} +} + +func (v NullableOrdType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableOrdType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/position.go b/oeml-sdk/go-ws/sdk/types/position.go new file mode 100644 index 0000000000..890008d39c --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/position.go @@ -0,0 +1,148 @@ +package types + +import ( + "encoding/json" + "fmt" +) + +// Position struct for Position +type Position struct { + // Exchange identifier used to identify the routing destination. + ExchangeId *string `json:"exchange_id,omitempty"` + Data *[]PositionData `json:"data,omitempty"` +} + +func (o *Position) String() string { + return fmt.Sprintf(" ExchangeId: %v, Data: %v", + *o.ExchangeId, + *o.Data, + ) +} + +// NewPosition instantiates a new Position object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewPosition() *Position { + this := Position{} + return &this +} + +// NewPositionWithDefaults instantiates a new Position object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewPositionWithDefaults() *Position { + this := Position{} + return &this +} + +// GetExchangeId returns the ExchangeId field value if set, zero value otherwise. +func (o *Position) GetExchangeId() string { + if o == nil || o.ExchangeId == nil { + var ret string + return ret + } + return *o.ExchangeId +} + +// GetExchangeIdOk returns a tuple with the ExchangeId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Position) GetExchangeIdOk() (*string, bool) { + if o == nil || o.ExchangeId == nil { + return nil, false + } + return o.ExchangeId, true +} + +// HasExchangeId returns a boolean if a field has been set. +func (o *Position) HasExchangeId() bool { + if o != nil && o.ExchangeId != nil { + return true + } + + return false +} + +// SetExchangeId gets a reference to the given string and assigns it to the ExchangeId field. +func (o *Position) SetExchangeId(v string) { + o.ExchangeId = &v +} + +// GetData returns the Data field value if set, zero value otherwise. +func (o *Position) GetData() []PositionData { + if o == nil || o.Data == nil { + var ret []PositionData + return ret + } + return *o.Data +} + +// GetDataOk returns a tuple with the Data field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Position) GetDataOk() (*[]PositionData, bool) { + if o == nil || o.Data == nil { + return nil, false + } + return o.Data, true +} + +// HasData returns a boolean if a field has been set. +func (o *Position) HasData() bool { + if o != nil && o.Data != nil { + return true + } + + return false +} + +// SetData gets a reference to the given []PositionData and assigns it to the Data field. +func (o *Position) SetData(v []PositionData) { + o.Data = &v +} + +func (o Position) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.ExchangeId != nil { + toSerialize["exchange_id"] = o.ExchangeId + } + if o.Data != nil { + toSerialize["data"] = o.Data + } + return json.Marshal(toSerialize) +} + +type NullablePosition struct { + value *Position + isSet bool +} + +func (v NullablePosition) Get() *Position { + return v.value +} + +func (v *NullablePosition) Set(val *Position) { + v.value = val + v.isSet = true +} + +func (v NullablePosition) IsSet() bool { + return v.isSet +} + +func (v *NullablePosition) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullablePosition(val *Position) *NullablePosition { + return &NullablePosition{value: val, isSet: true} +} + +func (v NullablePosition) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullablePosition) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/position_data.go b/oeml-sdk/go-ws/sdk/types/position_data.go new file mode 100644 index 0000000000..9130743152 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/position_data.go @@ -0,0 +1,450 @@ +package types + +import ( + "encoding/json" + "fmt" +) + +// PositionData The Position object. +type PositionData struct { + // Exchange symbol. + SymbolIdExchange *string `json:"symbol_id_exchange,omitempty"` + // CoinAPI symbol. + SymbolIdCoinapi *string `json:"symbol_id_coinapi,omitempty"` + // Calculated average price of all fills on this position. + AvgEntryPrice *float64 `json:"avg_entry_price,omitempty"` + // The current position quantity. + Quantity *float64 `json:"quantity,omitempty"` + Side *OrdSide `json:"side,omitempty"` + // Unrealised profit or loss (PNL) of this position. + UnrealizedPnl *float64 `json:"unrealized_pnl,omitempty"` + // Leverage for this position reported by the exchange. + Leverage *float64 `json:"leverage,omitempty"` + // Is cross margin mode enable for this position? + CrossMargin *bool `json:"cross_margin,omitempty"` + // Liquidation price. If mark price will reach this value, the position will be liquidated. + LiquidationPrice *float64 `json:"liquidation_price,omitempty"` + RawData *map[string]interface{} `json:"raw_data,omitempty"` +} + +func (o *PositionData) String() string { + return fmt.Sprintf(" SymbolIdExchange: %v, SymbolIdCoinapi: %v, AvgEntryPrice: %v, Quantity: %v, Side: %v, UnrealizedPnl: %v, Leverage %v, Leverage: %v, CrossMargin: %v, LiquidationPrice: %v", + o.SymbolIdExchange, + o.SymbolIdCoinapi, + o.AvgEntryPrice, + o.Quantity, + o.Side, + o.UnrealizedPnl, + o.Leverage, + o.CrossMargin, + o.LiquidationPrice, + ) +} + +// NewPositionData instantiates a new PositionData object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewPositionData() *PositionData { + this := PositionData{} + return &this +} + +// NewPositionDataWithDefaults instantiates a new PositionData object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewPositionDataWithDefaults() *PositionData { + this := PositionData{} + return &this +} + +// GetSymbolIdExchange returns the SymbolIdExchange field value if set, zero value otherwise. +func (o *PositionData) GetSymbolIdExchange() string { + if o == nil || o.SymbolIdExchange == nil { + var ret string + return ret + } + return *o.SymbolIdExchange +} + +// GetSymbolIdExchangeOk returns a tuple with the SymbolIdExchange field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PositionData) GetSymbolIdExchangeOk() (*string, bool) { + if o == nil || o.SymbolIdExchange == nil { + return nil, false + } + return o.SymbolIdExchange, true +} + +// HasSymbolIdExchange returns a boolean if a field has been set. +func (o *PositionData) HasSymbolIdExchange() bool { + if o != nil && o.SymbolIdExchange != nil { + return true + } + + return false +} + +// SetSymbolIdExchange gets a reference to the given string and assigns it to the SymbolIdExchange field. +func (o *PositionData) SetSymbolIdExchange(v string) { + o.SymbolIdExchange = &v +} + +// GetSymbolIdCoinapi returns the SymbolIdCoinapi field value if set, zero value otherwise. +func (o *PositionData) GetSymbolIdCoinapi() string { + if o == nil || o.SymbolIdCoinapi == nil { + var ret string + return ret + } + return *o.SymbolIdCoinapi +} + +// GetSymbolIdCoinapiOk returns a tuple with the SymbolIdCoinapi field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PositionData) GetSymbolIdCoinapiOk() (*string, bool) { + if o == nil || o.SymbolIdCoinapi == nil { + return nil, false + } + return o.SymbolIdCoinapi, true +} + +// HasSymbolIdCoinapi returns a boolean if a field has been set. +func (o *PositionData) HasSymbolIdCoinapi() bool { + if o != nil && o.SymbolIdCoinapi != nil { + return true + } + + return false +} + +// SetSymbolIdCoinapi gets a reference to the given string and assigns it to the SymbolIdCoinapi field. +func (o *PositionData) SetSymbolIdCoinapi(v string) { + o.SymbolIdCoinapi = &v +} + +// GetAvgEntryPrice returns the AvgEntryPrice field value if set, zero value otherwise. +func (o *PositionData) GetAvgEntryPrice() float64 { + if o == nil || o.AvgEntryPrice == nil { + var ret float64 + return ret + } + return *o.AvgEntryPrice +} + +// GetAvgEntryPriceOk returns a tuple with the AvgEntryPrice field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PositionData) GetAvgEntryPriceOk() (*float64, bool) { + if o == nil || o.AvgEntryPrice == nil { + return nil, false + } + return o.AvgEntryPrice, true +} + +// HasAvgEntryPrice returns a boolean if a field has been set. +func (o *PositionData) HasAvgEntryPrice() bool { + if o != nil && o.AvgEntryPrice != nil { + return true + } + + return false +} + +// SetAvgEntryPrice gets a reference to the given float64 and assigns it to the AvgEntryPrice field. +func (o *PositionData) SetAvgEntryPrice(v float64) { + o.AvgEntryPrice = &v +} + +// GetQuantity returns the Quantity field value if set, zero value otherwise. +func (o *PositionData) GetQuantity() float64 { + if o == nil || o.Quantity == nil { + var ret float64 + return ret + } + return *o.Quantity +} + +// GetQuantityOk returns a tuple with the Quantity field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PositionData) GetQuantityOk() (*float64, bool) { + if o == nil || o.Quantity == nil { + return nil, false + } + return o.Quantity, true +} + +// HasQuantity returns a boolean if a field has been set. +func (o *PositionData) HasQuantity() bool { + if o != nil && o.Quantity != nil { + return true + } + + return false +} + +// SetQuantity gets a reference to the given float64 and assigns it to the Quantity field. +func (o *PositionData) SetQuantity(v float64) { + o.Quantity = &v +} + +// GetSide returns the Side field value if set, zero value otherwise. +func (o *PositionData) GetSide() OrdSide { + if o == nil || o.Side == nil { + var ret OrdSide + return ret + } + return *o.Side +} + +// GetSideOk returns a tuple with the Side field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PositionData) GetSideOk() (*OrdSide, bool) { + if o == nil || o.Side == nil { + return nil, false + } + return o.Side, true +} + +// HasSide returns a boolean if a field has been set. +func (o *PositionData) HasSide() bool { + if o != nil && o.Side != nil { + return true + } + + return false +} + +// SetSide gets a reference to the given OrdSide and assigns it to the Side field. +func (o *PositionData) SetSide(v OrdSide) { + o.Side = &v +} + +// GetUnrealizedPnl returns the UnrealizedPnl field value if set, zero value otherwise. +func (o *PositionData) GetUnrealizedPnl() float64 { + if o == nil || o.UnrealizedPnl == nil { + var ret float64 + return ret + } + return *o.UnrealizedPnl +} + +// GetUnrealizedPnlOk returns a tuple with the UnrealizedPnl field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PositionData) GetUnrealizedPnlOk() (*float64, bool) { + if o == nil || o.UnrealizedPnl == nil { + return nil, false + } + return o.UnrealizedPnl, true +} + +// HasUnrealizedPnl returns a boolean if a field has been set. +func (o *PositionData) HasUnrealizedPnl() bool { + if o != nil && o.UnrealizedPnl != nil { + return true + } + + return false +} + +// SetUnrealizedPnl gets a reference to the given float64 and assigns it to the UnrealizedPnl field. +func (o *PositionData) SetUnrealizedPnl(v float64) { + o.UnrealizedPnl = &v +} + +// GetLeverage returns the Leverage field value if set, zero value otherwise. +func (o *PositionData) GetLeverage() float64 { + if o == nil || o.Leverage == nil { + var ret float64 + return ret + } + return *o.Leverage +} + +// GetLeverageOk returns a tuple with the Leverage field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PositionData) GetLeverageOk() (*float64, bool) { + if o == nil || o.Leverage == nil { + return nil, false + } + return o.Leverage, true +} + +// HasLeverage returns a boolean if a field has been set. +func (o *PositionData) HasLeverage() bool { + if o != nil && o.Leverage != nil { + return true + } + + return false +} + +// SetLeverage gets a reference to the given float64 and assigns it to the Leverage field. +func (o *PositionData) SetLeverage(v float64) { + o.Leverage = &v +} + +// GetCrossMargin returns the CrossMargin field value if set, zero value otherwise. +func (o *PositionData) GetCrossMargin() bool { + if o == nil || o.CrossMargin == nil { + var ret bool + return ret + } + return *o.CrossMargin +} + +// GetCrossMarginOk returns a tuple with the CrossMargin field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PositionData) GetCrossMarginOk() (*bool, bool) { + if o == nil || o.CrossMargin == nil { + return nil, false + } + return o.CrossMargin, true +} + +// HasCrossMargin returns a boolean if a field has been set. +func (o *PositionData) HasCrossMargin() bool { + if o != nil && o.CrossMargin != nil { + return true + } + + return false +} + +// SetCrossMargin gets a reference to the given bool and assigns it to the CrossMargin field. +func (o *PositionData) SetCrossMargin(v bool) { + o.CrossMargin = &v +} + +// GetLiquidationPrice returns the LiquidationPrice field value if set, zero value otherwise. +func (o *PositionData) GetLiquidationPrice() float64 { + if o == nil || o.LiquidationPrice == nil { + var ret float64 + return ret + } + return *o.LiquidationPrice +} + +// GetLiquidationPriceOk returns a tuple with the LiquidationPrice field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PositionData) GetLiquidationPriceOk() (*float64, bool) { + if o == nil || o.LiquidationPrice == nil { + return nil, false + } + return o.LiquidationPrice, true +} + +// HasLiquidationPrice returns a boolean if a field has been set. +func (o *PositionData) HasLiquidationPrice() bool { + if o != nil && o.LiquidationPrice != nil { + return true + } + + return false +} + +// SetLiquidationPrice gets a reference to the given float64 and assigns it to the LiquidationPrice field. +func (o *PositionData) SetLiquidationPrice(v float64) { + o.LiquidationPrice = &v +} + +// GetRawData returns the RawData field value if set, zero value otherwise. +func (o *PositionData) GetRawData() map[string]interface{} { + if o == nil || o.RawData == nil { + var ret map[string]interface{} + return ret + } + return *o.RawData +} + +// GetRawDataOk returns a tuple with the RawData field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PositionData) GetRawDataOk() (*map[string]interface{}, bool) { + if o == nil || o.RawData == nil { + return nil, false + } + return o.RawData, true +} + +// HasRawData returns a boolean if a field has been set. +func (o *PositionData) HasRawData() bool { + if o != nil && o.RawData != nil { + return true + } + + return false +} + +// SetRawData gets a reference to the given map[string]interface{} and assigns it to the RawData field. +func (o *PositionData) SetRawData(v map[string]interface{}) { + o.RawData = &v +} + +func (o PositionData) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.SymbolIdExchange != nil { + toSerialize["symbol_id_exchange"] = o.SymbolIdExchange + } + if o.SymbolIdCoinapi != nil { + toSerialize["symbol_id_coinapi"] = o.SymbolIdCoinapi + } + if o.AvgEntryPrice != nil { + toSerialize["avg_entry_price"] = o.AvgEntryPrice + } + if o.Quantity != nil { + toSerialize["quantity"] = o.Quantity + } + if o.Side != nil { + toSerialize["side"] = o.Side + } + if o.UnrealizedPnl != nil { + toSerialize["unrealized_pnl"] = o.UnrealizedPnl + } + if o.Leverage != nil { + toSerialize["leverage"] = o.Leverage + } + if o.CrossMargin != nil { + toSerialize["cross_margin"] = o.CrossMargin + } + if o.LiquidationPrice != nil { + toSerialize["liquidation_price"] = o.LiquidationPrice + } + if o.RawData != nil { + toSerialize["raw_data"] = o.RawData + } + return json.Marshal(toSerialize) +} + +type NullablePositionData struct { + value *PositionData + isSet bool +} + +func (v NullablePositionData) Get() *PositionData { + return v.value +} + +func (v *NullablePositionData) Set(val *PositionData) { + v.value = val + v.isSet = true +} + +func (v NullablePositionData) IsSet() bool { + return v.isSet +} + +func (v *NullablePositionData) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullablePositionData(val *PositionData) *NullablePositionData { + return &NullablePositionData{value: val, isSet: true} +} + +func (v NullablePositionData) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullablePositionData) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/server_info.go b/oeml-sdk/go-ws/sdk/types/server_info.go new file mode 100644 index 0000000000..3d2b4ca224 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/server_info.go @@ -0,0 +1,27 @@ +package types + +import "fmt" + +type ServerInfo struct { + Time *string `json:"time,omitempty"` + ExchangeId *string `json:"exchange_id,omitempty"` + InstanceGuid *string `json:"instance_guid,omitempty"` + ServerVersion *string `json:"server_version,omitempty"` + ServerName *string `json:"server_name,omitempty"` + DnsName *string `json:"dns_name,omitempty"` + IsRunning *bool `json:"is_running,omitempty"` + ServerStartTime *string `json:"time_server_start,omitempty"` +} + +func (s ServerInfo) String() string { + return fmt.Sprintf(" \n Time: %v, \n ExchangeId: %v, \n InstanceGuid: %v, \n ServerVersion: %v, \n ServerName: %v, \n DnsName: %v, \n IsRunning %v, \n ServerStartTime: %v", + *s.Time, + *s.ExchangeId, + "API-KEY", + *s.ServerVersion, + *s.ServerName, + *s.DnsName, + *s.IsRunning, + *s.ServerStartTime, + ) +} diff --git a/oeml-sdk/go-ws/sdk/types/severity.go b/oeml-sdk/go-ws/sdk/types/severity.go new file mode 100644 index 0000000000..587beb8bcb --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/severity.go @@ -0,0 +1,101 @@ +package types + +import ( + "encoding/json" + "fmt" +) + +// Severity Severity of the message. +type Severity string + +// List of Severity +const ( + INFO Severity = "INFO" + WARNING Severity = "WARNING" + ERROR Severity = "ERROR" +) + +var allowedSeverityEnumValues = []Severity{ + "INFO", + "WARNING", + "ERROR", +} + +func (v *Severity) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + enumTypeValue := Severity(value) + for _, existing := range allowedSeverityEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid Severity", value) +} + +// NewSeverityFromValue returns a pointer to a valid Severity +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewSeverityFromValue(v string) (*Severity, error) { + ev := Severity(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for Severity: valid values are %v", v, allowedSeverityEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v Severity) IsValid() bool { + for _, existing := range allowedSeverityEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to Severity value +func (v Severity) Ptr() *Severity { + return &v +} + +type NullableSeverity struct { + value *Severity + isSet bool +} + +func (v NullableSeverity) Get() *Severity { + return v.value +} + +func (v *NullableSeverity) Set(val *Severity) { + v.value = val + v.isSet = true +} + +func (v NullableSeverity) IsSet() bool { + return v.isSet +} + +func (v *NullableSeverity) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableSeverity(val *Severity) *NullableSeverity { + return &NullableSeverity{value: val, isSet: true} +} + +func (v NullableSeverity) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableSeverity) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/symbol.go b/oeml-sdk/go-ws/sdk/types/symbol.go new file mode 100644 index 0000000000..cbae6d247b --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/symbol.go @@ -0,0 +1,16 @@ +package types + +import "fmt" + +type Symbols struct { + // Exchange identifier used to identify the routing destination. + ExchangeId *string `json:"exchange_id,omitempty"` + Data *[]SymbolData `json:"data,omitempty"` +} + +func (s Symbols) String() string { + return fmt.Sprintf(" ExchangeId: %v, Data: %v", + *s.ExchangeId, + *s.Data, + ) +} diff --git a/oeml-sdk/go-ws/sdk/types/symbol_data.go b/oeml-sdk/go-ws/sdk/types/symbol_data.go new file mode 100644 index 0000000000..837598bd7d --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/symbol_data.go @@ -0,0 +1,27 @@ +package types + +import "fmt" + +type SymbolData struct { + Symbol_id_coinapi *string `json:"symbol_id_coinapi,omitempty"` + Symbol_id_base_exchange *string `json:"symbol_id_exchange,omitempty"` + Asset_id_base_exchange *string `json:"asset_id_base_exchange,omitempty"` + Asset_id_quote_exchange *string `json:"asset_id_quote_exchange,omitempty"` + Asset_id_base_coinapi *string `json:"asset_id_base_coinapi,omitempty"` + Asset_id_quote_coinapi *string `json:"asset_id_quote_coinapi,omitempty"` + Price_precision *float64 `json:"price_precision,omitempty"` + Size_precision *float64 `json:"size_precision,omitempty"` +} + +func (s SymbolData) String() string { + return fmt.Sprintf(" \n Symbol_id_coinapi: %v, \n Symbol_id_base_exchange: %v, \n Asset_id_base_exchange: %v, \n Asset_id_quote_exchange: %v, \n Asset_id_base_coinapi: %v, \n Asset_id_quote_coinapi: %v, \n Price_precision %v, \n Size_precision: %v", + *s.Symbol_id_coinapi, + *s.Symbol_id_base_exchange, + *s.Asset_id_base_exchange, + *s.Asset_id_quote_exchange, + *s.Asset_id_base_coinapi, + *s.Asset_id_quote_coinapi, + *s.Price_precision, + *s.Size_precision, + ) +} diff --git a/oeml-sdk/go-ws/sdk/types/time_in_force.go b/oeml-sdk/go-ws/sdk/types/time_in_force.go new file mode 100644 index 0000000000..1caf70eb9d --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/time_in_force.go @@ -0,0 +1,122 @@ +package types + +import ( + "encoding/json" + "fmt" +) + +// TimeInForce Order time in force options are documented in the separate section: OEML / Starter Guide / Order parameters / Time in force +type TimeInForce string + +// List of TimeInForce +const ( + GOOD_TILL_CANCEL TimeInForce = "GOOD_TILL_CANCEL" + GOOD_TILL_TIME_EXCHANGE TimeInForce = "GOOD_TILL_TIME_EXCHANGE" + GOOD_TILL_TIME_OMS TimeInForce = "GOOD_TILL_TIME_OMS" + FILL_OR_KILL TimeInForce = "FILL_OR_KILL" + IMMEDIATE_OR_CANCEL TimeInForce = "IMMEDIATE_OR_CANCEL" +) + +var allowedTimeInForceEnumValues = []TimeInForce{ + "GOOD_TILL_CANCEL", + "GOOD_TILL_TIME_EXCHANGE", + "GOOD_TILL_TIME_OMS", + "FILL_OR_KILL", + "IMMEDIATE_OR_CANCEL", +} + +func (v *TimeInForce) String() string { + switch *v { + case GOOD_TILL_CANCEL: + return "GOOD_TILL_CANCEL" + case GOOD_TILL_TIME_EXCHANGE: + return "GOOD_TILL_TIME_EXCHANGE" + case GOOD_TILL_TIME_OMS: + return "GOOD_TILL_TIME_OMS" + case FILL_OR_KILL: + return "FILL_OR_KILL" + case IMMEDIATE_OR_CANCEL: + return "IMMEDIATE_OR_CANCEL" + default: + return "UNKNOWN TimeInForce" + } +} + +func (v *TimeInForce) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + enumTypeValue := TimeInForce(value) + for _, existing := range allowedTimeInForceEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid TimeInForce", value) +} + +// NewTimeInForceFromValue returns a pointer to a valid TimeInForce +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewTimeInForceFromValue(v string) (*TimeInForce, error) { + ev := TimeInForce(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for TimeInForce: valid values are %v", v, allowedTimeInForceEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v TimeInForce) IsValid() bool { + for _, existing := range allowedTimeInForceEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to TimeInForce value +func (v TimeInForce) Ptr() *TimeInForce { + return &v +} + +type NullableTimeInForce struct { + value *TimeInForce + isSet bool +} + +func (v NullableTimeInForce) Get() *TimeInForce { + return v.value +} + +func (v *NullableTimeInForce) Set(val *TimeInForce) { + v.value = val + v.isSet = true +} + +func (v NullableTimeInForce) IsSet() bool { + return v.isSet +} + +func (v *NullableTimeInForce) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTimeInForce(val *TimeInForce) *NullableTimeInForce { + return &NullableTimeInForce{value: val, isSet: true} +} + +func (v NullableTimeInForce) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTimeInForce) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/utils.go b/oeml-sdk/go-ws/sdk/types/utils.go new file mode 100644 index 0000000000..c025c1440e --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/utils.go @@ -0,0 +1,318 @@ +package types + +import ( + "encoding/json" + "time" +) + +// PtrBool is a helper routine that returns a pointer to given boolean value. +func PtrBool(v bool) *bool { return &v } + +// PtrInt is a helper routine that returns a pointer to given integer value. +func PtrInt(v int) *int { return &v } + +// PtrInt32 is a helper routine that returns a pointer to given integer value. +func PtrInt32(v int32) *int32 { return &v } + +// PtrInt64 is a helper routine that returns a pointer to given integer value. +func PtrInt64(v int64) *int64 { return &v } + +// PtrFloat32 is a helper routine that returns a pointer to given float value. +func PtrFloat32(v float32) *float32 { return &v } + +// PtrFloat64 is a helper routine that returns a pointer to given float value. +func PtrFloat64(v float64) *float64 { return &v } + +// PtrString is a helper routine that returns a pointer to given string value. +func PtrString(v string) *string { return &v } + +// PtrTime is helper routine that returns a pointer to given Time value. +func PtrTime(v time.Time) *time.Time { return &v } + +type NullableBool struct { + value *bool + isSet bool +} + +func (v NullableBool) Get() *bool { + return v.value +} + +func (v *NullableBool) Set(val *bool) { + v.value = val + v.isSet = true +} + +func (v NullableBool) IsSet() bool { + return v.isSet +} + +func (v *NullableBool) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBool(val *bool) *NullableBool { + return &NullableBool{value: val, isSet: true} +} + +func (v NullableBool) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBool) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt struct { + value *int + isSet bool +} + +func (v NullableInt) Get() *int { + return v.value +} + +func (v *NullableInt) Set(val *int) { + v.value = val + v.isSet = true +} + +func (v NullableInt) IsSet() bool { + return v.isSet +} + +func (v *NullableInt) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt(val *int) *NullableInt { + return &NullableInt{value: val, isSet: true} +} + +func (v NullableInt) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt32 struct { + value *int32 + isSet bool +} + +func (v NullableInt32) Get() *int32 { + return v.value +} + +func (v *NullableInt32) Set(val *int32) { + v.value = val + v.isSet = true +} + +func (v NullableInt32) IsSet() bool { + return v.isSet +} + +func (v *NullableInt32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt32(val *int32) *NullableInt32 { + return &NullableInt32{value: val, isSet: true} +} + +func (v NullableInt32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt64 struct { + value *int64 + isSet bool +} + +func (v NullableInt64) Get() *int64 { + return v.value +} + +func (v *NullableInt64) Set(val *int64) { + v.value = val + v.isSet = true +} + +func (v NullableInt64) IsSet() bool { + return v.isSet +} + +func (v *NullableInt64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt64(val *int64) *NullableInt64 { + return &NullableInt64{value: val, isSet: true} +} + +func (v NullableInt64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat32 struct { + value *float32 + isSet bool +} + +func (v NullableFloat32) Get() *float32 { + return v.value +} + +func (v *NullableFloat32) Set(val *float32) { + v.value = val + v.isSet = true +} + +func (v NullableFloat32) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat32(val *float32) *NullableFloat32 { + return &NullableFloat32{value: val, isSet: true} +} + +func (v NullableFloat32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat64 struct { + value *float64 + isSet bool +} + +func (v NullableFloat64) Get() *float64 { + return v.value +} + +func (v *NullableFloat64) Set(val *float64) { + v.value = val + v.isSet = true +} + +func (v NullableFloat64) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat64(val *float64) *NullableFloat64 { + return &NullableFloat64{value: val, isSet: true} +} + +func (v NullableFloat64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableString struct { + value *string + isSet bool +} + +func (v NullableString) Get() *string { + return v.value +} + +func (v *NullableString) Set(val *string) { + v.value = val + v.isSet = true +} + +func (v NullableString) IsSet() bool { + return v.isSet +} + +func (v *NullableString) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableString(val *string) *NullableString { + return &NullableString{value: val, isSet: true} +} + +func (v NullableString) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableString) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableTime struct { + value *time.Time + isSet bool +} + +func (v NullableTime) Get() *time.Time { + return v.value +} + +func (v *NullableTime) Set(val *time.Time) { + v.value = val + v.isSet = true +} + +func (v NullableTime) IsSet() bool { + return v.isSet +} + +func (v *NullableTime) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTime(val *time.Time) *NullableTime { + return &NullableTime{value: val, isSet: true} +} + +func (v NullableTime) MarshalJSON() ([]byte, error) { + return v.value.MarshalJSON() +} + +func (v *NullableTime) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/types/validation_error.go b/oeml-sdk/go-ws/sdk/types/validation_error.go new file mode 100644 index 0000000000..27d18cd324 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/types/validation_error.go @@ -0,0 +1,247 @@ +package types + +import ( + "encoding/json" +) + +// ValidationError struct for ValidationError +type ValidationError struct { + Type *string `json:"type,omitempty"` + Title *string `json:"title,omitempty"` + Status *float64 `json:"status,omitempty"` + TraceId *string `json:"traceId,omitempty"` + Errors *string `json:"errors,omitempty"` +} + +// NewValidationError instantiates a new ValidationError object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewValidationError() *ValidationError { + this := ValidationError{} + return &this +} + +// NewValidationErrorWithDefaults instantiates a new ValidationError object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewValidationErrorWithDefaults() *ValidationError { + this := ValidationError{} + return &this +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *ValidationError) GetType() string { + if o == nil || o.Type == nil { + var ret string + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ValidationError) GetTypeOk() (*string, bool) { + if o == nil || o.Type == nil { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *ValidationError) HasType() bool { + if o != nil && o.Type != nil { + return true + } + + return false +} + +// SetType gets a reference to the given string and assigns it to the Type field. +func (o *ValidationError) SetType(v string) { + o.Type = &v +} + +// GetTitle returns the Title field value if set, zero value otherwise. +func (o *ValidationError) GetTitle() string { + if o == nil || o.Title == nil { + var ret string + return ret + } + return *o.Title +} + +// GetTitleOk returns a tuple with the Title field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ValidationError) GetTitleOk() (*string, bool) { + if o == nil || o.Title == nil { + return nil, false + } + return o.Title, true +} + +// HasTitle returns a boolean if a field has been set. +func (o *ValidationError) HasTitle() bool { + if o != nil && o.Title != nil { + return true + } + + return false +} + +// SetTitle gets a reference to the given string and assigns it to the Title field. +func (o *ValidationError) SetTitle(v string) { + o.Title = &v +} + +// GetStatus returns the Status field value if set, zero value otherwise. +func (o *ValidationError) GetStatus() float64 { + if o == nil || o.Status == nil { + var ret float64 + return ret + } + return *o.Status +} + +// GetStatusOk returns a tuple with the Status field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ValidationError) GetStatusOk() (*float64, bool) { + if o == nil || o.Status == nil { + return nil, false + } + return o.Status, true +} + +// HasStatus returns a boolean if a field has been set. +func (o *ValidationError) HasStatus() bool { + if o != nil && o.Status != nil { + return true + } + + return false +} + +// SetStatus gets a reference to the given float64 and assigns it to the Status field. +func (o *ValidationError) SetStatus(v float64) { + o.Status = &v +} + +// GetTraceId returns the TraceId field value if set, zero value otherwise. +func (o *ValidationError) GetTraceId() string { + if o == nil || o.TraceId == nil { + var ret string + return ret + } + return *o.TraceId +} + +// GetTraceIdOk returns a tuple with the TraceId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ValidationError) GetTraceIdOk() (*string, bool) { + if o == nil || o.TraceId == nil { + return nil, false + } + return o.TraceId, true +} + +// HasTraceId returns a boolean if a field has been set. +func (o *ValidationError) HasTraceId() bool { + if o != nil && o.TraceId != nil { + return true + } + + return false +} + +// SetTraceId gets a reference to the given string and assigns it to the TraceId field. +func (o *ValidationError) SetTraceId(v string) { + o.TraceId = &v +} + +// GetErrors returns the Errors field value if set, zero value otherwise. +func (o *ValidationError) GetErrors() string { + if o == nil || o.Errors == nil { + var ret string + return ret + } + return *o.Errors +} + +// GetErrorsOk returns a tuple with the Errors field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ValidationError) GetErrorsOk() (*string, bool) { + if o == nil || o.Errors == nil { + return nil, false + } + return o.Errors, true +} + +// HasErrors returns a boolean if a field has been set. +func (o *ValidationError) HasErrors() bool { + if o != nil && o.Errors != nil { + return true + } + + return false +} + +// SetErrors gets a reference to the given string and assigns it to the Errors field. +func (o *ValidationError) SetErrors(v string) { + o.Errors = &v +} + +func (o ValidationError) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.Type != nil { + toSerialize["type"] = o.Type + } + if o.Title != nil { + toSerialize["title"] = o.Title + } + if o.Status != nil { + toSerialize["status"] = o.Status + } + if o.TraceId != nil { + toSerialize["traceId"] = o.TraceId + } + if o.Errors != nil { + toSerialize["errors"] = o.Errors + } + return json.Marshal(toSerialize) +} + +type NullableValidationError struct { + value *ValidationError + isSet bool +} + +func (v NullableValidationError) Get() *ValidationError { + return v.value +} + +func (v *NullableValidationError) Set(val *ValidationError) { + v.value = val + v.isSet = true +} + +func (v NullableValidationError) IsSet() bool { + return v.isSet +} + +func (v *NullableValidationError) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableValidationError(val *ValidationError) *NullableValidationError { + return &NullableValidationError{value: val, isSet: true} +} + +func (v NullableValidationError) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableValidationError) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/oeml-sdk/go-ws/sdk/v1/asset_symbols.go b/oeml-sdk/go-ws/sdk/v1/asset_symbols.go new file mode 100644 index 0000000000..92b3efe7fd --- /dev/null +++ b/oeml-sdk/go-ws/sdk/v1/asset_symbols.go @@ -0,0 +1,57 @@ +package v1 + +import ( + "github.com/marvin-hansen/coinapi-sdk/oeml-sdk/go-ws/sdk/types" +) + +func (s SDKImpl) LookupSymbolData(exchangeID, baseSymbolCoinApi, quoteSymbolCoinApi string) (symbolData types.SymbolData, ok bool) { + assetKey := AssetKey{ + Base: baseSymbolCoinApi, + Quote: quoteSymbolCoinApi, + } + exists := s.checkSymbolExists(exchangeID, assetKey) + if exists { + return symbolMap[exchangeID][assetKey], exists + } else { + return types.SymbolData{}, exists + } +} +func (s SDKImpl) getSymbolData(exchangeID string, assetKey AssetKey) (ok bool, symbolData types.SymbolData) { + exists := s.checkSymbolExists(exchangeID, assetKey) + if exists { + return exists, symbolMap[exchangeID][assetKey] + } else { + return exists, types.SymbolData{} + } +} + +func (s SDKImpl) addSymbolData(exchangeID string, symbolData types.SymbolData) { + assetKey := AssetKey{ + Base: *symbolData.Asset_id_base_coinapi, + Quote: *symbolData.Asset_id_quote_coinapi, + } + exists := s.checkSymbolExists(exchangeID, assetKey) + if !exists { + symbolMap[exchangeID][assetKey] = symbolData + } +} + +func (s SDKImpl) checkSymbolExists(exchangeID string, assetKey AssetKey) (exists bool) { + if _, exists = symbolMap[exchangeID][assetKey]; exists { + return true + } + return false +} + +func (s SDKImpl) AddNewSymbolMap(exchangeID string) { + nestedMap := make(map[AssetKey]types.SymbolData) + symbolMap[exchangeID] = nestedMap + return +} + +func (s SDKImpl) isMapEmpty() (empty bool) { + if len(symbolMap) == 0 { + return true + } + return false +} diff --git a/oeml-sdk/go-ws/sdk/v1/dbg_utils.go b/oeml-sdk/go-ws/sdk/v1/dbg_utils.go new file mode 100644 index 0000000000..036d362b9d --- /dev/null +++ b/oeml-sdk/go-ws/sdk/v1/dbg_utils.go @@ -0,0 +1,16 @@ +package v1 + +import "log" + +func logError(err error) { + if err != nil { + log.Println(err) + } +} + +func checkError(err error) error { + if err != nil { + return nil + } + return err +} diff --git a/oeml-sdk/go-ws/sdk/v1/sdk_impl.go b/oeml-sdk/go-ws/sdk/v1/sdk_impl.go new file mode 100644 index 0000000000..6147b7cc94 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/v1/sdk_impl.go @@ -0,0 +1,79 @@ +package v1 + +import ( + "github.com/marvin-hansen/coinapi-sdk/oeml-sdk/go-ws/sdk/types" + "github.com/marvin-hansen/coinapi-sdk/oeml-sdk/go-ws/sdk/web_socket" +) + +type SDKImpl struct { + url *string +} + +// AssetKey is a composite key for a hashmap to access symbol description +// https://stackoverflow.com/questions/52348514/how-to-make-composite-key-for-a-hash-map-in-golang +type AssetKey struct { + Base, Quote string +} + +var ( + errorMessageInvoke types.InvokeFunction + serverInfoInvoke types.InvokeFunction + symbolSnapshotInvoke types.InvokeFunction + + executionUpdateInvoke types.InvokeFunction + executionSnapshotInvoke types.InvokeFunction + balanceUpdateInvoke types.InvokeFunction + balanceSnapshotInvoke types.InvokeFunction + positionUpdateInvoke types.InvokeFunction + positionSnapshotInvoke types.InvokeFunction + // + ws *web_socket.WebSocket + symbolMap map[string]map[AssetKey]types.SymbolData +) + +func NewOemlSdkV1(url string) (sdk *SDKImpl) { + sdk = new(SDKImpl) + sdk.init(url) + return sdk +} + +func (s SDKImpl) init(url string) { + symbolMap = make(map[string]map[AssetKey]types.SymbolData) + ws = web_socket.NewWebSocket(url) + s.url = &url + err := s.StartMessageProcessing() + if err != nil { + logError(err) + panic(err) + } +} + +func (s SDKImpl) OpenConnection() (err error) { + url := *s.url + err = ws.Connect(url, nil) + return err +} + +func (s SDKImpl) CloseConnection() (err error) { + s.StopMessageProcessing() + err = ws.Close() + if err != nil { + //log.Println("Can't close connection") + //logError(err) + return + } + return err +} + +func (s SDKImpl) ResetConnection() (err error) { + s.StopMessageProcessing() + err = s.CloseConnection() + logError(err) + + err = s.OpenConnection() + logError(err) + + err = s.StartMessageProcessing() + logError(err) + return err +} diff --git a/oeml-sdk/go-ws/sdk/v1/set_methods.go b/oeml-sdk/go-ws/sdk/v1/set_methods.go new file mode 100644 index 0000000000..77a33e9c7f --- /dev/null +++ b/oeml-sdk/go-ws/sdk/v1/set_methods.go @@ -0,0 +1,47 @@ +package v1 + +import ( + "github.com/marvin-hansen/coinapi-sdk/oeml-sdk/go-ws/sdk/types" +) + +func (s SDKImpl) SetSystemInvoke(function types.SystemInvoke) { + errorMessageInvoke = function.ErrorMessageInvoke + serverInfoInvoke = function.ServerInfoInvoke +} + +func (s SDKImpl) SetSnapshotInvoke(function types.SnapshotInvoke) { + executionSnapshotInvoke = function.ExecutionSnapshotInvoke + balanceSnapshotInvoke = function.BalanceSnapshotInvoke + positionSnapshotInvoke = function.PositionSnapshotInvoke + symbolSnapshotInvoke = function.SymbolSnapshotInvoke +} + +func (s SDKImpl) SetUpdateInvoke(function types.UpdateInvoke) { + executionUpdateInvoke = function.ExecutionUpdateInvoke + balanceUpdateInvoke = function.BalanceUpdateInvoke + positionUpdateInvoke = function.PositionUpdateInvoke +} + +func (s SDKImpl) SetExecUpdateInvoke(function types.InvokeFunction) { + executionUpdateInvoke = function +} + +func (s SDKImpl) SetExecSnapshotInvoke(function types.InvokeFunction) { + executionSnapshotInvoke = function +} + +func (s SDKImpl) SetBalanceUpdateInvoke(function types.InvokeFunction) { + balanceUpdateInvoke = function +} + +func (s SDKImpl) SetBalanceSnapshotInvoke(function types.InvokeFunction) { + balanceSnapshotInvoke = function +} + +func (s SDKImpl) SetPositionUpdateInvoke(function types.InvokeFunction) { + positionUpdateInvoke = function +} + +func (s SDKImpl) SetPositionSnapshotInvoke(function types.InvokeFunction) { + positionSnapshotInvoke = function +} diff --git a/oeml-sdk/go-ws/sdk/v1/ws_handler.go b/oeml-sdk/go-ws/sdk/v1/ws_handler.go new file mode 100644 index 0000000000..b084827efe --- /dev/null +++ b/oeml-sdk/go-ws/sdk/v1/ws_handler.go @@ -0,0 +1,159 @@ +package v1 + +import ( + "encoding/json" + "github.com/bitly/go-simplejson" + "github.com/marvin-hansen/coinapi-sdk/oeml-sdk/go-ws/sdk/types" + "github.com/marvin-hansen/coinapi-sdk/oeml-sdk/go-ws/sdk/web_socket" + "log" +) + +func (s SDKImpl) StopMessageProcessing() { + ws.StopReadingByteMessages() +} + +func (s SDKImpl) StartMessageProcessing() (err error) { + errHandler := logError + handler := s.getWSMessageHandler(errHandler) + err = ws.StartReadingByteMessages(handler, errHandler) + if err != nil { + log.Println("error starting message processing!") + logError(err) + return err + } + return nil +} + +func (s SDKImpl) getWSErrorHandler() (errHandler web_socket.WsErrHandler) { + errHandler = func(err error) { + if err != nil { + log.Println(err) + } + } + return errHandler +} + +func (s SDKImpl) getWSMessageHandler(errHandler web_socket.WsErrHandler) (wsHandler web_socket.WsHandler) { + wsHandler = func(message []byte) { + err := s.processMessage(message, errHandler) + errHandler(err) + } + return wsHandler +} + +func (s SDKImpl) processMessage(message []byte, errHandler web_socket.WsErrHandler) (err error) { + var dataMessage = new(types.OemlMessage) + messageType := s.getMessageType(message, errHandler) + dataMessage.MessageType = &messageType + + switch messageType { + + case types.ORDER_EXEC_REPORT_SNAPSHOT: + // https://docs.coinapi.io/oeml.html#order_exec_report_snapshot-in + msg := new(types.OrderExecutionReport) + _ = json.Unmarshal(message, msg) + dataMessage.OrderExecutionReportSnapshot = msg + err = executionSnapshotInvoke(dataMessage) + errHandler(err) + return checkError(err) + + case types.ORDER_EXEC_REPORT_UPDATE: + // https://docs.coinapi.io/oeml.html#order_exec_report_update-in + msg := new(types.OrderExecutionReport) + _ = json.Unmarshal(message, msg) + dataMessage.OrderExecutionReportUpdate = msg + err = executionUpdateInvoke(dataMessage) + errHandler(err) + return checkError(err) + + case types.BALANCE_SNAPSHOT: + // https://docs.coinapi.io/oeml.html#balance_snapshot-in + msg := new(types.Balance) + _ = json.Unmarshal(message, msg) + dataMessage.BalanceSnapshot = msg + err = balanceSnapshotInvoke(dataMessage) + errHandler(err) + return checkError(err) + + case types.BALANCE_UPDATE: + // https://docs.coinapi.io/oeml.html#balance_update-in + msg := new(types.Balance) + _ = json.Unmarshal(message, msg) + dataMessage.BalanceUpdate = msg + err = balanceUpdateInvoke(dataMessage) + errHandler(err) + return checkError(err) + + case types.POSITION_SNAPSHOT: + // https://docs.coinapi.io/oeml.html#position_snapshot-in + msg := new(types.Position) + _ = json.Unmarshal(message, msg) + dataMessage.PositionSnapshot = msg + err = positionSnapshotInvoke(dataMessage) + errHandler(err) + return checkError(err) + + case types.POSITION_UPDATE: + // https://docs.coinapi.io/oeml.html#position_update-in + msg := new(types.Position) + _ = json.Unmarshal(message, msg) + dataMessage.PositionUpdate = msg + err = positionUpdateInvoke(dataMessage) + errHandler(err) + return checkError(err) + + case types.SYMBOLS_SNAPSHOT: + // https://docs.coinapi.io/oeml.html#symbols_snapshot-in + msg := new(types.Symbols) + _ = json.Unmarshal(message, msg) + dataMessage.SymbolSnapshot = msg + + exchangeID := *dataMessage.SymbolSnapshot.ExchangeId + s.AddNewSymbolMap(exchangeID) + for _, symbolData := range *dataMessage.SymbolSnapshot.Data { + s.addSymbolData(exchangeID, symbolData) + } + + err = symbolSnapshotInvoke(dataMessage) + errHandler(err) + return checkError(err) + + case types.SERVER_INFO: + // https://docs.coinapi.io/oeml.html#symbols_snapshot-in + msg := new(types.ServerInfo) + _ = json.Unmarshal(message, msg) + dataMessage.ServerInfo = msg + err = serverInfoInvoke(dataMessage) + errHandler(err) + return checkError(err) + + case types.MESSAGE_REJECT: + // https://docs.coinapi.io/oeml.html#message_reject-in + msg := new(types.MessageReject) + _ = json.Unmarshal(message, msg) + dataMessage.MessageReject = msg + err = errorMessageInvoke(dataMessage) + errHandler(err) + return checkError(err) + } + + return nil +} + +func (s SDKImpl) getMessageType(message []byte, errHandler web_socket.WsErrHandler) (messageType types.MessageType) { + j, err := newJSON(message) + if err != nil { + errHandler(err) + return + } + messageType = types.MessageType(j.Get("type").MustString()) + return messageType +} + +func newJSON(data []byte) (j *simplejson.Json, err error) { + j, err = simplejson.NewJson(data) + if err != nil { + return nil, err + } + return j, nil +} diff --git a/oeml-sdk/go-ws/sdk/v1/ws_order_handler.go b/oeml-sdk/go-ws/sdk/v1/ws_order_handler.go new file mode 100644 index 0000000000..27a468004b --- /dev/null +++ b/oeml-sdk/go-ws/sdk/v1/ws_order_handler.go @@ -0,0 +1,44 @@ +package v1 + +import ( + "github.com/marvin-hansen/coinapi-sdk/oeml-sdk/go-ws/sdk/types" + "log" +) + +const verbose = false + +func (s SDKImpl) PlaceSingleOrder(req *types.OrderNewSingleRequest) (err error) { + b, err := req.MarshalJSON() + logError(err) + logError(err) + err = s.sendMessage(b) + return checkError(err) +} + +func (s SDKImpl) CancelSingleOrder(req *types.OrderCancelSingleRequest) (err error) { + b, err := req.MarshalJSON() + logError(err) + err = s.sendMessage(b) + return checkError(err) +} + +func (s SDKImpl) CancelAllOrders(req *types.OrderCancelAllRequest) (err error) { + b, err := req.MarshalJSON() + logError(err) + err = s.sendMessage(b) + return checkError(err) +} + +func (s SDKImpl) sendMessage(b []byte) (err error) { + if verbose { + println("Write message into Web Socket: ") + println(string(b)) + } + err = ws.WriteByteMessage(b) + if err != nil { + log.Println("can't send message!") + logError(err) + return err + } + return nil +} diff --git a/oeml-sdk/go-ws/sdk/v1/ws_order_req.go b/oeml-sdk/go-ws/sdk/v1/ws_order_req.go new file mode 100644 index 0000000000..3f369e9f91 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/v1/ws_order_req.go @@ -0,0 +1,46 @@ +package v1 + +import ( + "github.com/marvin-hansen/coinapi-sdk/oeml-sdk/go-ws/sdk/types" +) + +func (s SDKImpl) NewSingleOrderRequest(exchangeId, symbolIdCoinApi string, clientOrderId string, amountOrder float64, price float64, side types.OrdSide, orderType types.OrdType, timeInForce types.TimeInForce) (req *types.OrderNewSingleRequest) { + req = &types.OrderNewSingleRequest{ + Type: types.ORDER_NEW_SINGLE_REQUEST, + ExchangeId: exchangeId, + SymbolIdCoinapi: &symbolIdCoinApi, + ClientOrderId: clientOrderId, + AmountOrder: amountOrder, + Price: price, + Side: side, + OrderType: orderType, + TimeInForce: timeInForce, + } + return req +} + +// NewCancelSingleOrderRequest constructs a new cancel request. +// One of the properties (`exchange_order_id`, `client_order_id`) is required to identify the order. +// exchangeId: Identifier of the exchange from which active orders should be canceled. +func (s SDKImpl) NewCancelSingleOrderRequest(exchangeId, clientOrderId string) (req *types.OrderCancelSingleRequest) { + + r := new(types.OrderCancelSingleRequest) + r.Type = types.ORDER_CANCEL_SINGLE_REQUEST + r.ExchangeId = exchangeId + if clientOrderId == "" { + panic("Missing Client order ID") + } else { + r.ClientOrderId = &clientOrderId + } + return r +} + +// NewCancelAllOrdersRequest cancels all open orders at the exchange +// exchangeId: Identifier of the exchange from which active orders should be canceled. +func (s SDKImpl) NewCancelAllOrdersRequest(exchangeId string) (req *types.OrderCancelAllRequest) { + req = &types.OrderCancelAllRequest{ + Type: types.ORDER_CANCEL_ALL_REQUEST, + ExchangeId: exchangeId, + } + return req +} diff --git a/oeml-sdk/go-ws/sdk/web_socket/types.go b/oeml-sdk/go-ws/sdk/web_socket/types.go new file mode 100644 index 0000000000..7cf5ada144 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/web_socket/types.go @@ -0,0 +1,7 @@ +package web_socket + +// WsHandler handle raw websocket message +type WsHandler func(message []byte) + +// WsErrHandler handles raw websocket errors +type WsErrHandler func(err error) diff --git a/oeml-sdk/go-ws/sdk/web_socket/utils.go b/oeml-sdk/go-ws/sdk/web_socket/utils.go new file mode 100644 index 0000000000..5951fe1511 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/web_socket/utils.go @@ -0,0 +1,15 @@ +package web_socket + +import "log" + +func logError(err error) { + if err != nil { + log.Println(err) + } +} + +func printRawMsg(message []byte) { + msg := string(message) + log.Println("raw message: ") + log.Println(msg) +} diff --git a/oeml-sdk/go-ws/sdk/web_socket/websocket.go b/oeml-sdk/go-ws/sdk/web_socket/websocket.go new file mode 100644 index 0000000000..580f9760b4 --- /dev/null +++ b/oeml-sdk/go-ws/sdk/web_socket/websocket.go @@ -0,0 +1,98 @@ +package web_socket + +import ( + "github.com/gorilla/websocket" + "log" + "net/http" +) + +type WebSocket struct{} + +var ( + con *websocket.Conn + stopC chan struct{} + doneC chan struct{} +) + +func NewWebSocket(url string) (ws *WebSocket) { + ws = new(WebSocket) + ws.init(url) + return ws +} +func (s *WebSocket) init(url string) { + _ = s.Connect(url, nil) +} + +func (s *WebSocket) Connect(url string, requestHeader http.Header) (err error) { + con, _, err = websocket.DefaultDialer.Dial(url, nil) + if err != nil { + logError(err) + panic("Cannot connect to: " + url) + } + return err +} + +func (s *WebSocket) Close() (err error) { + con.CloseHandler() + err = con.Close() + if err != nil { + //log.Println("Can't close connection") + //logError(err) + return + } + return err +} + +func (s *WebSocket) StopReadingByteMessages() { + if stopC != nil { + close(stopC) + } +} + +func (s *WebSocket) WriteByteMessage(byteMessage []byte) (err error) { + err = con.WriteMessage(1, byteMessage) + if err != nil { + log.Println("can't send message: " + string(byteMessage)) + logError(err) + return err + } + return nil +} + +func (s *WebSocket) StartReadingByteMessages(messageHandler WsHandler, errorHandler WsErrHandler) (err error) { + + doneC = make(chan struct{}) + stopC = make(chan struct{}) + + go func() { + // This function will exit either on error from ReadMessage + // or when the stopC channel is closed by the client. + defer close(doneC) + + // Wait for the stopC channel to be closed. We do that in a + // separate goroutine because ReadMessage is a blocking operation. + silent := false + go func() { + select { + case <-stopC: + silent = true + case <-doneC: + } + _ = con.Close() + }() + + var message []byte + for { + _, message, err = con.ReadMessage() + if err != nil { + if !silent { + errorHandler(err) + } + return + } + //printRawMsg(message) + messageHandler(message) + } + }() + return +}