Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #3

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft

V2 #3

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ package main
import (
"context"

govortex "github.com/AsthaTech/govortex"
govortex "github.com/AsthaTech/govortex/v2"
)

const (
Expand Down Expand Up @@ -75,7 +75,7 @@ import (
"fmt"
"time"

"github.com/AsthaTech/govortex"
"github.com/AsthaTech/govortex/v2"
)

var wire *govortex.Wire
Expand Down
64 changes: 45 additions & 19 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,56 @@ import (
// Constants for the package
const (
name string = "govortex"
version string = "1.0.0"
version string = "2.0.0"
requestTimeout time.Duration = 7000 * time.Millisecond
baseURI string = "https://vortex.restapi.asthatrade.com"
flowBaseURI string = "https://flow.asthatrade.com"
baseURI string = "https://vortex-api.rupeezy.in/v2"
flowBaseURI string = "https://flow.rupeezy.in"
)

// Constants for the API endpoints
const (
URILogin string = "/user/login"
URIInstruments string = "/data/instruments"
URIPlaceOrder string = "/orders/%s" // "/orders/regular"
URIModifyOrder string = "/orders/%s/%s/%s" //"/orders/regular/{exchange}/{order_id}"
URIDeleterOrder string = "/orders/%s/%s/%s" //"/orders/regular/{exchange}/{order_id}"
URIOrderBook string = "/orders" //"/orders?limit={limit}&offset={offset}"
URIOrderHistory string = "/orders/%s" //"/orders/{order_id}"
URITrades string = "/trades"

URIPositions string = "/portfolio/positions"
URIConvertposition string = "/portfolio/positions"
URIHoldings string = "/portfolio/holdings"

URIFunds string = "/user/funds"
URILogin string = "/user/login"
URISession string = "/user/session"
URIInstruments string = "/data/instruments"
URIPlaceOrder string = "/trading/orders/%s" //"/trading/orders/regular"
URIModifyOrder string = "/trading/orders/%s/%s" //"/trading/orders/{{order_type}}/{order_id}"
URIModifyOrderTags string = "/trading/orders/%s/%s/tags" //"/trading/orders/{{order_type}}/{order_id}/tags"
URIDeleteOrder string = "/trading/orders/%s/%s" //"/trading/orders/{{order_type}}/{order_id}"
URIDeleteMultipleOrder string = "/trading/orders/%s/multi_delete" //"/trading/orders/{{order_type}}/{order_id}"
URIGttOrderBook string = "/trading/orders/gtt" //"/trading/orders/gtt"
URIOrderBook string = "/trading/orders" //"/trading/orders"
URIMultiCancelrders string = "/trading/orders/regular/multi_delete" //"/trading/orders/regular/multi_delete"
URIOrderHistory string = "/trading/orders/%s" //"/trading/orders/{order_id}"
URITrades string = "/trading/trades"

URIPositions string = "/trading/portfolio/positions"
URIConvertposition string = "/trading/portfolio/positions"
URIHoldings string = "/trading/portfolio/holdings"

URIFunds string = "/trading/user/funds"
URIBanks string = "/trading/user/banks"
URIBrokerage string = "/trading/user/brokerage"

URIWithdrawal string = "/user/funds/withdrawal"
URIOrderMargin string = "/margins/order"
URIOrderBasket string = "/margins/basket"
URIQuotes string = "/data/quote"
URIHistory string = "/data/history"

URIOptionChain string = "/strategies/option_chain"

URIStrategies string = "/strategies"
URIBuildStrategies string = "/strategies/build"
URIPayoffStrategies string = "/strategies/payoff"

URITradeReport string = "/reports/trades/%s?from_date=%s&to_date=%s"
URITurnoverSummaryReport string = "/reports/turnover/summary/%s?from_date=%s&to_date=%s"
URITurnoverDetailsReport string = "/reports/turnover/details/%s?from_date=%s&to_date=%s"
URIPnLReport string = "/reports/pnl/%s?from_date=%s&to_date=%s"
URIMTFInterestReport string = "/reports/mtf_interest/%s?from_date=%s&to_date=%s"

URITags string = "/reports/tags"
URITag string = "/reports/tags/%d"
)

// VortexApi is a struct representing the Vortex API client
Expand Down Expand Up @@ -65,8 +90,8 @@ func (v *VortexApi) initialize(applicationId string, apiKey string) {
}

// SetLogging sets the HTTP client with logging enabled
func (v *VortexApi) SetLogging(h *http.Client) {
v.htt = NewHTTPClient(h, nil, v.enableLogging)
func (v *VortexApi) SetLogging(flag bool) {
v.htt = NewHTTPClient(v.htt.GetClient().client, nil, flag)
}

// SetHTTPClient sets the HTTP client for the Vortex API client
Expand All @@ -92,5 +117,6 @@ func (v *VortexApi) doJson(ctx context.Context, method, uri string, body interfa
if v.AccessToken != "" {
headers.Add("Authorization", "Bearer "+v.AccessToken)
}
fmt.Println("URL:", v.baseURL+uri)
return v.htt.doJSON(ctx, method, v.baseURL+uri, body, params, headers, obj)
}
41 changes: 29 additions & 12 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,39 @@ const mockBaseDir = "./vortex-mocks"
var MockResponders = [][]interface{}{
// GET REQUESTS

{http.MethodGet, URIFunds, url.Values{}, "funds.json"},
{http.MethodGet, URIHoldings, url.Values{}, "holdings.json"},
{http.MethodGet, URIPositions, url.Values{}, "positions.json"},
{http.MethodGet, URIOrderBook, url.Values{"limit": []string{"20"}, "offset": []string{"1"}}, "orders.json"},
{http.MethodGet, URIQuotes, url.Values{"q": []string{"NSE_EQ-22"}, "mode": []string{string(QuoteModesFULL)}}, "quotes.json"},
{http.MethodGet, URITrades, url.Values{"limit": []string{"20"}, "offset": []string{"1"}}, "trades.json"},
{http.MethodGet, URIHistory, url.Values{"exchange": []string{string(ExchangeTypesNSEEQUITY)}, "token": []string{"22"}, "from": []string{"1494505756"}, "to": []string{"1494505756"}, "resolution": []string{string(ResolutionsMin1)}}, "history.json"},
{http.MethodGet, fmt.Sprintf(URIOrderHistory, "test"), url.Values{}, "order_history.json"},
{http.MethodGet, URIFunds, url.Values{}, "user/funds.json"},
{http.MethodGet, URIHoldings, url.Values{}, "portfolio/holdings.json"},
{http.MethodGet, URIPositions, url.Values{}, "portfolio/positions.json"},
{http.MethodGet, URIOrderBook, url.Values{}, "portfolio/orders.json"},
{http.MethodGet, URIQuotes, url.Values{"q": []string{"NSE_EQ-22"}, "mode": []string{string(QuoteModesFULL)}}, "data/quotes.json"},
{http.MethodGet, URITrades, url.Values{"limit": []string{"20"}, "offset": []string{"1"}}, "portfolio/trades.json"},
{http.MethodGet, URIHistory, url.Values{"exchange": []string{string(ExchangeTypesNSEEQUITY)}, "token": []string{"22"}, "from": []string{"1494505756"}, "to": []string{"1494505756"}, "resolution": []string{string(ResolutionsMin1)}}, "data/history.json"},
{http.MethodGet, fmt.Sprintf(URIOrderHistory, "test"), url.Values{}, "regular_orders/order_history.json"},
{http.MethodGet, URIGttOrderBook, url.Values{}, "gtt_orders/list.json"},
{http.MethodGet, URITags, url.Values{}, "reports/tags/list.json"},

// DELETE REQUESTS
{http.MethodDelete, fmt.Sprintf(URIDeleterOrder, "regular", ExchangeTypesNSEEQUITY, "NXAAE00002K3"), url.Values{}, "order.json"},
{http.MethodDelete, fmt.Sprintf(URIDeleteOrder, "regular", "NXAAE00002K3"), url.Values{}, "regular_orders/order.json"},
{http.MethodDelete, fmt.Sprintf(URIDeleteOrder, "gtt", "99823d7b-fd37-4d75-af7f-f21ec4671852"), url.Values{}, "gtt_orders/delete.json"},
{http.MethodDelete, fmt.Sprintf(URITag, 1), url.Values{}, "reports/tags/delete.json"},
{http.MethodDelete, fmt.Sprintf(URIDeleteOrder, "iceberg", "5eaefd25-518c-4a39-b556-93fc8e78e855"), url.Values{}, "iceberg_orders/delete.json"},
// POST REQUESTS
{http.MethodPost, fmt.Sprintf(URIPlaceOrder, "regular"), url.Values{}, "order.json"},
{http.MethodPost, fmt.Sprintf(URIPlaceOrder, "regular"), url.Values{}, "regular_orders/order.json"},
{http.MethodPost, fmt.Sprintf(URIPlaceOrder, "gtt"), url.Values{}, "gtt_orders/create.json"},
{http.MethodPost, fmt.Sprintf(URIPlaceOrder, "iceberg"), url.Values{}, "iceberg_orders/create.json"},
{http.MethodPost, URITags, url.Values{}, "reports/tags/create.json"},
{http.MethodPost, URIStrategies, url.Values{}, "strategies/all.json"},
{http.MethodPost, URIOptionChain, url.Values{}, "strategies/option_chain.json"},
{http.MethodPost, URIBuildStrategies, url.Values{}, "strategies/build_strategy.json"},
{http.MethodPost, URIPayoffStrategies, url.Values{}, "strategies/payoff.json"},
{http.MethodPost, URIMultiCancelrders, url.Values{}, "regular_orders/multi_cancel.json"},

// PUT REQUESTS
{http.MethodPut, fmt.Sprintf(URIModifyOrder, "regular", ExchangeTypesNSEEQUITY, "NXAAE00002K3"), url.Values{}, "order.json"},
{http.MethodPut, URIConvertposition, url.Values{}, "position_conversion.json"},
{http.MethodPut, fmt.Sprintf(URIModifyOrder, "regular", "NXAAE00002K3"), url.Values{}, "regular_orders/order.json"},
{http.MethodPut, URIConvertposition, url.Values{}, "portfolio/position_conversion.json"},
{http.MethodPut, fmt.Sprintf(URIModifyOrder, "gtt", "99823d7b-fd37-4d75-af7f-f21ec4671852"), url.Values{}, "gtt_orders/modify.json"},
{http.MethodPut, fmt.Sprintf(URIModifyOrder, "iceberg", "5eaefd25-518c-4a39-b556-93fc8e78e855"), url.Values{}, "iceberg_orders/modify.json"},
{http.MethodPut, fmt.Sprintf(URITag, 1), url.Values{}, "reports/tags/update.json"},
}

const suiteTestMethodPrefix = "Test"
Expand Down
Loading