mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 23:16:52 +00:00
Merge branch 'master' into engine
This commit is contained in:
@@ -132,7 +132,6 @@ func (a *ANX) GetDataToken() (string, error) {
|
||||
// NewOrder sends a new order request to the exchange.
|
||||
func (a *ANX) NewOrder(orderType string, buy bool, tradedCurrency string, tradedCurrencyAmount float64, settlementCurrency string, settlementCurrencyAmount, limitPriceSettlement float64,
|
||||
replace bool, replaceUUID string, replaceIfActive bool) (string, error) {
|
||||
|
||||
req := make(map[string]interface{})
|
||||
var order Order
|
||||
order.OrderType = orderType
|
||||
|
||||
@@ -241,7 +241,6 @@ func TestGetFee(t *testing.T) {
|
||||
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// CryptocurrencyWithdrawalFee Basic
|
||||
|
||||
@@ -243,7 +243,6 @@ func TestGetSymbols(t *testing.T) {
|
||||
"rrtusd",
|
||||
}
|
||||
if len(expectedCurrencies) <= len(symbols) {
|
||||
|
||||
for _, explicitSymbol := range expectedCurrencies {
|
||||
if common.StringDataCompare(expectedCurrencies, explicitSymbol) {
|
||||
break
|
||||
|
||||
@@ -203,7 +203,6 @@ func (b *Bitfinex) WsDataHandler() {
|
||||
if status == "OK" {
|
||||
b.Websocket.DataHandler <- eventData
|
||||
b.WsAddSubscriptionChannel(0, "account", "N/A")
|
||||
|
||||
} else if status == "fail" {
|
||||
b.Websocket.DataHandler <- fmt.Errorf("bitfinex.go error - Websocket unable to AUTH. Error code: %s",
|
||||
eventData["code"].(string))
|
||||
|
||||
@@ -187,7 +187,6 @@ func (b *Bitmex) wsHandleIncomingData() {
|
||||
|
||||
b.Websocket.DataHandler <- fmt.Errorf("%s websocket error: Unable to subscribe %s",
|
||||
b.Name, decodedResp.Subscribe)
|
||||
|
||||
} else if _, ok := quickCapture["table"]; ok {
|
||||
var decodedResp WebsocketMainResponse
|
||||
err := common.JSONDecode(resp.Raw, &decodedResp)
|
||||
|
||||
@@ -269,7 +269,6 @@ func (b *Bitstamp) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error
|
||||
feeBuilder.FeeType = exchange.OfflineTradeFee
|
||||
}
|
||||
return b.GetFee(feeBuilder)
|
||||
|
||||
}
|
||||
|
||||
// FetchOrderbook returns the orderbook for a currency pair
|
||||
|
||||
@@ -507,5 +507,4 @@ func (b *Bittrex) GetWithdrawalFee(c currency.Code) (float64, error) {
|
||||
// calculateTradingFee returns the fee for trading any currency on Bittrex
|
||||
func calculateTradingFee(price, amount float64) float64 {
|
||||
return 0.0025 * price * amount
|
||||
|
||||
}
|
||||
|
||||
@@ -435,7 +435,6 @@ func (b *Bittrex) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
feeBuilder.FeeType = exchange.OfflineTradeFee
|
||||
}
|
||||
return b.GetFee(feeBuilder)
|
||||
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
|
||||
@@ -68,7 +68,6 @@ func (b *BTSE) GetTrades(symbol string) ([]Trade, error) {
|
||||
var t []Trade
|
||||
endpoint := fmt.Sprintf("%s/%s", btseTrades, symbol)
|
||||
return t, b.SendHTTPRequest(http.MethodGet, endpoint, &t)
|
||||
|
||||
}
|
||||
|
||||
// GetTicker returns the ticker for a specified symbol
|
||||
|
||||
@@ -121,7 +121,6 @@ func TestGetFills(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestCreateOrder(t *testing.T) {
|
||||
|
||||
@@ -114,7 +114,6 @@ func (b *BTSE) SetDefaults() {
|
||||
b.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
|
||||
b.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
|
||||
b.WebsocketOrderbookBufferLimit = exchange.DefaultWebsocketOrderbookBufferLimit
|
||||
|
||||
}
|
||||
|
||||
// Setup takes in the supplied exchange configuration details and sets params
|
||||
|
||||
@@ -368,12 +368,9 @@ func TestCalculateTradingFee(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
|
||||
c.SetDefaults()
|
||||
expectedResult := exchange.AutoWithdrawCryptoWithAPIPermissionText + " & " + exchange.AutoWithdrawFiatWithAPIPermissionText
|
||||
|
||||
withdrawPermissions := c.FormatWithdrawPermissions()
|
||||
|
||||
if withdrawPermissions != expectedResult {
|
||||
t.Errorf("Expected: %s, Received: %s", expectedResult, withdrawPermissions)
|
||||
}
|
||||
@@ -450,7 +447,6 @@ func TestSubmitOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
c.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
@@ -477,7 +473,6 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
c.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
|
||||
@@ -454,7 +454,7 @@ type WebsocketTicker struct {
|
||||
BestBid float64 `json:"best_bid,string"`
|
||||
BestAsk float64 `json:"best_ask,string"`
|
||||
Side string `json:"side"`
|
||||
Time time.Time `json:"time,string"`
|
||||
Time time.Time `json:"time"`
|
||||
TradeID int64 `json:"trade_id"`
|
||||
LastSize float64 `json:"last_size,string"`
|
||||
}
|
||||
|
||||
@@ -248,7 +248,6 @@ func TestGetFee(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
|
||||
c.SetDefaults()
|
||||
expectedResult := exchange.WithdrawCryptoViaWebsiteOnlyText + " & " + exchange.WithdrawFiatViaWebsiteOnlyText
|
||||
|
||||
@@ -323,7 +322,6 @@ func TestSubmitOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
c.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
@@ -350,7 +348,6 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
c.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
|
||||
@@ -103,7 +103,6 @@ func (c *COINUT) WsHandleData() {
|
||||
}
|
||||
c.wsProcessResponse(individualJSON)
|
||||
}
|
||||
|
||||
} else {
|
||||
var incoming wsResponse
|
||||
err = common.JSONDecode(resp.Raw, &incoming)
|
||||
@@ -114,7 +113,6 @@ func (c *COINUT) WsHandleData() {
|
||||
|
||||
c.wsProcessResponse(resp.Raw)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,7 +356,6 @@ func (c *COINUT) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Pri
|
||||
}
|
||||
|
||||
return ticker.GetTicker(c.Name, p, assetType)
|
||||
|
||||
}
|
||||
|
||||
// FetchTicker returns the ticker for a currency pair
|
||||
@@ -728,7 +727,6 @@ func (c *COINUT) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, e
|
||||
CurrencyPair: p,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
order.FilterOrdersByTickRange(&allOrders, req.StartTicks, req.EndTicks)
|
||||
|
||||
@@ -255,7 +255,6 @@ func TestGetFee(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
|
||||
e.SetDefaults()
|
||||
expectedResult := exchange.AutoWithdrawCryptoWithSetupText + " & " + exchange.NoFiatWithdrawalsText
|
||||
|
||||
@@ -335,7 +334,6 @@ func TestSubmitOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
e.SetDefaults()
|
||||
TestSetup(t)
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
@@ -361,7 +359,6 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
e.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ type TradeHistory struct {
|
||||
|
||||
// ChartData contains chart data
|
||||
type ChartData struct {
|
||||
Timestamp time.Time `json:"timestamp,string"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Max float64 `json:"max,string"` // Max price
|
||||
Min float64 `json:"min,string"` // Min price
|
||||
Open float64 `json:"open,string"` // Open price
|
||||
@@ -74,7 +74,7 @@ type ChartData struct {
|
||||
type Currencies struct {
|
||||
ID string `json:"id"` // Currency identifier.
|
||||
FullName string `json:"fullName"` // Currency full name
|
||||
Crypto bool `json:"crypto,boolean"` // Is currency belongs to blockchain (false for ICO and fiat, like EUR)
|
||||
Crypto bool `json:"crypto"` // Is currency belongs to blockchain (false for ICO and fiat, like EUR)
|
||||
PayinEnabled bool `json:"payinEnabled"` // Is allowed for deposit (false for ICO)
|
||||
PayinPaymentID bool `json:"payinPaymentId"` // Is required to provide additional information other than the address for deposit
|
||||
PayinConfirmations int64 `json:"payinConfirmations"` // Blocks confirmations count for deposit
|
||||
@@ -134,10 +134,10 @@ type Order struct {
|
||||
Quantity float64 `json:"quantity,string"` // Order quantity
|
||||
Price float64 `json:"price,string"` // Order price
|
||||
CumQuantity float64 `json:"cumQuantity,string"` // Cumulative executed quantity
|
||||
CreatedAt time.Time `json:"createdAt,string"`
|
||||
UpdatedAt time.Time `json:"updatedAt,string"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
StopPrice float64 `json:"stopPrice,string"`
|
||||
ExpireTime time.Time `json:"expireTime,string"`
|
||||
ExpireTime time.Time `json:"expireTime"`
|
||||
}
|
||||
|
||||
// OpenOrdersResponseAll holds the full open order response
|
||||
@@ -260,7 +260,7 @@ type LoanOffer struct {
|
||||
Rate float64 `json:"rate,string"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
Duration int `json:"duration"`
|
||||
AutoRenew bool `json:"autoRenew,int"`
|
||||
AutoRenew bool `json:"autoRenew"`
|
||||
Date string `json:"date"`
|
||||
}
|
||||
|
||||
|
||||
@@ -470,7 +470,6 @@ func (k *Kraken) GetTradeBalance(args ...TradeBalanceOptions) (TradeBalanceInfo,
|
||||
if len(args[0].Asset) > 0 {
|
||||
params.Set("asset", args[0].Asset)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var response struct {
|
||||
|
||||
@@ -375,7 +375,6 @@ func (l *LakeBTC) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, err
|
||||
}
|
||||
|
||||
return cancelAllOrdersResponse, l.CancelExistingOrders(ordersToCancel)
|
||||
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
|
||||
@@ -169,7 +169,6 @@ func (l *Lbank) GetKlines(symbol, size, klineType, time string) ([]KlineResponse
|
||||
} else {
|
||||
tempResp.TradingVolume = resp2[x].(float64)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
k = append(k, tempResp)
|
||||
|
||||
@@ -655,7 +655,6 @@ func (l *Lbank) getAllOpenOrderID() (map[string][]string, error) {
|
||||
|
||||
for c := 0; c < tempData; c++ {
|
||||
resp[p] = append(resp[p], tempResp.Orders[c].OrderID)
|
||||
|
||||
}
|
||||
tempData = len(tempResp.Orders)
|
||||
b++
|
||||
|
||||
@@ -106,7 +106,7 @@ type AdEdit struct {
|
||||
MaxAmount int `json:"max_amount"`
|
||||
OpeningHours []string `json:"opening_hours"`
|
||||
LimitToFiatAmounts string `json:"limit_to_fiat_amounts"`
|
||||
Visible bool `json:"visible,int"`
|
||||
Visible bool `json:"visible"`
|
||||
|
||||
// Optional Arguments ONLINE_SELL ads
|
||||
RequireTradeVolume int `json:"require_trade_volume"`
|
||||
@@ -114,13 +114,13 @@ type AdEdit struct {
|
||||
FirstTimeLimitBTC int `json:"first_time_limit_btc"`
|
||||
VolumeCoefficientBTC int `json:"volume_coefficient_btc"`
|
||||
ReferenceType string `json:"reference_type"`
|
||||
DisplayReference bool `json:"display_reference,int"`
|
||||
DisplayReference bool `json:"display_reference"`
|
||||
|
||||
// Optional Arguments ONLINE_BUY
|
||||
PaymentWindowMinutes int `json:"payment_window_minutes"`
|
||||
|
||||
// Optional Arguments LOCAL_SELL
|
||||
Floating bool `json:"floating,int"`
|
||||
Floating bool `json:"floating"`
|
||||
}
|
||||
|
||||
// AdCreate references an outgoing paramater type for CreateAd() method
|
||||
@@ -148,7 +148,7 @@ type AdCreate struct {
|
||||
MaxAmount int `json:"max_amount"`
|
||||
OpeningHours []string `json:"opening_hours"`
|
||||
LimitToFiatAmounts string `json:"limit_to_fiat_amounts"`
|
||||
Visible bool `json:"visible,int"`
|
||||
Visible bool `json:"visible"`
|
||||
|
||||
// Optional Arguments ONLINE_SELL ads
|
||||
RequireTradeVolume int `json:"require_trade_volume"`
|
||||
@@ -156,13 +156,13 @@ type AdCreate struct {
|
||||
FirstTimeLimitBTC int `json:"first_time_limit_btc"`
|
||||
VolumeCoefficientBTC int `json:"volume_coefficient_btc"`
|
||||
ReferenceType string `json:"reference_type"`
|
||||
DisplayReference bool `json:"display_reference,int"`
|
||||
DisplayReference bool `json:"display_reference"`
|
||||
|
||||
// Optional Arguments ONLINE_BUY
|
||||
PaymentWindowMinutes int `json:"payment_window_minutes"`
|
||||
|
||||
// Optional Arguments LOCAL_SELL
|
||||
Floating bool `json:"floating,int"`
|
||||
Floating bool `json:"floating"`
|
||||
}
|
||||
|
||||
// Message holds the returned message data from a contact
|
||||
|
||||
@@ -160,7 +160,6 @@ func (l *LocalBitcoins) UpdateTradablePairs(forceUpdate bool) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return l.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
|
||||
@@ -420,7 +420,6 @@ func GetExcludedItems() (Exclusion, error) {
|
||||
if mErr != nil {
|
||||
return excludedList, mErr
|
||||
}
|
||||
|
||||
} else {
|
||||
err = json.Unmarshal(file, &excludedList)
|
||||
if err != nil {
|
||||
|
||||
@@ -1074,7 +1074,6 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
err := o.CancelOrder(&orderCancellation)
|
||||
testStandardErrorHandling(t, err)
|
||||
|
||||
}
|
||||
|
||||
// TestCancelAllExchangeOrders Wrapper test
|
||||
|
||||
@@ -1815,7 +1815,6 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
err := o.CancelOrder(&orderCancellation)
|
||||
testStandardErrorHandling(t, err)
|
||||
|
||||
}
|
||||
|
||||
// TestCancelAllExchangeOrders Wrapper test
|
||||
|
||||
@@ -626,7 +626,6 @@ func (o *OKGroup) SendHTTPRequest(httpMethod, requestType, requestPath string, d
|
||||
if !errCap.Result {
|
||||
return errors.New("unspecified error occurred")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return common.JSONDecode(intermediary, result)
|
||||
|
||||
@@ -20,19 +20,19 @@ type WhaleBombResult struct {
|
||||
}
|
||||
|
||||
// WhaleBomb finds the amount required to target a price
|
||||
func (o *Base) WhaleBomb(priceTarget float64, buy bool) (*WhaleBombResult, error) {
|
||||
func (b *Base) WhaleBomb(priceTarget float64, buy bool) (*WhaleBombResult, error) {
|
||||
if priceTarget < 0 {
|
||||
return nil, errors.New("price target is invalid")
|
||||
}
|
||||
if buy {
|
||||
a, orders := o.findAmount(priceTarget, true)
|
||||
a, orders := b.findAmount(priceTarget, true)
|
||||
min, max := orders.MinimumPrice(false), orders.MaximumPrice(true)
|
||||
var err error
|
||||
if max < priceTarget {
|
||||
err = errors.New("unable to hit price target due to insufficient orderbook items")
|
||||
}
|
||||
status := fmt.Sprintf("Buying %.2f %v worth of %v will send the price from %v to %v [%.2f%%] and take %v orders.",
|
||||
a, o.Pair.Quote.String(), o.Pair.Base.String(), min, max,
|
||||
a, b.Pair.Quote.String(), b.Pair.Base.String(), min, max,
|
||||
math.CalculatePercentageGainOrLoss(max, min), len(orders))
|
||||
return &WhaleBombResult{
|
||||
Amount: a,
|
||||
@@ -43,14 +43,14 @@ func (o *Base) WhaleBomb(priceTarget float64, buy bool) (*WhaleBombResult, error
|
||||
}, err
|
||||
}
|
||||
|
||||
a, orders := o.findAmount(priceTarget, false)
|
||||
a, orders := b.findAmount(priceTarget, false)
|
||||
min, max := orders.MinimumPrice(false), orders.MaximumPrice(true)
|
||||
var err error
|
||||
if min > priceTarget {
|
||||
err = errors.New("unable to hit price target due to insufficient orderbook items")
|
||||
}
|
||||
status := fmt.Sprintf("Selling %.2f %v worth of %v will send the price from %v to %v [%.2f%%] and take %v orders.",
|
||||
a, o.Pair.Base.String(), o.Pair.Quote.String(), max, min,
|
||||
a, b.Pair.Base.String(), b.Pair.Quote.String(), max, min,
|
||||
math.CalculatePercentageGainOrLoss(min, max), len(orders))
|
||||
return &WhaleBombResult{
|
||||
Amount: a,
|
||||
@@ -65,13 +65,13 @@ func (o *Base) WhaleBomb(priceTarget float64, buy bool) (*WhaleBombResult, error
|
||||
type OrderSimulationResult WhaleBombResult
|
||||
|
||||
// SimulateOrder simulates an order
|
||||
func (o *Base) SimulateOrder(amount float64, buy bool) *OrderSimulationResult {
|
||||
func (b *Base) SimulateOrder(amount float64, buy bool) *OrderSimulationResult {
|
||||
if buy {
|
||||
orders, amt := o.buy(amount)
|
||||
orders, amt := b.buy(amount)
|
||||
min, max := orders.MinimumPrice(false), orders.MaximumPrice(true)
|
||||
pct := math.CalculatePercentageGainOrLoss(max, min)
|
||||
status := fmt.Sprintf("Buying %.2f %v worth of %v will send the price from %v to %v [%.2f%%] and take %v orders.",
|
||||
amount, o.Pair.Quote.String(), o.Pair.Base.String(), min, max,
|
||||
amount, b.Pair.Quote.String(), b.Pair.Base.String(), min, max,
|
||||
pct, len(orders))
|
||||
return &OrderSimulationResult{
|
||||
Orders: orders,
|
||||
@@ -82,11 +82,11 @@ func (o *Base) SimulateOrder(amount float64, buy bool) *OrderSimulationResult {
|
||||
Status: status,
|
||||
}
|
||||
}
|
||||
orders, amt := o.sell(amount)
|
||||
orders, amt := b.sell(amount)
|
||||
min, max := orders.MinimumPrice(false), orders.MaximumPrice(true)
|
||||
pct := math.CalculatePercentageGainOrLoss(min, max)
|
||||
status := fmt.Sprintf("Selling %f %v worth of %v will send the price from %v to %v [%.2f%%] and take %v orders.",
|
||||
amount, o.Pair.Base.String(), o.Pair.Quote.String(), max, min,
|
||||
amount, b.Pair.Base.String(), b.Pair.Quote.String(), max, min,
|
||||
pct, len(orders))
|
||||
return &OrderSimulationResult{
|
||||
Orders: orders,
|
||||
@@ -138,89 +138,88 @@ func sortOrdersByPrice(o *orderSummary, reverse bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Base) findAmount(price float64, buy bool) (float64, orderSummary) {
|
||||
func (b *Base) findAmount(price float64, buy bool) (float64, orderSummary) {
|
||||
var orders orderSummary
|
||||
var amt float64
|
||||
|
||||
if buy {
|
||||
asks := o.Asks
|
||||
for x := range asks {
|
||||
if asks[x].Price >= price {
|
||||
amt += asks[x].Price * asks[x].Amount
|
||||
for x := range b.Asks {
|
||||
if b.Asks[x].Price >= price {
|
||||
amt += b.Asks[x].Price * b.Asks[x].Amount
|
||||
orders = append(orders, Item{
|
||||
Price: asks[x].Price,
|
||||
Amount: asks[x].Amount,
|
||||
Price: b.Asks[x].Price,
|
||||
Amount: b.Asks[x].Amount,
|
||||
})
|
||||
return amt, orders
|
||||
}
|
||||
orders = append(orders, Item{
|
||||
Price: asks[x].Price,
|
||||
Amount: asks[x].Amount,
|
||||
Price: b.Asks[x].Price,
|
||||
Amount: b.Asks[x].Amount,
|
||||
})
|
||||
amt += asks[x].Price * asks[x].Amount
|
||||
amt += b.Asks[x].Price * b.Asks[x].Amount
|
||||
}
|
||||
return amt, orders
|
||||
}
|
||||
|
||||
for x := range o.Bids {
|
||||
if o.Bids[x].Price <= price {
|
||||
amt += o.Bids[x].Amount
|
||||
for x := range b.Bids {
|
||||
if b.Bids[x].Price <= price {
|
||||
amt += b.Bids[x].Amount
|
||||
orders = append(orders, Item{
|
||||
Price: o.Bids[x].Price,
|
||||
Amount: o.Bids[x].Amount,
|
||||
Price: b.Bids[x].Price,
|
||||
Amount: b.Bids[x].Amount,
|
||||
})
|
||||
break
|
||||
}
|
||||
orders = append(orders, Item{
|
||||
Price: o.Bids[x].Price,
|
||||
Amount: o.Bids[x].Amount,
|
||||
Price: b.Bids[x].Price,
|
||||
Amount: b.Bids[x].Amount,
|
||||
})
|
||||
amt += o.Bids[x].Amount
|
||||
amt += b.Bids[x].Amount
|
||||
}
|
||||
return amt, orders
|
||||
}
|
||||
|
||||
func (o *Base) buy(amount float64) (orders orderSummary, baseAmount float64) {
|
||||
func (b *Base) buy(amount float64) (orders orderSummary, baseAmount float64) {
|
||||
var processedAmt float64
|
||||
for x := range o.Asks {
|
||||
subtotal := o.Asks[x].Price * o.Asks[x].Amount
|
||||
for x := range b.Asks {
|
||||
subtotal := b.Asks[x].Price * b.Asks[x].Amount
|
||||
if processedAmt+subtotal >= amount {
|
||||
diff := amount - processedAmt
|
||||
subAmt := diff / o.Asks[x].Price
|
||||
subAmt := diff / b.Asks[x].Price
|
||||
orders = append(orders, Item{
|
||||
Price: o.Asks[x].Price,
|
||||
Price: b.Asks[x].Price,
|
||||
Amount: subAmt,
|
||||
})
|
||||
baseAmount += subAmt
|
||||
break
|
||||
}
|
||||
processedAmt += subtotal
|
||||
baseAmount += o.Asks[x].Amount
|
||||
baseAmount += b.Asks[x].Amount
|
||||
orders = append(orders, Item{
|
||||
Price: o.Asks[x].Price,
|
||||
Amount: o.Asks[x].Amount,
|
||||
Price: b.Asks[x].Price,
|
||||
Amount: b.Asks[x].Amount,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (o *Base) sell(amount float64) (orders orderSummary, quoteAmount float64) {
|
||||
func (b *Base) sell(amount float64) (orders orderSummary, quoteAmount float64) {
|
||||
var processedAmt float64
|
||||
for x := range o.Bids {
|
||||
if processedAmt+o.Bids[x].Amount >= amount {
|
||||
for x := range b.Bids {
|
||||
if processedAmt+b.Bids[x].Amount >= amount {
|
||||
diff := amount - processedAmt
|
||||
orders = append(orders, Item{
|
||||
Price: o.Bids[x].Price,
|
||||
Price: b.Bids[x].Price,
|
||||
Amount: diff,
|
||||
})
|
||||
quoteAmount += diff * o.Bids[x].Price
|
||||
quoteAmount += diff * b.Bids[x].Price
|
||||
break
|
||||
}
|
||||
processedAmt += o.Bids[x].Amount
|
||||
quoteAmount += o.Bids[x].Amount * o.Bids[x].Price
|
||||
processedAmt += b.Bids[x].Amount
|
||||
quoteAmount += b.Bids[x].Amount * b.Bids[x].Price
|
||||
orders = append(orders, Item{
|
||||
Price: o.Bids[x].Price,
|
||||
Amount: o.Bids[x].Amount,
|
||||
Price: b.Bids[x].Price,
|
||||
Amount: b.Bids[x].Amount,
|
||||
})
|
||||
}
|
||||
return
|
||||
|
||||
@@ -262,7 +262,7 @@ type LoanOffer struct {
|
||||
Rate float64 `json:"rate,string"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
Duration int `json:"duration"`
|
||||
AutoRenew bool `json:"autoRenew,int"`
|
||||
AutoRenew bool `json:"autoRenew"`
|
||||
Date string `json:"date"`
|
||||
}
|
||||
|
||||
|
||||
@@ -595,7 +595,6 @@ func TestFlushCache(t *testing.T) {
|
||||
if obl.ob[cp][asset.Spot] != nil {
|
||||
t.Error("expected ob be flushed")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TestInsertingSnapShots logic test
|
||||
|
||||
Reference in New Issue
Block a user