diff --git a/config/config.go b/config/config.go index 531d3127b2c..322a13cd840 100644 --- a/config/config.go +++ b/config/config.go @@ -110,6 +110,7 @@ type ExchangeConfig struct { AvailablePairs string EnabledPairs string BaseCurrencies string + AssetTypes string ConfigCurrencyPairFormat *CurrencyPairFormatConfig `json:"ConfigCurrencyPairFormat"` RequestCurrencyPairFormat *CurrencyPairFormatConfig `json:"RequestCurrencyPairFormat"` } diff --git a/config_example.dat b/config_example.dat index 4e131c0f90b..ff0a64e202a 100644 --- a/config_example.dat +++ b/config_example.dat @@ -65,6 +65,7 @@ "AvailablePairs": "BTCUSD,BTCHKD,BTCEUR,BTCCAD,BTCAUD,BTCSGD,BTCJPY,BTCGBP,BTCNZD,LTCBTC,DOGEBTC,STRBTC,XRPBTC", "EnabledPairs": "BTCUSD,BTCHKD,BTCEUR,BTCCAD,BTCAUD,BTCSGD,BTCJPY,BTCGBP,BTCNZD,LTCBTC,DOGEBTC,STRBTC,XRPBTC", "BaseCurrencies": "USD,HKD,EUR,CAD,AUD,SGD,JPY,GBP,NZD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true, "Index": "BTC" @@ -86,6 +87,7 @@ "AvailablePairs": "BTCUSD,LTCUSD,LTCBTC,ETHUSD,ETHBTC,ETCBTC,ETCUSD,RRTUSD,RRTBTC,ZECUSD,ZECBTC,XMRUSD,XMRBTC,DSHUSD,DSHBTC,BCCBTC,BCUBTC,BCCUSD,BCUUSD,XRPUSD,XRPBTC,IOTUSD,IOTBTC,IOTETH,EOSUSD,EOSBTC,EOSETH,SANUSD,SANBTC,SANETH,OMGUSD,OMGBTC,OMGETH,BCHUSD,BCHBTC,BCHETH", "EnabledPairs": "BTCUSD,LTCUSD,LTCBTC,ETHUSD,ETHBTC", "BaseCurrencies": "USD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -106,6 +108,7 @@ "AvailablePairs": "BTCUSD,BTCEUR,EURUSD,XRPUSD,XRPEUR", "EnabledPairs": "BTCUSD,BTCEUR,EURUSD,XRPUSD,XRPEUR", "BaseCurrencies": "USD,EUR", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -122,9 +125,10 @@ "AuthenticatedAPISupport": false, "APIKey": "Key", "APISecret": "Secret", - "AvailablePairs": "BTC-LTC,BTC-DOGE,BTC-VTC,BTC-PPC,BTC-FTC,BTC-RDD,BTC-NXT,BTC-DASH,BTC-POT,BTC-BLK,BTC-XMY,BTC-AUR,BTC-EFL,BTC-GLD,BTC-SLR,BTC-PTC,BTC-GRS,BTC-NLG,BTC-RBY,BTC-XWC,BTC-MONA,BTC-THC,BTC-ENRG,BTC-ERC,BTC-NAUT,BTC-VRC,BTC-CURE,BTC-XBB,BTC-XMR,BTC-CLOAK,BTC-START,BTC-KORE,BTC-XDN,BTC-TRUST,BTC-NAV,BTC-XST,BTC-BTCD,BTC-VIA,BTC-UNO,BTC-PINK,BTC-IOC,BTC-CANN,BTC-SYS,BTC-NEOS,BTC-DGB,BTC-BURST,BTC-EXCL,BTC-SWIFT,BTC-DOPE,BTC-BLOCK,BTC-ABY,BTC-BYC,BTC-XMG,BTC-BLITZ,BTC-BAY,BTC-BTS,BTC-FAIR,BTC-SPR,BTC-VTR,BTC-XRP,BTC-GAME,BTC-COVAL,BTC-NXS,BTC-XCP,BTC-BITB,BTC-GEO,BTC-FLDC,BTC-GRC,BTC-FLO,BTC-NBT,BTC-MUE,BTC-XEM,BTC-CLAM,BTC-DMD,BTC-GAM,BTC-SPHR,BTC-OK,BTC-SNRG,BTC-PKB,BTC-CPC,BTC-AEON,BTC-ETH,BTC-GCR,BTC-TX,BTC-BCY,BTC-EXP,BTC-INFX,BTC-OMNI,BTC-AMP,BTC-AGRS,BTC-XLM,BTC-BTA,USDT-BTC,BITCNY-BTC,BTC-CLUB,BTC-VOX,BTC-EMC,BTC-FCT,BTC-MAID,BTC-EGC,BTC-SLS,BTC-RADS,BTC-DCR,BTC-SAFEX,BTC-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TC-MCO,ETH-MCO,BTC-ADT,ETH-ADT,BTC-FUN,ETH-FUN,BTC-PAY,ETH-PAY,BTC-MTL,ETH-MTL,BTC-STORJ,ETH-STORJ,BTC-ADX,ETH-ADX,ETH-DASH,ETH-SC,ETH-ZEC,USDT-ZEC,USDT-LTC,USDT-ETC,USDT-XRP,BTC-OMG,ETH-OMG,BTC-CVC,ETH-CVC,BTC-PART,BTC-QTUM,ETH-QTUM,ETH-XMR,ETH-XEM,ETH-XLM,ETH-NEO,USDT-XMR,USDT-DASH,ETH-BCC,USDT-BCC,BTC-BCC,USDT-NEO,ETH-WAVES,ETH-STRAT,ETH-DGB,ETH-FCT,ETH-BTS", "EnabledPairs": "USDT-BTC", "BaseCurrencies": "USD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true, "Delimiter": "-" @@ -146,6 +150,7 @@ "AvailablePairs": "BTCCNY,LTCCNY,LTCBTC", "EnabledPairs": "BTCCNY,LTCCNY,LTCBTC", "BaseCurrencies": "CNY", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -165,6 +170,7 @@ "AvailablePairs": "BTCUSD,BTCRUR,BTCEUR,LTCBTC,LTCUSD,LTCRUR,LTCEUR,NMCBTC,NMCUSD,NVCBTC,NVCUSD,USDRUR,EURUSD,EURRUR,PPCBTC,PPCUSD", "EnabledPairs": "BTCUSD,BTCRUR,BTCEUR,LTCBTC,LTCUSD,LTCRUR,LTCEUR,NMCBTC,NMCUSD,NVCBTC,NVCUSD,USDRUR,EURUSD,EURRUR,PPCBTC,PPCUSD", "BaseCurrencies": "USD,RUR,EUR", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -186,6 +192,7 @@ "AvailablePairs": "LTCAUD,BTCAUD", "EnabledPairs": "LTCAUD,BTCAUD", "BaseCurrencies": "AUD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -206,6 +213,7 @@ "AvailablePairs": "LTCBTC,ETCBTC,ETHBTC", "EnabledPairs": "LTCBTC,ETCBTC,ETHBTC", "BaseCurrencies": "USD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -226,6 +234,7 @@ "AvailablePairs": "LTCEUR,LTCBTC,BTCGBP,BTCEUR,ETHEUR,ETHBTC,LTCUSD,BTCUSD,ETHUSD", "EnabledPairs": "BTCUSD,BTCGBP,BTCEUR", "BaseCurrencies": "USD,GBP,EUR", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -246,6 +255,7 @@ "AvailablePairs": "BTCUSD,ETHBTC,ETHUSD", "EnabledPairs": "BTCUSD", "BaseCurrencies": "USD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -265,6 +275,7 @@ "AvailablePairs": "BTCCNY,LTCCNY", "EnabledPairs": "BTCCNY,LTCCNY", "BaseCurrencies": "CNY", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -285,6 +296,7 @@ "AvailablePairs": "XBTUSD,XBTSGD,XBTEUR", "EnabledPairs": "XBTUSD,XBTSGD,XBTEUR", "BaseCurrencies": "USD,SGD,EUR", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -301,9 +313,10 @@ "AuthenticatedAPISupport": false, "APIKey": "Key", "APISecret": "Secret", - "AvailablePairs": "XBTUSD,ZECEUR,REPETH,XBTJPY,ETHEUR.D,LTCXBT,GNOXBT,ETHCAD.D,ETHEUR,ETHUSD,ICNXBT,XDGXBT,BCHUSD,DASHEUR,ETHJPY.D,MLNXBT,XBTCAD,GNOETH,ETCUSD,REPXBT,ETCXBT,ICNETH,ETHXBT,XBTJPY.D,XMREUR,XRPUSD,ZECXBT,ETHCAD,XBTGBP.D,MLNETH,BCHEUR,ETCEUR,XBTEUR,XLMXBT,XRPXBT,ETCETH,REPEUR,XMRUSD,ZECUSD,USDTUSD,ETHXBT.D,ETHJPY,ETHUSD.D,XBTUSD.D,LTCUSD,XBTCAD.D,BCHXBT,DASHUSD,EOSXBT,ETHGBP.D,XMRXBT,XRPEUR,DASHXBT,EOSETH,LTCEUR,XBTEUR.D", + "AvailablePairs": "BCHEUR,REPEUR,XBTGBP,XBTUSD,ETHXBT,MLNXBT,ETCEUR,ETHGBP,ICNXBT,ZECEUR,EOSETH,GNOXBT,ETHCAD.D,ETHGBP.D,XRPEUR,BCHXBT,EOSXBT,LTCXBT,XBTEUR.D,XBTUSD.D,DASHUSD,GNOETH,ETHJPY,ETHUSD.D,REPETH,USDTUSD,ETHEUR,XLMXBT,BCHUSD,ETHCAD,XBTEUR,XMRUSD,ZECXBT,LTCUSD,XBTCAD,XMRXBT,ETHJPY.D,ICNETH,XBTCAD.D,XBTJPY,XRPUSD,ZECUSD,DASHEUR,ETCETH,ETCUSD,MLNETH,XMREUR,DASHXBT,ETHXBT.D,XDGXBT,XBTGBP.D,XRPXBT,XBTJPY.D,ETCXBT,ETHEUR.D,ETHUSD,LTCEUR,REPXBT", "EnabledPairs": "ETCUSD,XBTUSD,ETHUSD", "BaseCurrencies": "EUR,USD,CAD,GBP,JPY", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -324,6 +337,7 @@ "AvailablePairs": "BTCUSD,BTCEUR,USDHKD,AUDUSD,BTCGBP,BTCNZD,USDJPY,BTCSGD,BTCNGN,EURUSD,USDSGD,NZDUSD,USDNGN,USDCHF,BTCJPY,BTCAUD,BTCCAD,BTCCHF,GBPUSD,USDCAD", "EnabledPairs": "BTCUSD,BTCAUD", "BaseCurrencies": "USD,EUR,HKD,AUD,GBP,NZD,JPY,SGD,NGN,CHF,CAD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -340,9 +354,10 @@ "AuthenticatedAPISupport": false, "APIKey": "Key", "APISecret": "Secret", - "AvailablePairs": "SAN_BTC,OAX_BTC,VSL_BT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C,PAY_ETH,DGD_USDT,ZRX_BTC,WINGS_BTC,QRL_BTC,MCO_BTC,VSL_USDT,BAT_BTC,ANT_USDT,PAY_USDT,XID_ETH,TKN_BTC,EOS_ETH,NET_BTC,RLC_BTC,PTOY_BTC,SNM_ETH,OAX_BTC,1ST_ETH,BCAP_USDT,TRST_USDT,PLU_USDT,GUP_ETH,MCO_USDT,BCC_ETH,ROUND_ETH,TIME_ETH,TIME_BTC,ICN_USDT,GUP_BTC,SNGLS_USDT,PLU_BTC,MYST_USDT,CFI_USDT,SNT_BTC,SNT_ETH,ZRX_USDT,ICN_BTC,BAT_USDT,REP_USDT,HMQ_BTC,OAX_USDT,LTC_BTC,EDG_ETH,GNT_USDT,ROUND_USDT,BNT_USDT,CFI_BTC,CVC_BTC,BCC_USDT,GNT_BTC,STX_ETH,1ST_BTC,MGO_BTC,DNT_USDT,DASH_ETH,1ST_USDT,EDG_USDT,TKN_ETH,PTOY_USDT,ADX_ETH,LTC_USDT,RLC_ETH,HMQ_USDT,ANT_ETH,DGD_ETH,MLN_USDT,TRST_ETH,TAAS_USDT", "EnabledPairs": "ETH_BTC,LTC_BTC,DASH_BTC", "BaseCurrencies": "USD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true, "Delimiter": "_" @@ -365,6 +380,7 @@ "AvailablePairs": "BTCARS,BTCAUD,BTCBRL,BTCCAD,BTCCHF,BTCCZK,BTCDKK,BTCEUR,BTCGBP,BTCHKD,BTCILS,BTCINR,BTCMXN,BTCNOK,BTCNZD,BTCPLN,BTCRUB,BTCSEK,BTCSGD,BTCTHB,BTCUSD,BTCZAR", "EnabledPairs": "BTCARS,BTCAUD,BTCBRL,BTCCAD,BTCCHF,BTCCZK,BTCDKK,BTCEUR,BTCGBP,BTCHKD,BTCILS,BTCINR,BTCMXN,BTCNOK,BTCNZD,BTCPLN,BTCRUB,BTCSEK,BTCSGD,BTCTHB,BTCUSD,BTCZAR", "BaseCurrencies": "ARS,AUD,BRL,CAD,CHF,CZK,DKK,EUR,GBP,HKD,ILS,INR,MXN,NOK,NZD,PLN,RUB,SEK,SGD,THB,USD,ZAR", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -384,6 +400,7 @@ "AvailablePairs": "BTCCNY,LTCCNY", "EnabledPairs": "BTCCNY,LTCCNY", "BaseCurrencies": "CNY", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -404,6 +421,7 @@ "AvailablePairs": "BTCUSD,LTCUSD", "EnabledPairs": "BTCUSD,LTCUSD", "BaseCurrencies": "USD", + "AssetTypes": "SPOT,this_week,next_week,quarter", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -424,6 +442,7 @@ "AvailablePairs": "BTC_XUSD,BTC_FCT,BTC_MMNXT,BTC_NMC,BTC_BITUSD,BTC_RDD,BTC_XMR,BTC_XST,BTC_DSH,BTC_MAID,BTC_DGB,BTC_NEOS,BTC_BLK,BTC_NAUT,BTC_NBT,BTC_XCP,BTC_STR,BTC_BTCD,BTC_GRC,BTC_HUC,BTC_BBR,BTC_XDN,BTC_INDEX,BTC_IOC,BTC_SWARM,BTC_EMC2,BTC_MCN,BTC_NOXT,BTC_MINT,BTC_PTS,BTC_SC,BTC_GEO,BTC_XRP,BTC_FLO,BTC_BITS,BTC_HYP,BTC_XCR,BTC_LTBC,BTC_SYS,BTC_GMC,BTC_ETH,BTC_SYNC,BTC_GAP,BTC_BCN,BTC_C2,BTC_PINK,BTC_FIBRE,BTC_POT,BTC_QTL,BTC_SDC,BTC_XC,BTC_DASH,BTC_SILK,BTC_CLAM,BTC_NAV,BTC_PIGGY,BTC_BCY,BTC_MIL,BTC_XCN,BTC_YACC,BTC_BTS,BTC_QBK,BTC_SJCX,BTC_LQD,BTC_BURST,BTC_RIC,BTC_VRC,BTC_LTC,BTC_XPB,BTC_GRS,BTC_XCH,BTC_ARCH,BTC_QORA,BTC_HZ,BTC_NSR,BTC_XPM,BTC_BITCNY,BTC_EXE,BTC_XMG,BTC_BTC,BTC_BTM,BTC_NOBL,BTC_NXT,BTC_DOGE,BTC_CURE,BTC_MNTA,BTC_ADN,BTC_EXP,BTC_VTC,BTC_FLDC,BTC_MRS,BTC_MYR,BTC_OMNI,BTC_VNL,BTC_USDT,BTC_NOTE,BTC_WDC,BTC_BELA,BTC_VIA,BTC_CGA,BTC_DIEM,BTC_IFC,BTC_XDP,BTC_BLOCK,BTC_MMC,BTC_1CR,BTC_UNITY,BTC_XBC,BTC_GEMZ,BTC_FLT,BTC_PPC,BTC_XEM,BTC_RBY,BTC_CNMT,BTC_ABY,XMR_XDN,XMR_IFC,XMR_DIEM,XMR_BBR,XMR_DSH,XMR_BCN,XMR_LTC,XMR_MAID,XMR_DASH,XMR_BTCD,XMR_HYP,XMR_BLK,XMR_QORA,XMR_MNTA,XMR_NXT,USDT_BTC,USDT_ETH,USDT_XRP,USDT_DASH,USDT_LTC,USDT_NXT,USDT_XMR,USDT_STR", "EnabledPairs": "BTC_LTC,BTC_ETH,BTC_DOGE,BTC_DASH,BTC_XRP", "BaseCurrencies": "USD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true, "Delimiter": "_" diff --git a/events/event_test.go b/events/event_test.go index e9b9070bb53..c33c37bdbdb 100644 --- a/events/event_test.go +++ b/events/event_test.go @@ -5,27 +5,27 @@ import ( ) func TestAddEvent(t *testing.T) { - eventID, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", actionTest) + eventID, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", "SPOT", actionTest) if err != nil && eventID != 0 { t.Errorf("Test Failed. AddEvent: Error, %s", err) } - eventID, err = AddEvent("ANXX", "price", ">,==", "BTC", "LTC", actionTest) + eventID, err = AddEvent("ANXX", "price", ">,==", "BTC", "LTC", "SPOT", actionTest) if err == nil && eventID == 0 { t.Error("Test Failed. AddEvent: Error, error not captured in Exchange") } - eventID, err = AddEvent("ANX", "prices", ">,==", "BTC", "LTC", actionTest) + eventID, err = AddEvent("ANX", "prices", ">,==", "BTC", "LTC", "SPOT", actionTest) if err == nil && eventID == 0 { t.Error("Test Failed. AddEvent: Error, error not captured in Item") } - eventID, err = AddEvent("ANX", "price", "3===D", "BTC", "LTC", actionTest) + eventID, err = AddEvent("ANX", "price", "3===D", "BTC", "LTC", "SPOT", actionTest) if err == nil && eventID == 0 { t.Error("Test Failed. AddEvent: Error, error not captured in Condition") } - eventID, err = AddEvent("ANX", "price", ">,==", "BTC", "LTC", "console_prints") + eventID, err = AddEvent("ANX", "price", ">,==", "BTC", "LTC", "SPOT", "console_prints") if err == nil && eventID == 0 { t.Error("Test Failed. AddEvent: Error, error not captured in Action") } - eventID, err = AddEvent("ANX", "price", ">,==", "BATMAN", "ROBIN", actionTest) + eventID, err = AddEvent("ANX", "price", ">,==", "BATMAN", "ROBIN", "SPOT", actionTest) if err == nil && eventID == 0 { t.Error("Test Failed. AddEvent: Error, error not captured in Action") } @@ -35,7 +35,7 @@ func TestAddEvent(t *testing.T) { } func TestRemoveEvent(t *testing.T) { - eventID, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", actionTest) + eventID, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", "SPOT", actionTest) if err != nil && eventID != 0 { t.Errorf("Test Failed. RemoveEvent: Error, %s", err) } @@ -48,15 +48,15 @@ func TestRemoveEvent(t *testing.T) { } func TestGetEventCounter(t *testing.T) { - one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", actionTest) + one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", "SPOT", actionTest) if err != nil { t.Errorf("Test Failed. GetEventCounter: Error, %s", err) } - two, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", actionTest) + two, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", "SPOT", actionTest) if err != nil { t.Errorf("Test Failed. GetEventCounter: Error, %s", err) } - three, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", actionTest) + three, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", "SPOT", actionTest) if err != nil { t.Errorf("Test Failed. GetEventCounter: Error, %s", err) } @@ -84,7 +84,7 @@ func TestGetEventCounter(t *testing.T) { } func TestExecuteAction(t *testing.T) { - one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", actionTest) + one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", "SPOT", actionTest) if err != nil { t.Errorf("Test Failed. ExecuteAction: Error, %s", err) } @@ -100,13 +100,13 @@ func TestExecuteAction(t *testing.T) { } func TestEventToString(t *testing.T) { - one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", actionTest) + one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", "SPOT", actionTest) if err != nil { t.Errorf("Test Failed. EventToString: Error, %s", err) } eventString := Events[one].EventToString() - if eventString != "If the BTCLTC price on ANX is > == then ACTION_TEST." { + if eventString != "If the BTCLTC [SPOT] price on ANX is > == then ACTION_TEST." { t.Error("Test Failed. EventToString: Error, incorrect return string") } @@ -116,7 +116,7 @@ func TestEventToString(t *testing.T) { } func TestCheckCondition(t *testing.T) { //error handling needs to be implemented - one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", actionTest) + one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", "SPOT", actionTest) if err != nil { t.Errorf("Test Failed. EventToString: Error, %s", err) } diff --git a/events/events.go b/events/events.go index 5f3aa13e1e5..9105ec0679c 100644 --- a/events/events.go +++ b/events/events.go @@ -42,6 +42,7 @@ type Event struct { Item string Condition string FirstCurrency string + Asset string SecondCurrency string Action string Executed bool @@ -53,7 +54,7 @@ var Events []*Event // AddEvent adds an event to the Events chain and returns an index/eventID // and an error -func AddEvent(Exchange, Item, Condition, FirstCurrency, SecondCurrency, Action string) (int, error) { +func AddEvent(Exchange, Item, Condition, FirstCurrency, SecondCurrency, Asset, Action string) (int, error) { err := IsValidEvent(Exchange, Item, Condition, Action) if err != nil { return 0, err @@ -76,6 +77,7 @@ func AddEvent(Exchange, Item, Condition, FirstCurrency, SecondCurrency, Action s Event.Condition = Condition Event.FirstCurrency = FirstCurrency Event.SecondCurrency = SecondCurrency + Event.Asset = Asset Event.Action = Action Event.Executed = false Events = append(Events, Event) @@ -131,8 +133,8 @@ func (e *Event) ExecuteAction() bool { func (e *Event) EventToString() string { condition := common.SplitStrings(e.Condition, ",") return fmt.Sprintf( - "If the %s%s %s on %s is %s then %s.", e.FirstCurrency, e.SecondCurrency, - e.Item, e.Exchange, condition[0]+" "+condition[1], e.Action, + "If the %s%s [%s] %s on %s is %s then %s.", e.FirstCurrency, e.SecondCurrency, + e.Asset, e.Item, e.Exchange, condition[0]+" "+condition[1], e.Action, ) } @@ -147,7 +149,7 @@ func (e *Event) CheckCondition() bool { return false } - lastPrice := ticker.Price[pair.CurrencyItem(e.FirstCurrency)][pair.CurrencyItem(e.SecondCurrency)].Last + lastPrice := ticker.Price[pair.CurrencyItem(e.FirstCurrency)][pair.CurrencyItem(e.SecondCurrency)][e.Asset].Last if lastPrice == 0 { return false diff --git a/exchanges/alphapoint/alphapoint.go b/exchanges/alphapoint/alphapoint.go index 8da73698ce0..327bc2dd26d 100644 --- a/exchanges/alphapoint/alphapoint.go +++ b/exchanges/alphapoint/alphapoint.go @@ -11,6 +11,7 @@ import ( "github.com/gorilla/websocket" "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -49,6 +50,7 @@ type Alphapoint struct { func (a *Alphapoint) SetDefaults() { a.APIUrl = alphapointDefaultAPIURL a.WebsocketURL = alphapointDefaultWebsocketURL + a.AssetTypes = []string{ticker.Spot} } // GetTicker returns current ticker information from Alphapoint for a selected diff --git a/exchanges/alphapoint/alphapoint_wrapper.go b/exchanges/alphapoint/alphapoint_wrapper.go index 8ec18e8dadb..b93b09683cd 100644 --- a/exchanges/alphapoint/alphapoint_wrapper.go +++ b/exchanges/alphapoint/alphapoint_wrapper.go @@ -29,8 +29,8 @@ func (a *Alphapoint) GetExchangeAccountInfo() (exchange.AccountInfo, error) { } // UpdateTicker updates and returns the ticker for a currency pair -func (a *Alphapoint) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice +func (a *Alphapoint) UpdateTicker(p pair.CurrencyPair) (ticker.Price, error) { + var tickerPrice ticker.Price tick, err := a.GetTicker(p.Pair().String()) if err != nil { return tickerPrice, err @@ -43,13 +43,13 @@ func (a *Alphapoint) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, erro tickerPrice.High = tick.High tickerPrice.Volume = tick.Volume tickerPrice.Last = tick.Last - ticker.ProcessTicker(a.GetName(), p, tickerPrice) - return tickerPrice, nil + ticker.ProcessTicker(a.GetName(), p, tickerPrice, ticker.Spot) + return ticker.GetTicker(a.Name, p, ticker.Spot) } // GetTickerPrice returns the ticker for a currency pair -func (a *Alphapoint) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tick, err := ticker.GetTicker(a.GetName(), p) +func (a *Alphapoint) GetTickerPrice(p pair.CurrencyPair) (ticker.Price, error) { + tick, err := ticker.GetTicker(a.GetName(), p, ticker.Spot) if err != nil { return a.UpdateTicker(p) } @@ -74,9 +74,8 @@ func (a *Alphapoint) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBa orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data.Quantity, Price: data.Price}) } - orderBook.Pair = p orderbook.ProcessOrderbook(a.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(a.Name, p) } // GetOrderbookEx returns the orderbook for a currency pair diff --git a/exchanges/anx/anx.go b/exchanges/anx/anx.go index 9688fbabe59..1843a3c8dc0 100644 --- a/exchanges/anx/anx.go +++ b/exchanges/anx/anx.go @@ -11,6 +11,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -45,6 +46,7 @@ func (a *ANX) SetDefaults() { a.ConfigCurrencyPairFormat.Delimiter = "" a.ConfigCurrencyPairFormat.Uppercase = true a.ConfigCurrencyPairFormat.Index = "BTC" + a.AssetTypes = []string{ticker.Spot} } //Setup is run on startup to setup exchange with config values @@ -65,6 +67,10 @@ func (a *ANX) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = a.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/anx/anx_wrapper.go b/exchanges/anx/anx_wrapper.go index e6288c5d4f3..8c6e9c8c8c4 100644 --- a/exchanges/anx/anx_wrapper.go +++ b/exchanges/anx/anx_wrapper.go @@ -3,12 +3,10 @@ package anx import ( "log" "strconv" - "time" "github.com/thrasher-/gocryptotrader/currency/pair" "github.com/thrasher-/gocryptotrader/exchanges" "github.com/thrasher-/gocryptotrader/exchanges/orderbook" - "github.com/thrasher-/gocryptotrader/exchanges/stats" "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) @@ -23,29 +21,12 @@ func (a *ANX) Run() { log.Printf("%s polling delay: %ds.\n", a.GetName(), a.RESTPollingDelay) log.Printf("%s %d currencies enabled: %s.\n", a.GetName(), len(a.EnabledPairs), a.EnabledPairs) } - - for a.Enabled { - pairs := a.GetEnabledCurrencies() - for x := range pairs { - currency := pairs[x] - go func() { - ticker, err := a.UpdateTicker(currency) - if err != nil { - log.Println(err) - return - } - log.Printf("ANX %s: Last %f High %f Low %f Volume %f\n", exchange.FormatCurrency(currency).String(), ticker.Last, ticker.High, ticker.Low, ticker.Volume) - stats.AddExchangeInfo(a.GetName(), currency.GetFirstCurrency().String(), currency.GetSecondCurrency().String(), ticker.Last, ticker.Volume) - }() - } - time.Sleep(time.Second * a.RESTPollingDelay) - } } // UpdateTicker updates and returns the ticker for a currency pair -func (a *ANX) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice - tick, err := a.GetTicker(p.Pair().String()) +func (a *ANX) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price + tick, err := a.GetTicker(exchange.FormatExchangeCurrency(a.GetName(), p).String()) if err != nil { return tickerPrice, err } @@ -105,15 +86,15 @@ func (a *ANX) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { } else { tickerPrice.High = 0 } - ticker.ProcessTicker(a.GetName(), p, tickerPrice) - return tickerPrice, nil + ticker.ProcessTicker(a.GetName(), p, tickerPrice, assetType) + return ticker.GetTicker(a.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (a *ANX) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tickerNew, err := ticker.GetTicker(a.GetName(), p) +func (a *ANX) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tickerNew, err := ticker.GetTicker(a.GetName(), p, assetType) if err != nil { - return a.UpdateTicker(p) + return a.UpdateTicker(p, assetType) } return tickerNew, nil } diff --git a/exchanges/bitfinex/bitfinex.go b/exchanges/bitfinex/bitfinex.go index f1e148006dc..1c6185a4ea2 100644 --- a/exchanges/bitfinex/bitfinex.go +++ b/exchanges/bitfinex/bitfinex.go @@ -13,6 +13,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -85,6 +86,7 @@ func (b *Bitfinex) SetDefaults() { b.RequestCurrencyPairFormat.Uppercase = true b.ConfigCurrencyPairFormat.Delimiter = "" b.ConfigCurrencyPairFormat.Uppercase = true + b.AssetTypes = []string{ticker.Spot} } // Setup takes in the supplied exchange configuration details and sets params @@ -105,6 +107,10 @@ func (b *Bitfinex) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = b.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/bitfinex/bitfinex_wrapper.go b/exchanges/bitfinex/bitfinex_wrapper.go index d09f102037c..8a817e52e6e 100644 --- a/exchanges/bitfinex/bitfinex_wrapper.go +++ b/exchanges/bitfinex/bitfinex_wrapper.go @@ -39,8 +39,8 @@ func (b *Bitfinex) Run() { } // UpdateTicker updates and returns the ticker for a currency pair -func (b *Bitfinex) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice +func (b *Bitfinex) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price tickerNew, err := b.GetTicker(p.Pair().String(), nil) if err != nil { return tickerPrice, err @@ -53,15 +53,15 @@ func (b *Bitfinex) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) tickerPrice.Last = tickerNew.Last tickerPrice.Volume = tickerNew.Volume tickerPrice.High = tickerNew.High - ticker.ProcessTicker(b.GetName(), p, tickerPrice) - return tickerPrice, nil + ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType) + return ticker.GetTicker(b.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (b *Bitfinex) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tick, err := ticker.GetTicker(b.GetName(), p) +func (b *Bitfinex) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tick, err := ticker.GetTicker(b.GetName(), p, ticker.Spot) if err != nil { - return b.UpdateTicker(p) + return b.UpdateTicker(p, assetType) } return tick, nil } @@ -91,9 +91,8 @@ func (b *Bitfinex) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase orderBook.Bids = append(orderBook.Bids, orderbook.OrderbookItem{Price: orderbookNew.Bids[x].Price, Amount: orderbookNew.Bids[x].Amount}) } - orderBook.Pair = p orderbook.ProcessOrderbook(b.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(b.Name, p) } // GetExchangeAccountInfo retrieves balances for all enabled currencies on the diff --git a/exchanges/bitfinex/bitfinex_wrapper_test.go b/exchanges/bitfinex/bitfinex_wrapper_test.go index e1f634adfc7..4b61439286a 100644 --- a/exchanges/bitfinex/bitfinex_wrapper_test.go +++ b/exchanges/bitfinex/bitfinex_wrapper_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/thrasher-/gocryptotrader/currency/pair" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) func TestStart(t *testing.T) { @@ -18,7 +19,7 @@ func TestRun(t *testing.T) { func TestGetTickerPrice(t *testing.T) { getTickerPrice := Bitfinex{} - _, err := getTickerPrice.GetTickerPrice(pair.NewCurrencyPair("BTC", "USD")) + _, err := getTickerPrice.GetTickerPrice(pair.NewCurrencyPair("BTC", "USD"), ticker.Spot) if err != nil { t.Errorf("Test Failed - Bitfinex GetTickerPrice() error: %s", err) } diff --git a/exchanges/bitstamp/bitstamp.go b/exchanges/bitstamp/bitstamp.go index b10873d4556..cafffa043e0 100644 --- a/exchanges/bitstamp/bitstamp.go +++ b/exchanges/bitstamp/bitstamp.go @@ -13,6 +13,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -64,6 +65,7 @@ func (b *Bitstamp) SetDefaults() { b.RequestCurrencyPairFormat.Uppercase = true b.ConfigCurrencyPairFormat.Delimiter = "" b.ConfigCurrencyPairFormat.Uppercase = true + b.AssetTypes = []string{ticker.Spot} } // Setup sets configuration values to bitstamp @@ -84,6 +86,10 @@ func (b *Bitstamp) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = b.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/bitstamp/bitstamp_wrapper.go b/exchanges/bitstamp/bitstamp_wrapper.go index 2e8609edeae..31c44b53d43 100644 --- a/exchanges/bitstamp/bitstamp_wrapper.go +++ b/exchanges/bitstamp/bitstamp_wrapper.go @@ -29,8 +29,8 @@ func (b *Bitstamp) Run() { } // UpdateTicker updates and returns the ticker for a currency pair -func (b *Bitstamp) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice +func (b *Bitstamp) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price tick, err := b.GetTicker(p.Pair().String(), false) if err != nil { return tickerPrice, err @@ -43,15 +43,15 @@ func (b *Bitstamp) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) tickerPrice.Last = tick.Last tickerPrice.Volume = tick.Volume tickerPrice.High = tick.High - ticker.ProcessTicker(b.GetName(), p, tickerPrice) - return tickerPrice, nil + ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType) + return ticker.GetTicker(b.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (b *Bitstamp) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tick, err := ticker.GetTicker(b.GetName(), p) +func (b *Bitstamp) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tick, err := ticker.GetTicker(b.GetName(), p, assetType) if err != nil { - return b.UpdateTicker(p) + return b.UpdateTicker(p, assetType) } return tick, nil } @@ -83,9 +83,8 @@ func (b *Bitstamp) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data.Amount, Price: data.Price}) } - orderBook.Pair = p orderbook.ProcessOrderbook(b.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(b.Name, p) } // GetExchangeAccountInfo retrieves balances for all enabled currencies for the diff --git a/exchanges/bittrex/bittrex.go b/exchanges/bittrex/bittrex.go index b5ffd7a9a98..ab5791fb271 100644 --- a/exchanges/bittrex/bittrex.go +++ b/exchanges/bittrex/bittrex.go @@ -13,6 +13,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -70,6 +71,7 @@ func (b *Bittrex) SetDefaults() { b.RequestCurrencyPairFormat.Uppercase = true b.ConfigCurrencyPairFormat.Delimiter = "-" b.ConfigCurrencyPairFormat.Uppercase = true + b.AssetTypes = []string{ticker.Spot} } // Setup method sets current configuration details if enabled @@ -90,6 +92,10 @@ func (b *Bittrex) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = b.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/bittrex/bittrex_wrapper.go b/exchanges/bittrex/bittrex_wrapper.go index 72797a5442a..00392a32ac3 100644 --- a/exchanges/bittrex/bittrex_wrapper.go +++ b/exchanges/bittrex/bittrex_wrapper.go @@ -75,8 +75,8 @@ func (b *Bittrex) GetExchangeAccountInfo() (exchange.AccountInfo, error) { } // UpdateTicker updates and returns the ticker for a currency pair -func (b *Bittrex) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice +func (b *Bittrex) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price tick, err := b.GetMarketSummary(exchange.FormatExchangeCurrency(b.GetName(), p).String()) if err != nil { return tickerPrice, err @@ -86,15 +86,15 @@ func (b *Bittrex) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) tickerPrice.Bid = tick[0].Bid tickerPrice.Last = tick[0].Last tickerPrice.Volume = tick[0].Volume - ticker.ProcessTicker(b.GetName(), p, tickerPrice) - return tickerPrice, nil + ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType) + return ticker.GetTicker(b.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (b *Bittrex) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tick, err := ticker.GetTicker(b.GetName(), p) +func (b *Bittrex) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tick, err := ticker.GetTicker(b.GetName(), p, ticker.Spot) if err != nil { - return b.UpdateTicker(p) + return b.UpdateTicker(p, assetType) } return tick, nil } @@ -134,7 +134,6 @@ func (b *Bittrex) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, ) } - orderBook.Pair = p orderbook.ProcessOrderbook(b.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(b.Name, p) } diff --git a/exchanges/btcc/btcc.go b/exchanges/btcc/btcc.go index ec14b9e76cb..639499e967d 100644 --- a/exchanges/btcc/btcc.go +++ b/exchanges/btcc/btcc.go @@ -12,6 +12,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -59,6 +60,7 @@ func (b *BTCC) SetDefaults() { b.RequestCurrencyPairFormat.Uppercase = false b.ConfigCurrencyPairFormat.Delimiter = "" b.ConfigCurrencyPairFormat.Uppercase = true + b.AssetTypes = []string{ticker.Spot} } // Setup is run on startup to setup exchange with config values @@ -79,6 +81,10 @@ func (b *BTCC) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = b.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/btcc/btcc_wrapper.go b/exchanges/btcc/btcc_wrapper.go index b009339da64..bbab1953a45 100644 --- a/exchanges/btcc/btcc_wrapper.go +++ b/exchanges/btcc/btcc_wrapper.go @@ -29,8 +29,8 @@ func (b *BTCC) Run() { } // UpdateTicker updates and returns the ticker for a currency pair -func (b *BTCC) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice +func (b *BTCC) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price tick, err := b.GetTicker(exchange.FormatExchangeCurrency(b.GetName(), p).String()) if err != nil { return tickerPrice, err @@ -42,15 +42,15 @@ func (b *BTCC) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { tickerPrice.Last = tick.Last tickerPrice.Volume = tick.Vol tickerPrice.High = tick.High - ticker.ProcessTicker(b.GetName(), p, tickerPrice) - return tickerPrice, nil + ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType) + return ticker.GetTicker(b.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (b *BTCC) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tickerNew, err := ticker.GetTicker(b.GetName(), p) +func (b *BTCC) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tickerNew, err := ticker.GetTicker(b.GetName(), p, assetType) if err != nil { - return b.UpdateTicker(p) + return b.UpdateTicker(p, assetType) } return tickerNew, nil } @@ -82,9 +82,8 @@ func (b *BTCC) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, er orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Price: data[0], Amount: data[1]}) } - orderBook.Pair = p orderbook.ProcessOrderbook(b.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(b.Name, p) } // GetExchangeAccountInfo : Retrieves balances for all enabled currencies for diff --git a/exchanges/btce/btce.go b/exchanges/btce/btce.go index bebd3674da0..b251a4b5706 100644 --- a/exchanges/btce/btce.go +++ b/exchanges/btce/btce.go @@ -12,6 +12,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -53,6 +54,7 @@ func (b *BTCE) SetDefaults() { b.RequestCurrencyPairFormat.Separator = "-" b.ConfigCurrencyPairFormat.Delimiter = "" b.ConfigCurrencyPairFormat.Uppercase = true + b.AssetTypes = []string{ticker.Spot} } func (b *BTCE) Setup(exch config.ExchangeConfig) { @@ -72,6 +74,10 @@ func (b *BTCE) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = b.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/btce/btce_wrapper.go b/exchanges/btce/btce_wrapper.go index b37814a6f0d..0b8e3eed804 100644 --- a/exchanges/btce/btce_wrapper.go +++ b/exchanges/btce/btce_wrapper.go @@ -53,8 +53,8 @@ func (b *BTCE) Run() { } // UpdateTicker updates and returns the ticker for a currency pair -func (b *BTCE) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice +func (b *BTCE) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price result, err := b.GetTicker(p.Pair().String()) if err != nil { return tickerPrice, err @@ -71,15 +71,15 @@ func (b *BTCE) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { tickerPrice.Last = tick.Last tickerPrice.Volume = tick.Vol_cur tickerPrice.High = tick.High - ticker.ProcessTicker(b.GetName(), p, tickerPrice) - return tickerPrice, nil + ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType) + return ticker.GetTicker(b.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (b *BTCE) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tick, err := ticker.GetTicker(b.GetName(), p) +func (b *BTCE) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tick, err := ticker.GetTicker(b.GetName(), p, assetType) if err != nil { - return b.UpdateTicker(p) + return b.UpdateTicker(p, assetType) } return tick, nil } @@ -111,9 +111,8 @@ func (b *BTCE) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, er orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Price: data[0], Amount: data[1]}) } - orderBook.Pair = p orderbook.ProcessOrderbook(b.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(b.Name, p) } // GetExchangeAccountInfo retrieves balances for all enabled currencies for the diff --git a/exchanges/btcmarkets/btcmarkets.go b/exchanges/btcmarkets/btcmarkets.go index 9cc8916f8d7..4668fedd8f9 100644 --- a/exchanges/btcmarkets/btcmarkets.go +++ b/exchanges/btcmarkets/btcmarkets.go @@ -11,6 +11,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -56,6 +57,7 @@ func (b *BTCMarkets) SetDefaults() { b.RequestCurrencyPairFormat.Uppercase = true b.ConfigCurrencyPairFormat.Delimiter = "" b.ConfigCurrencyPairFormat.Uppercase = true + b.AssetTypes = []string{ticker.Spot} } // Setup takes in an exchange configuration and sets all paramaters @@ -76,6 +78,10 @@ func (b *BTCMarkets) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = b.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/btcmarkets/btcmarkets_wrapper.go b/exchanges/btcmarkets/btcmarkets_wrapper.go index a06b7bcb15c..841b316b598 100644 --- a/exchanges/btcmarkets/btcmarkets_wrapper.go +++ b/exchanges/btcmarkets/btcmarkets_wrapper.go @@ -51,8 +51,8 @@ func (b *BTCMarkets) Run() { } // UpdateTicker updates and returns the ticker for a currency pair -func (b *BTCMarkets) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice +func (b *BTCMarkets) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price tick, err := b.GetTicker(p.GetFirstCurrency().String()) if err != nil { return tickerPrice, err @@ -61,15 +61,15 @@ func (b *BTCMarkets) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, erro tickerPrice.Ask = tick.BestAsk tickerPrice.Bid = tick.BestBID tickerPrice.Last = tick.LastPrice - ticker.ProcessTicker(b.GetName(), p, tickerPrice) - return tickerPrice, nil + ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType) + return ticker.GetTicker(b.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (b *BTCMarkets) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tickerNew, err := ticker.GetTicker(b.GetName(), p) +func (b *BTCMarkets) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tickerNew, err := ticker.GetTicker(b.GetName(), p, assetType) if err != nil { - return b.UpdateTicker(p) + return b.UpdateTicker(p, assetType) } return tickerNew, nil } @@ -101,9 +101,8 @@ func (b *BTCMarkets) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBa orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data[1], Price: data[0]}) } - orderBook.Pair = p orderbook.ProcessOrderbook(b.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(b.Name, p) } // GetExchangeAccountInfo retrieves balances for all enabled currencies for the diff --git a/exchanges/coinut/coinut.go b/exchanges/coinut/coinut.go index a26d966c338..273c6f09b65 100644 --- a/exchanges/coinut/coinut.go +++ b/exchanges/coinut/coinut.go @@ -11,6 +11,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -52,6 +53,7 @@ func (c *COINUT) SetDefaults() { c.RequestCurrencyPairFormat.Uppercase = true c.ConfigCurrencyPairFormat.Delimiter = "" c.ConfigCurrencyPairFormat.Uppercase = true + c.AssetTypes = []string{ticker.Spot} } func (c *COINUT) Setup(exch config.ExchangeConfig) { @@ -71,6 +73,10 @@ func (c *COINUT) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = c.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/coinut/coinut_types.go b/exchanges/coinut/coinut_types.go index 91b55223cc6..10db1bf9bd6 100644 --- a/exchanges/coinut/coinut_types.go +++ b/exchanges/coinut/coinut_types.go @@ -34,7 +34,7 @@ type CoinutTicker struct { type CoinutOrderbookBase struct { Count int `json:"count"` Price float64 `json:"price,string"` - Quantity float64 `json:"quantity,string"` + Quantity float64 `json:"qty,string"` } type CoinutOrderbook struct { diff --git a/exchanges/coinut/coinut_wrapper.go b/exchanges/coinut/coinut_wrapper.go index a183016ec36..bb60982e0d9 100644 --- a/exchanges/coinut/coinut_wrapper.go +++ b/exchanges/coinut/coinut_wrapper.go @@ -69,11 +69,11 @@ func (c *COINUT) GetExchangeAccountInfo() (exchange.AccountInfo, error) { } // UpdateTicker updates and returns the ticker for a currency pair -func (c *COINUT) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice +func (c *COINUT) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price tick, err := c.GetInstrumentTicker(c.InstrumentMap[p.Pair().String()]) if err != nil { - return ticker.TickerPrice{}, err + return ticker.Price{}, err } tickerPrice.Pair = p @@ -81,16 +81,16 @@ func (c *COINUT) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { tickerPrice.Last = tick.Last tickerPrice.High = tick.HighestBuy tickerPrice.Low = tick.LowestSell - ticker.ProcessTicker(c.GetName(), p, tickerPrice) - return tickerPrice, nil + ticker.ProcessTicker(c.GetName(), p, tickerPrice, assetType) + return ticker.GetTicker(c.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (c *COINUT) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tickerNew, err := ticker.GetTicker(c.GetName(), p) +func (c *COINUT) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tickerNew, err := ticker.GetTicker(c.GetName(), p, assetType) if err != nil { - return c.UpdateTicker(p) + return c.UpdateTicker(p, assetType) } return tickerNew, nil } @@ -120,7 +120,6 @@ func (c *COINUT) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: orderbookNew.Sell[x].Quantity, Price: orderbookNew.Sell[x].Price}) } - orderBook.Pair = p orderbook.ProcessOrderbook(c.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(c.Name, p) } diff --git a/exchanges/exchange.go b/exchanges/exchange.go index 9ebb7ce792d..89c859e220a 100644 --- a/exchanges/exchange.go +++ b/exchanges/exchange.go @@ -49,6 +49,7 @@ type Base struct { BaseCurrencies []string AvailablePairs []string EnabledPairs []string + AssetTypes []string WebsocketURL string APIUrl string RequestCurrencyPairFormat config.CurrencyPairFormatConfig @@ -63,8 +64,8 @@ type IBotExchange interface { SetDefaults() GetName() string IsEnabled() bool - GetTickerPrice(currency pair.CurrencyPair) (ticker.TickerPrice, error) - UpdateTicker(currency pair.CurrencyPair) (ticker.TickerPrice, error) + GetTickerPrice(currency pair.CurrencyPair, assetType string) (ticker.Price, error) + UpdateTicker(currency pair.CurrencyPair, assetType string) (ticker.Price, error) GetOrderbookEx(currency pair.CurrencyPair) (orderbook.OrderbookBase, error) UpdateOrderbook(currency pair.CurrencyPair) (orderbook.OrderbookBase, error) GetEnabledCurrencies() []pair.CurrencyPair @@ -72,6 +73,42 @@ type IBotExchange interface { GetAuthenticatedAPISupport() bool } +// SetAssetTypes checks the exchange asset types (whether it supports SPOT, +// Binary or Futures) and sets it to a default setting if it doesn't exist +func (e *Base) SetAssetTypes() error { + cfg := config.GetConfig() + exch, err := cfg.GetExchangeConfig(e.Name) + if err != nil { + return err + } + + update := false + if exch.AssetTypes == "" { + exch.AssetTypes = common.JoinStrings(e.AssetTypes, ",") + update = true + } else { + e.AssetTypes = common.SplitStrings(exch.AssetTypes, ",") + } + + if update { + return cfg.UpdateExchangeConfig(exch) + } + + return nil +} + +// GetExchangeAssetTypes returns the asset types the exchange supports (SPOT, +// binary, futures) +func GetExchangeAssetTypes(exchName string) ([]string, error) { + cfg := config.GetConfig() + exch, err := cfg.GetExchangeConfig(exchName) + if err != nil { + return nil, err + } + + return common.SplitStrings(exch.AssetTypes, ","), nil +} + // SetCurrencyPairFormat checks the exchange request and config currency pair // formats and sets it to a default setting if it doesn't exist func (e *Base) SetCurrencyPairFormat() error { diff --git a/exchanges/gdax/gdax.go b/exchanges/gdax/gdax.go index 04a2d36106a..1ff4f59a13b 100644 --- a/exchanges/gdax/gdax.go +++ b/exchanges/gdax/gdax.go @@ -12,6 +12,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -50,6 +51,7 @@ func (g *GDAX) SetDefaults() { g.RequestCurrencyPairFormat.Uppercase = true g.ConfigCurrencyPairFormat.Delimiter = "" g.ConfigCurrencyPairFormat.Uppercase = true + g.AssetTypes = []string{ticker.Spot} } func (g *GDAX) Setup(exch config.ExchangeConfig) { @@ -69,6 +71,10 @@ func (g *GDAX) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = g.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/gdax/gdax_wrapper.go b/exchanges/gdax/gdax_wrapper.go index 13583d78972..f6705edc5b5 100644 --- a/exchanges/gdax/gdax_wrapper.go +++ b/exchanges/gdax/gdax_wrapper.go @@ -65,17 +65,17 @@ func (g *GDAX) GetExchangeAccountInfo() (exchange.AccountInfo, error) { } // UpdateTicker updates and returns the ticker for a currency pair -func (g *GDAX) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice +func (g *GDAX) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price tick, err := g.GetTicker(exchange.FormatExchangeCurrency(g.Name, p).String()) if err != nil { - return ticker.TickerPrice{}, err + return ticker.Price{}, err } stats, err := g.GetStats(exchange.FormatExchangeCurrency(g.Name, p).String()) if err != nil { - return ticker.TickerPrice{}, err + return ticker.Price{}, err } tickerPrice.Pair = p @@ -83,15 +83,15 @@ func (g *GDAX) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { tickerPrice.Last = tick.Price tickerPrice.High = stats.High tickerPrice.Low = stats.Low - ticker.ProcessTicker(g.GetName(), p, tickerPrice) - return tickerPrice, nil + ticker.ProcessTicker(g.GetName(), p, tickerPrice, assetType) + return ticker.GetTicker(g.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (g *GDAX) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tickerNew, err := ticker.GetTicker(g.GetName(), p) +func (g *GDAX) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tickerNew, err := ticker.GetTicker(g.GetName(), p, assetType) if err != nil { - return g.UpdateTicker(p) + return g.UpdateTicker(p, assetType) } return tickerNew, nil } @@ -108,7 +108,7 @@ func (g *GDAX) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, err // UpdateOrderbook updates and returns the orderbook for a currency pair func (g *GDAX) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, error) { var orderBook orderbook.OrderbookBase - orderbookNew, err := g.GetOrderbook(p.Pair().String(), 2) + orderbookNew, err := g.GetOrderbook(exchange.FormatExchangeCurrency(g.Name, p).String(), 2) if err != nil { return orderBook, err } @@ -123,7 +123,6 @@ func (g *GDAX) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, er orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: obNew.Bids[x].Amount, Price: obNew.Bids[x].Price}) } - orderBook.Pair = p orderbook.ProcessOrderbook(g.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(g.Name, p) } diff --git a/exchanges/gemini/gemini.go b/exchanges/gemini/gemini.go index 638ebd6ca51..35766c8b522 100644 --- a/exchanges/gemini/gemini.go +++ b/exchanges/gemini/gemini.go @@ -12,6 +12,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -49,6 +50,7 @@ func (g *Gemini) SetDefaults() { g.RequestCurrencyPairFormat.Uppercase = true g.ConfigCurrencyPairFormat.Delimiter = "" g.ConfigCurrencyPairFormat.Uppercase = true + g.AssetTypes = []string{ticker.Spot} } func (g *Gemini) Setup(exch config.ExchangeConfig) { @@ -68,6 +70,10 @@ func (g *Gemini) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = g.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/gemini/gemini_wrapper.go b/exchanges/gemini/gemini_wrapper.go index b948ce05274..19ee46d905b 100644 --- a/exchanges/gemini/gemini_wrapper.go +++ b/exchanges/gemini/gemini_wrapper.go @@ -53,8 +53,8 @@ func (g *Gemini) GetExchangeAccountInfo() (exchange.AccountInfo, error) { } // UpdateTicker updates and returns the ticker for a currency pair -func (g *Gemini) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice +func (g *Gemini) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price tick, err := g.GetTicker(p.Pair().String()) if err != nil { return tickerPrice, err @@ -64,15 +64,15 @@ func (g *Gemini) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { tickerPrice.Bid = tick.Bid tickerPrice.Last = tick.Last tickerPrice.Volume = tick.Volume.USD - ticker.ProcessTicker(g.GetName(), p, tickerPrice) - return tickerPrice, nil + ticker.ProcessTicker(g.GetName(), p, tickerPrice, assetType) + return ticker.GetTicker(g.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (g *Gemini) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tickerNew, err := ticker.GetTicker(g.GetName(), p) +func (g *Gemini) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tickerNew, err := ticker.GetTicker(g.GetName(), p, assetType) if err != nil { - return g.UpdateTicker(p) + return g.UpdateTicker(p, assetType) } return tickerNew, nil } @@ -102,7 +102,6 @@ func (g *Gemini) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: orderbookNew.Asks[x].Amount, Price: orderbookNew.Asks[x].Price}) } - orderBook.Pair = p orderbook.ProcessOrderbook(g.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(g.Name, p) } diff --git a/exchanges/huobi/huobi.go b/exchanges/huobi/huobi.go index 5b15a233d1b..f03517c4a46 100644 --- a/exchanges/huobi/huobi.go +++ b/exchanges/huobi/huobi.go @@ -11,6 +11,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -33,6 +34,7 @@ func (h *HUOBI) SetDefaults() { h.RequestCurrencyPairFormat.Uppercase = false h.ConfigCurrencyPairFormat.Delimiter = "" h.ConfigCurrencyPairFormat.Uppercase = true + h.AssetTypes = []string{ticker.Spot} } func (h *HUOBI) Setup(exch config.ExchangeConfig) { @@ -52,6 +54,10 @@ func (h *HUOBI) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = h.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/huobi/huobi_wrapper.go b/exchanges/huobi/huobi_wrapper.go index 07d36619fa5..10f7d5a4f50 100644 --- a/exchanges/huobi/huobi_wrapper.go +++ b/exchanges/huobi/huobi_wrapper.go @@ -29,8 +29,8 @@ func (h *HUOBI) Run() { } // UpdateTicker updates and returns the ticker for a currency pair -func (h *HUOBI) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice +func (h *HUOBI) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price tick, err := h.GetTicker(p.GetFirstCurrency().Lower().String()) if err != nil { return tickerPrice, err @@ -42,15 +42,15 @@ func (h *HUOBI) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { tickerPrice.Last = tick.Last tickerPrice.Volume = tick.Vol tickerPrice.High = tick.High - ticker.ProcessTicker(h.GetName(), p, tickerPrice) - return tickerPrice, nil + ticker.ProcessTicker(h.GetName(), p, tickerPrice, assetType) + return ticker.GetTicker(h.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (h *HUOBI) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tickerNew, err := ticker.GetTicker(h.GetName(), p) +func (h *HUOBI) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tickerNew, err := ticker.GetTicker(h.GetName(), p, assetType) if err != nil { - return h.UpdateTicker(p) + return h.UpdateTicker(p, assetType) } return tickerNew, nil } @@ -82,9 +82,8 @@ func (h *HUOBI) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, e orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data[1], Price: data[0]}) } - orderBook.Pair = p orderbook.ProcessOrderbook(h.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(h.Name, p) } //GetExchangeAccountInfo retrieves balances for all enabled currencies for the diff --git a/exchanges/itbit/itbit.go b/exchanges/itbit/itbit.go index ae2f1b94a5a..80aec2b0bb2 100644 --- a/exchanges/itbit/itbit.go +++ b/exchanges/itbit/itbit.go @@ -12,6 +12,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -35,6 +36,7 @@ func (i *ItBit) SetDefaults() { i.RequestCurrencyPairFormat.Uppercase = true i.ConfigCurrencyPairFormat.Delimiter = "" i.ConfigCurrencyPairFormat.Uppercase = true + i.AssetTypes = []string{ticker.Spot} } func (i *ItBit) Setup(exch config.ExchangeConfig) { @@ -54,6 +56,10 @@ func (i *ItBit) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = i.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/itbit/itbit_wrapper.go b/exchanges/itbit/itbit_wrapper.go index 445abc61795..871e923e4d6 100644 --- a/exchanges/itbit/itbit_wrapper.go +++ b/exchanges/itbit/itbit_wrapper.go @@ -24,9 +24,10 @@ func (i *ItBit) Run() { } // UpdateTicker updates and returns the ticker for a currency pair -func (i *ItBit) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice - tick, err := i.GetTicker(p.Pair().String()) +func (i *ItBit) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price + tick, err := i.GetTicker(exchange.FormatExchangeCurrency(i.Name, + p).String()) if err != nil { return tickerPrice, err } @@ -38,15 +39,15 @@ func (i *ItBit) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { tickerPrice.High = tick.High24h tickerPrice.Low = tick.Low24h tickerPrice.Volume = tick.Volume24h - ticker.ProcessTicker(i.GetName(), p, tickerPrice) - return tickerPrice, nil + ticker.ProcessTicker(i.GetName(), p, tickerPrice, assetType) + return ticker.GetTicker(i.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (i *ItBit) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tickerNew, err := ticker.GetTicker(i.GetName(), p) +func (i *ItBit) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tickerNew, err := ticker.GetTicker(i.GetName(), p, assetType) if err != nil { - return i.UpdateTicker(p) + return i.UpdateTicker(p, assetType) } return tickerNew, nil } @@ -63,7 +64,8 @@ func (i *ItBit) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, er // UpdateOrderbook updates and returns the orderbook for a currency pair func (i *ItBit) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, error) { var orderBook orderbook.OrderbookBase - orderbookNew, err := i.GetOrderbook(p.Pair().String()) + orderbookNew, err := i.GetOrderbook(exchange.FormatExchangeCurrency(i.Name, + p).String()) if err != nil { return orderBook, err } @@ -94,9 +96,8 @@ func (i *ItBit) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, e orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: amount, Price: price}) } - orderBook.Pair = p orderbook.ProcessOrderbook(i.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(i.Name, p) } // GetExchangeAccountInfo retrieves balances for all enabled currencies for the diff --git a/exchanges/kraken/kraken.go b/exchanges/kraken/kraken.go index cb90144e8f8..cd264052e38 100644 --- a/exchanges/kraken/kraken.go +++ b/exchanges/kraken/kraken.go @@ -12,6 +12,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -60,6 +61,7 @@ func (k *Kraken) SetDefaults() { k.RequestCurrencyPairFormat.Separator = "," k.ConfigCurrencyPairFormat.Delimiter = "" k.ConfigCurrencyPairFormat.Uppercase = true + k.AssetTypes = []string{ticker.Spot} } func (k *Kraken) Setup(exch config.ExchangeConfig) { @@ -79,6 +81,10 @@ func (k *Kraken) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = k.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/kraken/kraken_wrapper.go b/exchanges/kraken/kraken_wrapper.go index c05e69c880a..c880dafc8db 100644 --- a/exchanges/kraken/kraken_wrapper.go +++ b/exchanges/kraken/kraken_wrapper.go @@ -37,8 +37,8 @@ func (k *Kraken) Run() { } // UpdateTicker updates and returns the ticker for a currency pair -func (k *Kraken) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice +func (k *Kraken) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price pairs := k.GetEnabledCurrencies() pairsCollated, err := exchange.GetAndFormatExchangeCurrencies(k.Name, pairs) if err != nil { @@ -50,7 +50,7 @@ func (k *Kraken) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { } for _, x := range pairs { - var tp ticker.TickerPrice + var tp ticker.Price tick, ok := k.Ticker[x.Pair().String()] if !ok { continue @@ -63,16 +63,16 @@ func (k *Kraken) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { tp.High = tick.High tp.Low = tick.Low tp.Volume = tick.Volume - ticker.ProcessTicker(k.GetName(), x, tp) + ticker.ProcessTicker(k.GetName(), x, tp, assetType) } - return ticker.GetTicker(k.GetName(), p) + return ticker.GetTicker(k.GetName(), p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (k *Kraken) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tickerNew, err := ticker.GetTicker(k.GetName(), p) +func (k *Kraken) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tickerNew, err := ticker.GetTicker(k.GetName(), p, assetType) if err != nil { - return k.UpdateTicker(p) + return k.UpdateTicker(p, assetType) } return tickerNew, nil } @@ -102,9 +102,8 @@ func (k *Kraken) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: orderbookNew.Asks[x].Amount, Price: orderbookNew.Asks[x].Price}) } - orderBook.Pair = p orderbook.ProcessOrderbook(k.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(k.Name, p) } // GetExchangeAccountInfo retrieves balances for all enabled currencies for the diff --git a/exchanges/lakebtc/lakebtc.go b/exchanges/lakebtc/lakebtc.go index 79c0a9c96cc..62a8f604078 100644 --- a/exchanges/lakebtc/lakebtc.go +++ b/exchanges/lakebtc/lakebtc.go @@ -11,6 +11,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -46,6 +47,7 @@ func (l *LakeBTC) SetDefaults() { l.RequestCurrencyPairFormat.Uppercase = true l.ConfigCurrencyPairFormat.Delimiter = "" l.ConfigCurrencyPairFormat.Uppercase = true + l.AssetTypes = []string{ticker.Spot} } func (l *LakeBTC) Setup(exch config.ExchangeConfig) { @@ -65,6 +67,10 @@ func (l *LakeBTC) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = l.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/lakebtc/lakebtc_wrapper.go b/exchanges/lakebtc/lakebtc_wrapper.go index e9b463abede..df01c9fab3f 100644 --- a/exchanges/lakebtc/lakebtc_wrapper.go +++ b/exchanges/lakebtc/lakebtc_wrapper.go @@ -25,34 +25,32 @@ func (l *LakeBTC) Run() { } // UpdateTicker updates and returns the ticker for a currency pair -func (l *LakeBTC) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { +func (l *LakeBTC) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { tick, err := l.GetTicker() if err != nil { - return ticker.TickerPrice{}, err + return ticker.Price{}, err } - result, ok := tick[p.Pair().String()] - if !ok { - return ticker.TickerPrice{}, err + for _, x := range l.GetEnabledCurrencies() { + currency := exchange.FormatExchangeCurrency(l.Name, x).String() + var tickerPrice ticker.Price + tickerPrice.Pair = x + tickerPrice.Ask = tick[currency].Ask + tickerPrice.Bid = tick[currency].Bid + tickerPrice.Volume = tick[currency].Volume + tickerPrice.High = tick[currency].High + tickerPrice.Low = tick[currency].Low + tickerPrice.Last = tick[currency].Last + ticker.ProcessTicker(l.GetName(), x, tickerPrice, assetType) } - - var tickerPrice ticker.TickerPrice - tickerPrice.Pair = p - tickerPrice.Ask = result.Ask - tickerPrice.Bid = result.Bid - tickerPrice.Volume = result.Volume - tickerPrice.High = result.High - tickerPrice.Low = result.Low - tickerPrice.Last = result.Last - ticker.ProcessTicker(l.GetName(), p, tickerPrice) - return tickerPrice, nil + return ticker.GetTicker(l.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (l *LakeBTC) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tickerNew, err := ticker.GetTicker(l.GetName(), p) +func (l *LakeBTC) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tickerNew, err := ticker.GetTicker(l.GetName(), p, assetType) if err != nil { - return l.UpdateTicker(p) + return l.UpdateTicker(p, assetType) } return tickerNew, nil } @@ -82,9 +80,8 @@ func (l *LakeBTC) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: orderbookNew.Asks[x].Amount, Price: orderbookNew.Asks[x].Price}) } - orderBook.Pair = p orderbook.ProcessOrderbook(l.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(l.Name, p) } // GetExchangeAccountInfo retrieves balances for all enabled currencies for the diff --git a/exchanges/liqui/liqui.go b/exchanges/liqui/liqui.go index 4d610cb67a6..ca9c5f6a209 100644 --- a/exchanges/liqui/liqui.go +++ b/exchanges/liqui/liqui.go @@ -12,6 +12,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -51,6 +52,7 @@ func (l *Liqui) SetDefaults() { l.RequestCurrencyPairFormat.Separator = "-" l.ConfigCurrencyPairFormat.Delimiter = "_" l.ConfigCurrencyPairFormat.Uppercase = true + l.AssetTypes = []string{ticker.Spot} } func (l *Liqui) Setup(exch config.ExchangeConfig) { @@ -70,6 +72,10 @@ func (l *Liqui) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = l.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/liqui/liqui_wrapper.go b/exchanges/liqui/liqui_wrapper.go index ae3d5b791f1..ba934d99f89 100644 --- a/exchanges/liqui/liqui_wrapper.go +++ b/exchanges/liqui/liqui_wrapper.go @@ -36,8 +36,8 @@ func (l *Liqui) Run() { } // UpdateTicker updates and returns the ticker for a currency pair -func (l *Liqui) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice +func (l *Liqui) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price pairsString, err := exchange.GetAndFormatExchangeCurrencies(l.Name, l.GetEnabledCurrencies()) if err != nil { @@ -49,34 +49,34 @@ func (l *Liqui) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { return tickerPrice, err } - for x, y := range result { - var tp ticker.TickerPrice - currency := pair.NewCurrencyPairDelimiter(common.StringToUpper(x), "_") - tp.Pair = currency - tp.Last = y.Last - tp.Ask = y.Sell - tp.Bid = y.Buy - tp.Last = y.Last - tp.Low = y.Low - tp.Volume = y.Vol_cur - ticker.ProcessTicker(l.GetName(), currency, tp) + for _, x := range l.GetEnabledCurrencies() { + currency := exchange.FormatExchangeCurrency(l.Name, x).String() + var tp ticker.Price + tp.Pair = x + tp.Last = result[currency].Last + tp.Ask = result[currency].Sell + tp.Bid = result[currency].Buy + tp.Last = result[currency].Last + tp.Low = result[currency].Low + tp.Volume = result[currency].Vol_cur + ticker.ProcessTicker(l.Name, x, tp, assetType) } - return ticker.GetTicker(l.GetName(), p) + return ticker.GetTicker(l.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (l *Liqui) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tickerNew, err := ticker.GetTicker(l.GetName(), p) +func (l *Liqui) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tickerNew, err := ticker.GetTicker(l.Name, p, assetType) if err != nil { - return l.UpdateTicker(p) + return l.UpdateTicker(p, assetType) } return tickerNew, nil } // GetOrderbookEx returns orderbook base on the currency pair func (l *Liqui) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, error) { - ob, err := orderbook.GetOrderbook(l.GetName(), p) + ob, err := orderbook.GetOrderbook(l.Name, p) if err == nil { return l.UpdateOrderbook(p) } @@ -101,9 +101,8 @@ func (l *Liqui) UpdateOrderbook(p pair.CurrencyPair) (orderbook.OrderbookBase, e orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data[1], Price: data[0]}) } - orderBook.Pair = p - orderbook.ProcessOrderbook(l.GetName(), p, orderBook) - return orderBook, nil + orderbook.ProcessOrderbook(l.Name, p, orderBook) + return orderbook.GetOrderbook(l.Name, p) } // GetExchangeAccountInfo retrieves balances for all enabled currencies for the diff --git a/exchanges/localbitcoins/localbitcoins.go b/exchanges/localbitcoins/localbitcoins.go index 5370503eff7..705c0aca0eb 100644 --- a/exchanges/localbitcoins/localbitcoins.go +++ b/exchanges/localbitcoins/localbitcoins.go @@ -12,6 +12,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -42,6 +43,7 @@ func (l *LocalBitcoins) SetDefaults() { l.RequestCurrencyPairFormat.Uppercase = true l.ConfigCurrencyPairFormat.Delimiter = "" l.ConfigCurrencyPairFormat.Uppercase = true + l.AssetTypes = []string{ticker.Spot} } func (l *LocalBitcoins) Setup(exch config.ExchangeConfig) { @@ -61,6 +63,10 @@ func (l *LocalBitcoins) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = l.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/localbitcoins/localbitcoins_wrapper.go b/exchanges/localbitcoins/localbitcoins_wrapper.go index 5a980492e7b..06685353277 100644 --- a/exchanges/localbitcoins/localbitcoins_wrapper.go +++ b/exchanges/localbitcoins/localbitcoins_wrapper.go @@ -3,8 +3,6 @@ package localbitcoins import ( "log" - "github.com/thrasher-/gocryptotrader/common" - "github.com/thrasher-/gocryptotrader/currency/pair" "github.com/thrasher-/gocryptotrader/exchanges" "github.com/thrasher-/gocryptotrader/exchanges/orderbook" @@ -25,30 +23,30 @@ func (l *LocalBitcoins) Run() { } // UpdateTicker updates and returns the ticker for a currency pair -func (l *LocalBitcoins) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice +func (l *LocalBitcoins) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price tick, err := l.GetTicker() if err != nil { return tickerPrice, err } - for key, value := range tick { - currency := pair.NewCurrencyPair("BTC", common.StringToUpper(key)) - var tp ticker.TickerPrice - tp.Pair = currency - tp.Last = value.Rates.Last - tp.Volume = value.VolumeBTC - ticker.ProcessTicker(l.GetName(), currency, tp) + for _, x := range l.GetEnabledCurrencies() { + currency := x.SecondCurrency.String() + var tp ticker.Price + tp.Pair = x + tp.Last = tick[currency].Rates.Last + tp.Volume = tick[currency].VolumeBTC + ticker.ProcessTicker(l.GetName(), x, tp, assetType) } - return ticker.GetTicker(l.GetName(), p) + return ticker.GetTicker(l.GetName(), p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (l *LocalBitcoins) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) { - tickerNew, err := ticker.GetTicker(l.GetName(), p) +func (l *LocalBitcoins) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tickerNew, err := ticker.GetTicker(l.GetName(), p, assetType) if err == nil { - return l.UpdateTicker(p) + return l.UpdateTicker(p, assetType) } return tickerNew, nil } @@ -77,12 +75,11 @@ func (l *LocalBitcoins) UpdateOrderbook(p pair.CurrencyPair) (orderbook.Orderboo for x := range orderbookNew.Asks { data := orderbookNew.Asks[x] - orderBook.Bids = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data.Amount, Price: data.Price}) + orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data.Amount, Price: data.Price}) } - orderBook.Pair = p orderbook.ProcessOrderbook(l.GetName(), p, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(l.Name, p) } // GetExchangeAccountInfo retrieves balances for all enabled currencies for the diff --git a/exchanges/okcoin/okcoin.go b/exchanges/okcoin/okcoin.go index 47ed673ec8d..e9b8364b440 100644 --- a/exchanges/okcoin/okcoin.go +++ b/exchanges/okcoin/okcoin.go @@ -12,6 +12,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -93,8 +94,10 @@ func (o *OKCoin) SetDefaults() { o.Websocket = false o.RESTPollingDelay = 10 o.FuturesValues = []string{"this_week", "next_week", "quarter"} + o.AssetTypes = []string{ticker.Spot} if !okcoinDefaultsSet { + o.AssetTypes = append(o.AssetTypes, o.FuturesValues...) o.APIUrl = OKCOIN_API_URL o.Name = "OKCOIN International" o.WebsocketURL = OKCOIN_WEBSOCKET_URL @@ -125,6 +128,10 @@ func (o *OKCoin) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = o.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } diff --git a/exchanges/okcoin/okcoin_wrapper.go b/exchanges/okcoin/okcoin_wrapper.go index 937ed9aa82b..a1a4807f945 100644 --- a/exchanges/okcoin/okcoin_wrapper.go +++ b/exchanges/okcoin/okcoin_wrapper.go @@ -2,13 +2,11 @@ package okcoin import ( "log" - "time" "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/currency/pair" "github.com/thrasher-/gocryptotrader/exchanges" "github.com/thrasher-/gocryptotrader/exchanges/orderbook" - "github.com/thrasher-/gocryptotrader/exchanges/stats" "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) @@ -28,53 +26,49 @@ func (o *OKCoin) Run() { if o.Websocket { go o.WebsocketClient() } - - for o.Enabled { - pairs := o.GetEnabledCurrencies() - for x := range pairs { - curr := pairs[x] - if o.APIUrl == OKCOIN_API_URL { - for _, y := range o.FuturesValues { - futuresValue := y - go func() { - ticker, err := o.GetFuturesTicker(exchange.FormatExchangeCurrency(o.Name, curr).String(), futuresValue) - if err != nil { - log.Println(err) - return - } - log.Printf("OKCoin Intl Futures %s (%s): Last %f High %f Low %f Volume %f\n", exchange.FormatCurrency(curr).String(), futuresValue, ticker.Last, ticker.High, ticker.Low, ticker.Vol) - stats.AddExchangeInfo(o.GetName(), curr.GetFirstCurrency().String(), curr.GetSecondCurrency().String(), ticker.Last, ticker.Vol) - }() - } - } - } - time.Sleep(time.Second * o.RESTPollingDelay) - } } // UpdateTicker updates and returns the ticker for a currency pair -func (o *OKCoin) UpdateTicker(currency pair.CurrencyPair) (ticker.TickerPrice, error) { - var tickerPrice ticker.TickerPrice - tick, err := o.GetTicker(exchange.FormatExchangeCurrency(o.Name, currency).String()) - if err != nil { - return tickerPrice, err +func (o *OKCoin) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + currency := exchange.FormatExchangeCurrency(o.Name, p).String() + var tickerPrice ticker.Price + + if assetType != ticker.Spot && o.APIUrl == OKCOIN_API_URL { + tick, err := o.GetFuturesTicker(currency, assetType) + if err != nil { + return tickerPrice, err + } + tickerPrice.Pair = p + tickerPrice.Ask = tick.Sell + tickerPrice.Bid = tick.Buy + tickerPrice.Low = tick.Low + tickerPrice.Last = tick.Last + tickerPrice.Volume = tick.Vol + tickerPrice.High = tick.High + ticker.ProcessTicker(o.GetName(), p, tickerPrice, assetType) + } else { + tick, err := o.GetTicker(currency) + if err != nil { + return tickerPrice, err + } + tickerPrice.Pair = p + tickerPrice.Ask = tick.Sell + tickerPrice.Bid = tick.Buy + tickerPrice.Low = tick.Low + tickerPrice.Last = tick.Last + tickerPrice.Volume = tick.Vol + tickerPrice.High = tick.High + ticker.ProcessTicker(o.GetName(), p, tickerPrice, ticker.Spot) + } - tickerPrice.Pair = currency - tickerPrice.Ask = tick.Sell - tickerPrice.Bid = tick.Buy - tickerPrice.Low = tick.Low - tickerPrice.Last = tick.Last - tickerPrice.Volume = tick.Vol - tickerPrice.High = tick.High - ticker.ProcessTicker(o.GetName(), currency, tickerPrice) - return tickerPrice, nil + return ticker.GetTicker(o.Name, p, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (o *OKCoin) GetTickerPrice(currency pair.CurrencyPair) (ticker.TickerPrice, error) { - tickerNew, err := ticker.GetTicker(o.GetName(), currency) +func (o *OKCoin) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) { + tickerNew, err := ticker.GetTicker(o.GetName(), p, assetType) if err != nil { - return o.UpdateTicker(currency) + return o.UpdateTicker(p, assetType) } return tickerNew, nil } @@ -106,9 +100,8 @@ func (o *OKCoin) UpdateOrderbook(currency pair.CurrencyPair) (orderbook.Orderboo orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data[1], Price: data[0]}) } - orderBook.Pair = currency orderbook.ProcessOrderbook(o.GetName(), currency, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(o.Name, currency) } // GetExchangeAccountInfo retrieves balances for all enabled currencies for the diff --git a/exchanges/orderbook/orderbook.go b/exchanges/orderbook/orderbook.go index d9391a58d94..50528dacca0 100644 --- a/exchanges/orderbook/orderbook.go +++ b/exchanges/orderbook/orderbook.go @@ -122,6 +122,7 @@ func CreateNewOrderbook(exchangeName string, p pair.CurrencyPair, orderbookNew O func ProcessOrderbook(exchangeName string, p pair.CurrencyPair, orderbookNew OrderbookBase) { orderbookNew.CurrencyPair = p.Pair().String() + orderbookNew.LastUpdated = time.Now() if len(Orderbooks) == 0 { CreateNewOrderbook(exchangeName, p, orderbookNew) return diff --git a/exchanges/poloniex/poloniex.go b/exchanges/poloniex/poloniex.go index e34cde5822c..3c777206d9e 100644 --- a/exchanges/poloniex/poloniex.go +++ b/exchanges/poloniex/poloniex.go @@ -12,6 +12,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -62,6 +63,7 @@ func (p *Poloniex) SetDefaults() { p.RequestCurrencyPairFormat.Uppercase = true p.ConfigCurrencyPairFormat.Delimiter = "_" p.ConfigCurrencyPairFormat.Uppercase = true + p.AssetTypes = []string{ticker.Spot} } func (p *Poloniex) Setup(exch config.ExchangeConfig) { @@ -81,6 +83,10 @@ func (p *Poloniex) Setup(exch config.ExchangeConfig) { if err != nil { log.Fatal(err) } + err = p.SetAssetTypes() + if err != nil { + log.Fatal(err) + } } } @@ -133,14 +139,20 @@ func (p *Poloniex) GetOrderbook(currencyPair string, depth int) (PoloniexOrderbo ob := PoloniexOrderbook{} for x := range resp.Asks { data := resp.Asks[x] - price, _ := strconv.ParseFloat(data[0].(string), 64) + price, err := strconv.ParseFloat(data[0].(string), 64) + if err != nil { + return ob, err + } amount := data[1].(float64) ob.Asks = append(ob.Asks, PoloniexOrderbookItem{Price: price, Amount: amount}) } for x := range resp.Bids { data := resp.Bids[x] - price, _ := strconv.ParseFloat(data[0].(string), 64) + price, err := strconv.ParseFloat(data[0].(string), 64) + if err != nil { + return ob, err + } amount := data[1].(float64) ob.Bids = append(ob.Bids, PoloniexOrderbookItem{Price: price, Amount: amount}) } diff --git a/exchanges/poloniex/poloniex_wrapper.go b/exchanges/poloniex/poloniex_wrapper.go index e779f4b87dc..10896e50ea3 100644 --- a/exchanges/poloniex/poloniex_wrapper.go +++ b/exchanges/poloniex/poloniex_wrapper.go @@ -29,30 +29,33 @@ func (p *Poloniex) Run() { } // UpdateTicker updates and returns the ticker for a currency pair -func (p *Poloniex) UpdateTicker(currencyPair pair.CurrencyPair) (ticker.TickerPrice, error) { - currency := exchange.FormatCurrency(currencyPair).String() - var tickerPrice ticker.TickerPrice +func (p *Poloniex) UpdateTicker(currencyPair pair.CurrencyPair, assetType string) (ticker.Price, error) { + var tickerPrice ticker.Price tick, err := p.GetTicker() if err != nil { return tickerPrice, err } - tickerPrice.Pair = currencyPair - tickerPrice.Ask = tick[currency].Last - tickerPrice.Bid = tick[currency].HighestBid - tickerPrice.High = tick[currency].HighestBid - tickerPrice.Last = tick[currency].Last - tickerPrice.Low = tick[currency].LowestAsk - tickerPrice.Volume = tick[currency].BaseVolume - ticker.ProcessTicker(p.GetName(), currencyPair, tickerPrice) - return tickerPrice, nil + for _, x := range p.GetEnabledCurrencies() { + var tp ticker.Price + curr := exchange.FormatExchangeCurrency(p.GetName(), x).String() + tp.Pair = x + tp.Ask = tick[curr].LowestAsk + tp.Bid = tick[curr].HighestBid + tp.High = tick[curr].High24Hr + tp.Last = tick[curr].Last + tp.Low = tick[curr].Low24Hr + tp.Volume = tick[curr].BaseVolume + ticker.ProcessTicker(p.GetName(), x, tp, assetType) + } + return ticker.GetTicker(p.Name, currencyPair, assetType) } // GetTickerPrice returns the ticker for a currency pair -func (p *Poloniex) GetTickerPrice(currencyPair pair.CurrencyPair) (ticker.TickerPrice, error) { - tickerNew, err := ticker.GetTicker(p.GetName(), currencyPair) +func (p *Poloniex) GetTickerPrice(currencyPair pair.CurrencyPair, assetType string) (ticker.Price, error) { + tickerNew, err := ticker.GetTicker(p.GetName(), currencyPair, assetType) if err != nil { - return p.UpdateTicker(currencyPair) + return p.UpdateTicker(currencyPair, assetType) } return tickerNew, nil } @@ -69,7 +72,7 @@ func (p *Poloniex) GetOrderbookEx(currencyPair pair.CurrencyPair) (orderbook.Ord // UpdateOrderbook updates and returns the orderbook for a currency pair func (p *Poloniex) UpdateOrderbook(currencyPair pair.CurrencyPair) (orderbook.OrderbookBase, error) { var orderBook orderbook.OrderbookBase - orderbookNew, err := p.GetOrderbook(exchange.FormatCurrency(currencyPair).String(), 1000) + orderbookNew, err := p.GetOrderbook(exchange.FormatExchangeCurrency(p.GetName(), currencyPair).String(), 1000) if err != nil { return orderBook, err } @@ -83,9 +86,9 @@ func (p *Poloniex) UpdateOrderbook(currencyPair pair.CurrencyPair) (orderbook.Or data := orderbookNew.Asks[x] orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data.Amount, Price: data.Price}) } - orderBook.Pair = currencyPair + orderbook.ProcessOrderbook(p.GetName(), currencyPair, orderBook) - return orderBook, nil + return orderbook.GetOrderbook(p.Name, currencyPair) } // GetExchangeAccountInfo retrieves balances for all enabled currencies for the diff --git a/exchanges/ticker/ticker.go b/exchanges/ticker/ticker.go index 576e13d7d37..3d2c23c7003 100644 --- a/exchanges/ticker/ticker.go +++ b/exchanges/ticker/ticker.go @@ -8,15 +8,22 @@ import ( "github.com/thrasher-/gocryptotrader/currency/pair" ) -var ( +// Const values for the ticker package +const ( ErrTickerForExchangeNotFound = "Ticker for exchange does not exist." ErrPrimaryCurrencyNotFound = "Error primary currency for ticker not found." ErrSecondaryCurrencyNotFound = "Error secondary currency for ticker not found." + Spot = "SPOT" +) + +// Vars for the ticker package +var ( Tickers []Ticker ) -type TickerPrice struct { +// Price struct stores the currency pair and pricing information +type Price struct { Pair pair.CurrencyPair `json:"Pair"` CurrencyPair string `json:"CurrencyPair"` Last float64 `json:"Last"` @@ -28,50 +35,55 @@ type TickerPrice struct { PriceATH float64 `json:"PriceATH"` } +// Ticker struct holds the ticker information for a currency pair and type type Ticker struct { - Price map[pair.CurrencyItem]map[pair.CurrencyItem]TickerPrice + Price map[pair.CurrencyItem]map[pair.CurrencyItem]map[string]Price ExchangeName string } -func (t *Ticker) PriceToString(p pair.CurrencyPair, priceType string) string { +// PriceToString returns the string version of a stored price field +func (t *Ticker) PriceToString(p pair.CurrencyPair, priceType, tickerType string) string { priceType = common.StringToLower(priceType) + switch priceType { case "last": - return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].Last, 'f', -1, 64) + return strconv.FormatFloat(t.Price[p.FirstCurrency][p.SecondCurrency][tickerType].Last, 'f', -1, 64) case "high": - return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].High, 'f', -1, 64) + return strconv.FormatFloat(t.Price[p.FirstCurrency][p.SecondCurrency][tickerType].High, 'f', -1, 64) case "low": - return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].Low, 'f', -1, 64) + return strconv.FormatFloat(t.Price[p.FirstCurrency][p.SecondCurrency][tickerType].Low, 'f', -1, 64) case "bid": - return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].Bid, 'f', -1, 64) + return strconv.FormatFloat(t.Price[p.FirstCurrency][p.SecondCurrency][tickerType].Bid, 'f', -1, 64) case "ask": - return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].Ask, 'f', -1, 64) + return strconv.FormatFloat(t.Price[p.FirstCurrency][p.SecondCurrency][tickerType].Ask, 'f', -1, 64) case "volume": - return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].Volume, 'f', -1, 64) + return strconv.FormatFloat(t.Price[p.FirstCurrency][p.SecondCurrency][tickerType].Volume, 'f', -1, 64) case "ath": - return strconv.FormatFloat(t.Price[p.GetFirstCurrency()][p.GetSecondCurrency()].PriceATH, 'f', -1, 64) + return strconv.FormatFloat(t.Price[p.FirstCurrency][p.SecondCurrency][tickerType].PriceATH, 'f', -1, 64) default: return "" } } -func GetTicker(exchange string, p pair.CurrencyPair) (TickerPrice, error) { +// GetTicker checks and returns a requested ticker if it exists +func GetTicker(exchange string, p pair.CurrencyPair, tickerType string) (Price, error) { ticker, err := GetTickerByExchange(exchange) if err != nil { - return TickerPrice{}, err + return Price{}, err } - if !FirstCurrencyExists(exchange, p.GetFirstCurrency()) { - return TickerPrice{}, errors.New(ErrPrimaryCurrencyNotFound) + if !FirstCurrencyExists(exchange, p.FirstCurrency) { + return Price{}, errors.New(ErrPrimaryCurrencyNotFound) } if !SecondCurrencyExists(exchange, p) { - return TickerPrice{}, errors.New(ErrSecondaryCurrencyNotFound) + return Price{}, errors.New(ErrSecondaryCurrencyNotFound) } - return ticker.Price[p.GetFirstCurrency()][p.GetSecondCurrency()], nil + return ticker.Price[p.FirstCurrency][p.SecondCurrency][tickerType], nil } +// GetTickerByExchange returns an exchange Ticker func GetTickerByExchange(exchange string) (*Ticker, error) { for _, y := range Tickers { if y.ExchangeName == exchange { @@ -81,6 +93,8 @@ func GetTickerByExchange(exchange string) (*Ticker, error) { return nil, errors.New(ErrTickerForExchangeNotFound) } +// FirstCurrencyExists checks to see if the first currency of the Price map +// exists func FirstCurrencyExists(exchange string, currency pair.CurrencyItem) bool { for _, y := range Tickers { if y.ExchangeName == exchange { @@ -92,6 +106,8 @@ func FirstCurrencyExists(exchange string, currency pair.CurrencyItem) bool { return false } +// SecondCurrencyExists checks to see if the second currency of the Price map +// exists func SecondCurrencyExists(exchange string, p pair.CurrencyPair) bool { for _, y := range Tickers { if y.ExchangeName == exchange { @@ -105,40 +121,49 @@ func SecondCurrencyExists(exchange string, p pair.CurrencyPair) bool { return false } -func CreateNewTicker(exchangeName string, p pair.CurrencyPair, tickerNew TickerPrice) Ticker { +// CreateNewTicker creates a new Ticker +func CreateNewTicker(exchangeName string, p pair.CurrencyPair, tickerNew Price, tickerType string) Ticker { ticker := Ticker{} ticker.ExchangeName = exchangeName - ticker.Price = make(map[pair.CurrencyItem]map[pair.CurrencyItem]TickerPrice) - sMap := make(map[pair.CurrencyItem]TickerPrice) - sMap[p.GetSecondCurrency()] = tickerNew - ticker.Price[p.GetFirstCurrency()] = sMap + ticker.Price = make(map[pair.CurrencyItem]map[pair.CurrencyItem]map[string]Price) + a := make(map[pair.CurrencyItem]map[string]Price) + b := make(map[string]Price) + b[tickerType] = tickerNew + a[p.SecondCurrency] = b + ticker.Price[p.FirstCurrency] = a Tickers = append(Tickers, ticker) return ticker } -func ProcessTicker(exchangeName string, p pair.CurrencyPair, tickerNew TickerPrice) { +// ProcessTicker processes incoming tickers, creating or updating the Tickers +// list +func ProcessTicker(exchangeName string, p pair.CurrencyPair, tickerNew Price, tickerType string) { tickerNew.CurrencyPair = p.Pair().String() if len(Tickers) == 0 { - CreateNewTicker(exchangeName, p, tickerNew) - //issue - not appending + CreateNewTicker(exchangeName, p, tickerNew, tickerType) return - } else { - ticker, err := GetTickerByExchange(exchangeName) - if err != nil { - CreateNewTicker(exchangeName, p, tickerNew) - return - } + } - if FirstCurrencyExists(exchangeName, p.GetFirstCurrency()) { - if !SecondCurrencyExists(exchangeName, p) { - second := ticker.Price[p.GetFirstCurrency()] - second[p.GetSecondCurrency()] = tickerNew - ticker.Price[p.GetFirstCurrency()] = second - return - } + ticker, err := GetTickerByExchange(exchangeName) + if err != nil { + CreateNewTicker(exchangeName, p, tickerNew, tickerType) + return + } + + if FirstCurrencyExists(exchangeName, p.FirstCurrency) { + if !SecondCurrencyExists(exchangeName, p) { + a := ticker.Price[p.FirstCurrency] + b := make(map[string]Price) + b[tickerType] = tickerNew + a[p.SecondCurrency] = b + ticker.Price[p.FirstCurrency] = a + return } - sMap := make(map[pair.CurrencyItem]TickerPrice) - sMap[p.GetSecondCurrency()] = tickerNew - ticker.Price[p.GetFirstCurrency()] = sMap } + + a := make(map[pair.CurrencyItem]map[string]Price) + b := make(map[string]Price) + b[tickerType] = tickerNew + a[p.SecondCurrency] = b + ticker.Price[p.FirstCurrency] = a } diff --git a/exchanges/ticker/ticker_test.go b/exchanges/ticker/ticker_test.go index 789a751b0bf..eb7c8b91119 100644 --- a/exchanges/ticker/ticker_test.go +++ b/exchanges/ticker/ticker_test.go @@ -9,7 +9,7 @@ import ( func TestPriceToString(t *testing.T) { newPair := pair.NewCurrencyPair("BTC", "USD") - priceStruct := TickerPrice{ + priceStruct := Price{ Pair: newPair, CurrencyPair: newPair.Pair().String(), Last: 1200, @@ -21,37 +21,37 @@ func TestPriceToString(t *testing.T) { PriceATH: 1337, } - newTicker := CreateNewTicker("ANX", newPair, priceStruct) + newTicker := CreateNewTicker("ANX", newPair, priceStruct, Spot) - if newTicker.PriceToString(newPair, "last") != "1200" { + if newTicker.PriceToString(newPair, "last", Spot) != "1200" { t.Error("Test Failed - ticker PriceToString last value is incorrect") } - if newTicker.PriceToString(newPair, "high") != "1298" { + if newTicker.PriceToString(newPair, "high", Spot) != "1298" { t.Error("Test Failed - ticker PriceToString high value is incorrect") } - if newTicker.PriceToString(newPair, "low") != "1148" { + if newTicker.PriceToString(newPair, "low", Spot) != "1148" { t.Error("Test Failed - ticker PriceToString low value is incorrect") } - if newTicker.PriceToString(newPair, "bid") != "1195" { + if newTicker.PriceToString(newPair, "bid", Spot) != "1195" { t.Error("Test Failed - ticker PriceToString bid value is incorrect") } - if newTicker.PriceToString(newPair, "ask") != "1220" { + if newTicker.PriceToString(newPair, "ask", Spot) != "1220" { t.Error("Test Failed - ticker PriceToString ask value is incorrect") } - if newTicker.PriceToString(newPair, "volume") != "5" { + if newTicker.PriceToString(newPair, "volume", Spot) != "5" { t.Error("Test Failed - ticker PriceToString volume value is incorrect") } - if newTicker.PriceToString(newPair, "ath") != "1337" { + if newTicker.PriceToString(newPair, "ath", Spot) != "1337" { t.Error("Test Failed - ticker PriceToString ath value is incorrect") } - if newTicker.PriceToString(newPair, "obtuse") != "" { + if newTicker.PriceToString(newPair, "obtuse", Spot) != "" { t.Error("Test Failed - ticker PriceToString obtuse value is incorrect") } } func TestGetTicker(t *testing.T) { newPair := pair.NewCurrencyPair("BTC", "USD") - priceStruct := TickerPrice{ + priceStruct := Price{ Pair: newPair, CurrencyPair: newPair.Pair().String(), Last: 1200, @@ -63,21 +63,30 @@ func TestGetTicker(t *testing.T) { PriceATH: 1337, } - bitfinexTicker := CreateNewTicker("bitfinex", newPair, priceStruct) - Tickers = append(Tickers, bitfinexTicker) - - tickerPrice, err := GetTicker("bitfinex", newPair) + ProcessTicker("bitfinex", newPair, priceStruct, Spot) + tickerPrice, err := GetTicker("bitfinex", newPair, Spot) if err != nil { t.Errorf("Test Failed - Ticker GetTicker init error: %s", err) } if tickerPrice.CurrencyPair != "BTCUSD" { t.Error("Test Failed - ticker tickerPrice.CurrencyPair value is incorrect") } + + priceStruct.PriceATH = 9001 + ProcessTicker("bitfinex", newPair, priceStruct, "futures_3m") + tickerPrice, err = GetTicker("bitfinex", newPair, "futures_3m") + if err != nil { + t.Errorf("Test Failed - Ticker GetTicker init error: %s", err) + } + + if tickerPrice.PriceATH != 9001 { + t.Error("Test Failed - ticker tickerPrice.PriceATH value is incorrect") + } } func TestGetTickerByExchange(t *testing.T) { newPair := pair.NewCurrencyPair("BTC", "USD") - priceStruct := TickerPrice{ + priceStruct := Price{ Pair: newPair, CurrencyPair: newPair.Pair().String(), Last: 1200, @@ -89,7 +98,7 @@ func TestGetTickerByExchange(t *testing.T) { PriceATH: 1337, } - anxTicker := CreateNewTicker("ANX", newPair, priceStruct) + anxTicker := CreateNewTicker("ANX", newPair, priceStruct, Spot) Tickers = append(Tickers, anxTicker) tickerPtr, err := GetTickerByExchange("ANX") @@ -103,7 +112,7 @@ func TestGetTickerByExchange(t *testing.T) { func TestFirstCurrencyExists(t *testing.T) { newPair := pair.NewCurrencyPair("BTC", "USD") - priceStruct := TickerPrice{ + priceStruct := Price{ Pair: newPair, CurrencyPair: newPair.Pair().String(), Last: 1200, @@ -115,7 +124,7 @@ func TestFirstCurrencyExists(t *testing.T) { PriceATH: 1337, } - alphaTicker := CreateNewTicker("alphapoint", newPair, priceStruct) + alphaTicker := CreateNewTicker("alphapoint", newPair, priceStruct, Spot) Tickers = append(Tickers, alphaTicker) if !FirstCurrencyExists("alphapoint", "BTC") { @@ -130,7 +139,7 @@ func TestSecondCurrencyExists(t *testing.T) { t.Parallel() newPair := pair.NewCurrencyPair("BTC", "USD") - priceStruct := TickerPrice{ + priceStruct := Price{ Pair: newPair, CurrencyPair: newPair.Pair().String(), Last: 1200, @@ -142,7 +151,7 @@ func TestSecondCurrencyExists(t *testing.T) { PriceATH: 1337, } - bitstampTicker := CreateNewTicker("bitstamp", newPair, priceStruct) + bitstampTicker := CreateNewTicker("bitstamp", newPair, priceStruct, "SPOT") Tickers = append(Tickers, bitstampTicker) if !SecondCurrencyExists("bitstamp", newPair) { @@ -157,7 +166,7 @@ func TestSecondCurrencyExists(t *testing.T) { func TestCreateNewTicker(t *testing.T) { newPair := pair.NewCurrencyPair("BTC", "USD") - priceStruct := TickerPrice{ + priceStruct := Price{ Pair: newPair, CurrencyPair: newPair.Pair().String(), Last: 1200, @@ -169,7 +178,7 @@ func TestCreateNewTicker(t *testing.T) { PriceATH: 1337, } - newTicker := CreateNewTicker("ANX", newPair, priceStruct) + newTicker := CreateNewTicker("ANX", newPair, priceStruct, Spot) if reflect.ValueOf(newTicker).NumField() != 2 { t.Error("Test Failed - ticker CreateNewTicker struct change/or updated") @@ -181,38 +190,38 @@ func TestCreateNewTicker(t *testing.T) { t.Error("Test Failed - ticker CreateNewTicker.ExchangeName value is not ANX") } - if newTicker.Price["BTC"]["USD"].Pair.Pair().String() != "BTCUSD" { + if newTicker.Price["BTC"]["USD"][Spot].Pair.Pair().String() != "BTCUSD" { t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Pair.Pair().String() value is not expected 'BTCUSD'") } - if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Ask).String() != "float64" { + if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].Ask).String() != "float64" { t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Ask value is not a float64") } - if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Bid).String() != "float64" { + if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].Bid).String() != "float64" { t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Bid value is not a float64") } - if reflect.TypeOf(newTicker.Price["BTC"]["USD"].CurrencyPair).String() != "string" { + if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].CurrencyPair).String() != "string" { t.Error("Test Failed - ticker newTicker.Price[BTC][USD].CurrencyPair value is not a string") } - if reflect.TypeOf(newTicker.Price["BTC"]["USD"].High).String() != "float64" { + if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].High).String() != "float64" { t.Error("Test Failed - ticker newTicker.Price[BTC][USD].High value is not a float64") } - if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Last).String() != "float64" { + if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].Last).String() != "float64" { t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Last value is not a float64") } - if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Low).String() != "float64" { + if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].Low).String() != "float64" { t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Low value is not a float64") } - if reflect.TypeOf(newTicker.Price["BTC"]["USD"].PriceATH).String() != "float64" { + if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].PriceATH).String() != "float64" { t.Error("Test Failed - ticker newTicker.Price[BTC][USD].PriceATH value is not a float64") } - if reflect.TypeOf(newTicker.Price["BTC"]["USD"].Volume).String() != "float64" { + if reflect.TypeOf(newTicker.Price["BTC"]["USD"][Spot].Volume).String() != "float64" { t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Volume value is not a float64") } } func TestProcessTicker(t *testing.T) { //non-appending function to tickers newPair := pair.NewCurrencyPair("BTC", "USD") - priceStruct := TickerPrice{ + priceStruct := Price{ Pair: newPair, CurrencyPair: newPair.Pair().String(), Last: 1200, @@ -224,5 +233,5 @@ func TestProcessTicker(t *testing.T) { //non-appending function to tickers PriceATH: 1337, } - ProcessTicker("btcc", newPair, priceStruct) + ProcessTicker("btcc", newPair, priceStruct, Spot) } diff --git a/main.go b/main.go index 08a6b9d896e..97b9dbfd50a 100644 --- a/main.go +++ b/main.go @@ -191,7 +191,7 @@ func main() { go WebsocketHandler() go TickerUpdaterRoutine() - go OrderbookUpdaterRoutine() + //go OrderbookUpdaterRoutine() if bot.config.Webserver.Enabled { err := bot.config.CheckWebserverConfigValues() diff --git a/routines.go b/routines.go index 51cbd6579e0..0da929feeba 100644 --- a/routines.go +++ b/routines.go @@ -1,12 +1,50 @@ package main import ( + "fmt" "log" "time" + "github.com/thrasher-/gocryptotrader/currency/pair" exchange "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) +func printSummary(result ticker.Price, p pair.CurrencyPair, assetType, exchangeName string, err error) { + if err != nil { + log.Printf("failed to get %s %s ticker. Error: %s", + p.Pair().String(), + exchangeName, + err) + return + } + + log.Printf("%s %s %s: Last %.8f Ask %.8f Bid %.8f High %.8f Low %.8f Volume %.8f", + exchangeName, + exchange.FormatCurrency(p).String(), + assetType, + result.Last, + result.Ask, + result.Bid, + result.High, + result.Low, + result.Volume) +} + +func relayWebsocketEvent(result interface{}, event, assetType, exchangeName string) { + evt := WebsocketEvent{ + Data: result, + Event: event, + AssetType: assetType, + Exchange: exchangeName, + } + err := BroadcastWebsocketMessage(evt) + if err != nil { + log.Println(fmt.Errorf("Failed to broadcast websocket event. Error: %s", + err)) + } +} + func TickerUpdaterRoutine() { log.Println("Starting ticker updater routine") for { @@ -15,30 +53,34 @@ func TickerUpdaterRoutine() { exchangeName := bot.exchanges[x].GetName() enabledCurrencies := bot.exchanges[x].GetEnabledCurrencies() + var result ticker.Price + var err error + var assetTypes []string + for y := range enabledCurrencies { currency := enabledCurrencies[y] - result, err := bot.exchanges[x].UpdateTicker(currency) + assetTypes, err = exchange.GetExchangeAssetTypes(exchangeName) if err != nil { - log.Printf("failed to get %s ticker", currency.Pair().String()) - continue + log.Printf("failed to get %s exchange asset types. Error: %s", + exchangeName, err) } - - log.Printf("%s %s: Last %.8f Ask %.8f Bid %.8f High %.8f Low %.8f Volume %.8f", - exchangeName, - exchange.FormatCurrency(currency).String(), - result.Last, - result.Ask, - result.Bid, - result.High, - result.Low, - result.Volume) - - evt := WebsocketEvent{ - Data: result, - Event: "ticker_update", - Exchange: exchangeName, + if len(assetTypes) > 1 { + for z := range assetTypes { + result, err = bot.exchanges[x].UpdateTicker(currency, + assetTypes[z]) + printSummary(result, currency, assetTypes[z], exchangeName, err) + if err == nil { + relayWebsocketEvent(result, "ticker_update", assetTypes[z], exchangeName) + } + } + } else { + result, err = bot.exchanges[x].UpdateTicker(currency, + assetTypes[0]) + printSummary(result, currency, assetTypes[0], exchangeName, err) + if err == nil { + relayWebsocketEvent(result, "ticker_update", assetTypes[0], exchangeName) + } } - BroadcastWebsocketMessage(evt) } } } @@ -52,6 +94,11 @@ func OrderbookUpdaterRoutine() { for x := range bot.exchanges { if bot.exchanges[x].IsEnabled() { exchangeName := bot.exchanges[x].GetName() + + if exchangeName == "ANX" { + continue + } + enabledCurrencies := bot.exchanges[x].GetEnabledCurrencies() for y := range enabledCurrencies { diff --git a/testdata/configtest.dat b/testdata/configtest.dat index 48c98e847d4..e894e05e3b6 100644 --- a/testdata/configtest.dat +++ b/testdata/configtest.dat @@ -65,6 +65,7 @@ "AvailablePairs": "BTCUSD,BTCHKD,BTCEUR,BTCCAD,BTCAUD,BTCSGD,BTCJPY,BTCGBP,BTCNZD,LTCBTC,DOGEBTC,STRBTC,XRPBTC", "EnabledPairs": "BTCUSD,BTCHKD,BTCEUR,BTCCAD,BTCAUD,BTCSGD,BTCJPY,BTCGBP,BTCNZD,LTCBTC,DOGEBTC,STRBTC,XRPBTC", "BaseCurrencies": "USD,HKD,EUR,CAD,AUD,SGD,JPY,GBP,NZD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true, "Index": "BTC" @@ -86,6 +87,7 @@ "AvailablePairs": "BTCUSD,LTCUSD,LTCBTC,ETHUSD,ETHBTC,ETCBTC,ETCUSD,RRTUSD,RRTBTC,ZECUSD,ZECBTC,XMRUSD,XMRBTC,DSHUSD,DSHBTC,BCCBTC,BCUBTC,BCCUSD,BCUUSD,XRPUSD,XRPBTC,IOTUSD,IOTBTC,IOTETH,EOSUSD,EOSBTC,EOSETH,SANUSD,SANBTC,SANETH,OMGUSD,OMGBTC,OMGETH,BCHUSD,BCHBTC,BCHETH", "EnabledPairs": "BTCUSD,LTCUSD,LTCBTC,ETHUSD,ETHBTC", "BaseCurrencies": "USD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -106,6 +108,7 @@ "AvailablePairs": "BTCUSD,BTCEUR,EURUSD,XRPUSD,XRPEUR", "EnabledPairs": "BTCUSD,BTCEUR,EURUSD,XRPUSD,XRPEUR", "BaseCurrencies": "USD,EUR", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -125,6 +128,7 @@ "AvailablePairs": "BTC-LTC,BTC-DOGE,BTC-VTC,BTC-PPC,BTC-FTC,BTC-RDD,BTC-NXT,BTC-DASH,BTC-POT,BTC-BLK,BTC-EMC2,BTC-XMY,BTC-AUR,BTC-EFL,BTC-GLD,BTC-SLR,BTC-PTC,BTC-GRS,BTC-NLG,BTC-RBY,BTC-XWC,BTC-MONA,BTC-THC,BTC-ENRG,BTC-ERC,BTC-VRC,BTC-CURE,BTC-XBB,BTC-XMR,BTC-CLOAK,BTC-START,BTC-KORE,BTC-XDN,BTC-TRUST,BTC-NAV,BTC-XST,BTC-BTCD,BTC-VIA,BTC-UNO,BTC-PINK,BTC-IOC,BTC-CANN,BTC-SYS,BTC-NEOS,BTC-DGB,BTC-BURST,BTC-EXCL,BTC-SWIFT,BTC-DOPE,BTC-BLOCK,BTC-ABY,BTC-BYC,BTC-XMG,BTC-BLITZ,BTC-BAY,BTC-BTS,BTC-FAIR,BTC-SPR,BTC-VTR,BTC-XRP,BTC-GAME,BTC-COVAL,BTC-NXS,BTC-XCP,BTC-BITB,BTC-GEO,BTC-FLDC,BTC-GRC,BTC-FLO,BTC-NBT,BTC-MUE,BTC-XEM,BTC-CLAM,BTC-DMD,BTC-GAM,BTC-SPHR,BTC-OK,BTC-SN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C-MYST,ETH-MYST,BTC-CFI,ETH-CFI,BTC-BNT,ETH-BNT,BTC-NMR,ETH-NMR,ETH-TIME,ETH-LTC,ETH-XRP,BTC-SNT,ETH-SNT,BTC-DCT,BTC-XEL,BTC-MCO,ETH-MCO,BTC-ADT,ETH-ADT,BTC-FUN,ETH-FUN,BTC-PAY,ETH-PAY,BTC-MTL,ETH-MTL,BTC-STORJ,ETH-STORJ,BTC-ADX,ETH-ADX,ETH-DASH,ETH-SC,ETH-ZEC,USDT-ZEC,USDT-LTC,USDT-ETC,USDT-XRP,BTC-OMG,ETH-OMG,BTC-CVC,ETH-CVC,BTC-PART,BTC-QTUM,ETH-QTUM,ETH-XMR,ETH-XEM,ETH-XLM,ETH-NEO,USDT-XMR,USDT-DASH,ETH-BCC,USDT-BCC,BTC-BCC,USDT-NEO,ETH-WAVES,ETH-STRAT,ETH-DGB,ETH-FCT,ETH-BTS", "EnabledPairs": "USDT-BTC", "BaseCurrencies": "USD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true, "Delimiter": "-" @@ -146,6 +150,7 @@ "AvailablePairs": "BTCCNY,LTCCNY,LTCBTC", "EnabledPairs": "BTCCNY,LTCCNY,LTCBTC", "BaseCurrencies": "CNY", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -165,6 +170,7 @@ "AvailablePairs": "BTCUSD,BTCRUR,BTCEUR,LTCBTC,LTCUSD,LTCRUR,LTCEUR,NMCBTC,NMCUSD,NVCBTC,NVCUSD,USDRUR,EURUSD,EURRUR,PPCBTC,PPCUSD", "EnabledPairs": "BTCUSD,BTCRUR,BTCEUR,LTCBTC,LTCUSD,LTCRUR,LTCEUR,NMCBTC,NMCUSD,NVCBTC,NVCUSD,USDRUR,EURUSD,EURRUR,PPCBTC,PPCUSD", "BaseCurrencies": "USD,RUR,EUR", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -186,6 +192,7 @@ "AvailablePairs": "LTCAUD,BTCAUD", "EnabledPairs": "LTCAUD,BTCAUD", "BaseCurrencies": "AUD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -206,6 +213,7 @@ "AvailablePairs": "LTCEUR,LTCBTC,BTCGBP,BTCEUR,ETHEUR,ETHBTC,LTCUSD,BTCUSD,ETHUSD", "EnabledPairs": "BTCUSD,BTCGBP,BTCEUR", "BaseCurrencies": "USD,GBP,EUR", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -226,6 +234,7 @@ "AvailablePairs": "BTCUSD,ETHBTC,ETHUSD", "EnabledPairs": "BTCUSD", "BaseCurrencies": "USD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -245,6 +254,7 @@ "AvailablePairs": "BTCCNY,LTCCNY", "EnabledPairs": "BTCCNY,LTCCNY", "BaseCurrencies": "CNY", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -265,6 +275,7 @@ "AvailablePairs": "XBTUSD,XBTSGD,XBTEUR", "EnabledPairs": "XBTUSD,XBTSGD,XBTEUR", "BaseCurrencies": "USD,SGD,EUR", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -281,9 +292,10 @@ "AuthenticatedAPISupport": false, "APIKey": "Key", "APISecret": "Secret", - "AvailablePairs": "REPETH,ZECXBT,ETCUSD,ETHCAD,ETCEUR,ETHXBT.D,XBTJPY.D,EOSXBT,USDTUSD,LTCEUR,XBTUSD,ETHUSD,XBTEUR.D,BCHEUR,GNOXBT,ICNXBT,XBTEUR,ZECUSD,ETCXBT,ICNETH,LTCXBT,XRPXBT,ZECEUR,DASHUSD,ETHEUR.D,ETHJPY.D,LTCUSD,XMRXBT,BCHXBT,ETHJPY,GNOETH,XDGXBT,ETHCAD.D,XRPUSD,ETHEUR,XMRUSD,MLNETH,REPEUR,XBTCAD.D,XRPEUR,BCHUSD,ETHXBT,XBTJPY,XBTUSD.D,XLMXBT,DASHXBT,XBTGBP.D,MLNXBT,REPXBT,XBTCAD,DASHEUR,ETHGBP.D,ETHUSD.D,XMREUR,EOSETH,ETCETH", + "AvailablePairs": "ETHEUR,XRPXBT,BCHXBT,DASHUSD,EOSETH,REPXBT,XBTUSD.D,XLMXBT,ETHGBP.D,XMRXBT,GNOXBT,ETHUSD,ETCXBT,ETHEUR.D,ICNXBT,XBTJPY.D,XRPUSD,BCHEUR,DASHXBT,ETHCAD,ZECUSD,ICNETH,MLNETH,XDGXBT,GNOETH,LTCUSD,XBTCAD,XBTEUR,ZECXBT,BCHUSD,DASHEUR,EOSXBT,USDTUSD,ETCUSD,ETHXBT,ETHXBT.D,XBTJPY,XBTCAD.D,XRPEUR,LTCXBT,REPETH,XBTGBP.D,REPEUR,XMRUSD,ETHCAD.D,ETHJPY,ETHJPY.D,ETCETH,XBTEUR.D,XBTGBP,LTCEUR,MLNXBT,XBTUSD,XMREUR,ZECEUR,ETCEUR,ETHGBP,ETHUSD.D", "EnabledPairs": "ETCUSD,XBTUSD,ETHUSD", "BaseCurrencies": "EUR,USD,CAD,GBP,JPY", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -304,6 +316,7 @@ "AvailablePairs": "BTCUSD,BTCEUR,USDHKD,AUDUSD,BTCGBP,BTCNZD,USDJPY,BTCSGD,BTCNGN,EURUSD,USDSGD,NZDUSD,USDNGN,USDCHF,BTCJPY,BTCAUD,BTCCAD,BTCCHF,GBPUSD,USDCAD", "EnabledPairs": "BTCUSD,BTCAUD", "BaseCurrencies": "USD,EUR,HKD,AUD,GBP,NZD,JPY,SGD,NGN,CHF,CAD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -320,9 +333,10 @@ "AuthenticatedAPISupport": false, "APIKey": "Key", "APISecret": "Secret", - "AvailablePairs": "XID_BTC,OAX_ETH,LTC_BTC,TIME_BTC,GNT_ET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T,TNT_BTC,WAVES_BTC,GUP_ETH,BCAP_ETH,BNT_BTC,BNT_USDT,SNT_ETH,XID_BTC,DGD_BTC,ICN_ETH,DGD_ETH,LTC_USDT,TIME_USDT,REP_ETH,ANT_ETH,BAT_ETH,ADX_ETH,SAN_BTC,ICN_BTC,QTUM_BTC,MGO_ETH,MYST_USDT,EOS_BTC,OMG_USDT,OAX_BTC,MLN_BTC,TAAS_BTC,WINGS_BTC,SNGLS_BTC,CFI_USDT,SNM_BTC,EOS_ETH,STX_ETH,QRL_ETH,CFI_ETH,STORJ_USDT,SAN_USDT,DNT_USDT,LTC_ETH,VSL_USDT,WAVES_USDT,TRST_USDT,PTOY_USDT,ETH_USDT,GUP_USDT,PAY_ETH,OMG_BTC,INCNT_BTC,CVC_ETH,GNT_ETH,REP_BTC,GNO_USDT,LUN_BTC,MYST_BTC,SNGLS_USDT,QTUM_ETH,PLU_BTC,BCC_USDT,BCAP_USDT,ANT_BTC,BAT_USDT,QRL_USDT,CVC_USDT,DNT_ETH,STX_BTC,EDG_ETH,TNT_ETH", "EnabledPairs": "ETH_BTC,LTC_BTC,DASH_BTC", "BaseCurrencies": "USD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true, "Delimiter": "_" @@ -345,6 +359,7 @@ "AvailablePairs": "BTCARS,BTCAUD,BTCBRL,BTCCAD,BTCCHF,BTCCZK,BTCDKK,BTCEUR,BTCGBP,BTCHKD,BTCILS,BTCINR,BTCMXN,BTCNOK,BTCNZD,BTCPLN,BTCRUB,BTCSEK,BTCSGD,BTCTHB,BTCUSD,BTCZAR", "EnabledPairs": "BTCARS,BTCAUD,BTCBRL,BTCCAD,BTCCHF,BTCCZK,BTCDKK,BTCEUR,BTCGBP,BTCHKD,BTCILS,BTCINR,BTCMXN,BTCNOK,BTCNZD,BTCPLN,BTCRUB,BTCSEK,BTCSGD,BTCTHB,BTCUSD,BTCZAR", "BaseCurrencies": "ARS,AUD,BRL,CAD,CHF,CZK,DKK,EUR,GBP,HKD,ILS,INR,MXN,NOK,NZD,PLN,RUB,SEK,SGD,THB,USD,ZAR", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -364,6 +379,7 @@ "AvailablePairs": "BTCCNY,LTCCNY", "EnabledPairs": "BTCCNY,LTCCNY", "BaseCurrencies": "CNY", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -384,6 +400,7 @@ "AvailablePairs": "BTCUSD,LTCUSD", "EnabledPairs": "BTCUSD,LTCUSD", "BaseCurrencies": "USD", + "AssetTypes": "SPOT,this_week,next_week,quarter", "ConfigCurrencyPairFormat": { "Uppercase": true }, @@ -404,6 +421,7 @@ "AvailablePairs": "BTC_XUSD,BTC_FCT,BTC_MMNXT,BTC_NMC,BTC_BITUSD,BTC_RDD,BTC_XMR,BTC_XST,BTC_DSH,BTC_MAID,BTC_DGB,BTC_NEOS,BTC_BLK,BTC_NAUT,BTC_NBT,BTC_XCP,BTC_STR,BTC_BTCD,BTC_GRC,BTC_HUC,BTC_BBR,BTC_XDN,BTC_INDEX,BTC_IOC,BTC_SWARM,BTC_EMC2,BTC_MCN,BTC_NOXT,BTC_MINT,BTC_PTS,BTC_SC,BTC_GEO,BTC_XRP,BTC_FLO,BTC_BITS,BTC_HYP,BTC_XCR,BTC_LTBC,BTC_SYS,BTC_GMC,BTC_ETH,BTC_SYNC,BTC_GAP,BTC_BCN,BTC_C2,BTC_PINK,BTC_FIBRE,BTC_POT,BTC_QTL,BTC_SDC,BTC_XC,BTC_DASH,BTC_SILK,BTC_CLAM,BTC_NAV,BTC_PIGGY,BTC_BCY,BTC_MIL,BTC_XCN,BTC_YACC,BTC_BTS,BTC_QBK,BTC_SJCX,BTC_LQD,BTC_BURST,BTC_RIC,BTC_VRC,BTC_LTC,BTC_XPB,BTC_GRS,BTC_XCH,BTC_ARCH,BTC_QORA,BTC_HZ,BTC_NSR,BTC_XPM,BTC_BITCNY,BTC_EXE,BTC_XMG,BTC_BTC,BTC_BTM,BTC_NOBL,BTC_NXT,BTC_DOGE,BTC_CURE,BTC_MNTA,BTC_ADN,BTC_EXP,BTC_VTC,BTC_FLDC,BTC_MRS,BTC_MYR,BTC_OMNI,BTC_VNL,BTC_USDT,BTC_NOTE,BTC_WDC,BTC_BELA,BTC_VIA,BTC_CGA,BTC_DIEM,BTC_IFC,BTC_XDP,BTC_BLOCK,BTC_MMC,BTC_1CR,BTC_UNITY,BTC_XBC,BTC_GEMZ,BTC_FLT,BTC_PPC,BTC_XEM,BTC_RBY,BTC_CNMT,BTC_ABY,XMR_XDN,XMR_IFC,XMR_DIEM,XMR_BBR,XMR_DSH,XMR_BCN,XMR_LTC,XMR_MAID,XMR_DASH,XMR_BTCD,XMR_HYP,XMR_BLK,XMR_QORA,XMR_MNTA,XMR_NXT,USDT_BTC,USDT_ETH,USDT_XRP,USDT_DASH,USDT_LTC,USDT_NXT,USDT_XMR,USDT_STR", "EnabledPairs": "BTC_LTC,BTC_ETH,BTC_DOGE,BTC_DASH,BTC_XRP", "BaseCurrencies": "USD", + "AssetTypes": "SPOT", "ConfigCurrencyPairFormat": { "Uppercase": true, "Delimiter": "_" diff --git a/ticker_routes.go b/ticker_routes.go index 7da2a1a75fd..7c49949c35e 100644 --- a/ticker_routes.go +++ b/ticker_routes.go @@ -7,17 +7,19 @@ import ( "github.com/gorilla/mux" "github.com/thrasher-/gocryptotrader/currency/pair" + exchange "github.com/thrasher-/gocryptotrader/exchanges" "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) -func GetSpecificTicker(currency, exchangeName string) (ticker.TickerPrice, error) { - var specificTicker ticker.TickerPrice +func GetSpecificTicker(currency, exchangeName, assetType string) (ticker.Price, error) { + var specificTicker ticker.Price var err error for i := 0; i < len(bot.exchanges); i++ { if bot.exchanges[i] != nil { if bot.exchanges[i].IsEnabled() && bot.exchanges[i].GetName() == exchangeName { specificTicker, err = bot.exchanges[i].GetTickerPrice( pair.NewCurrencyPairFromString(currency), + assetType, ) break } @@ -30,7 +32,12 @@ func jsonTickerResponse(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) currency := vars["currency"] exchange := vars["exchangeName"] - response, err := GetSpecificTicker(currency, exchange) + assetType := vars["assetType"] + + if assetType == "" { + assetType = ticker.Spot + } + response, err := GetSpecificTicker(currency, exchange, assetType) if err != nil { log.Printf("Failed to fetch ticker for %s currency: %s\n", exchange, currency) @@ -51,8 +58,8 @@ type AllEnabledExchangeCurrencies struct { // EnabledExchangeCurrencies is a sub type for singular exchanges and respective // currencies type EnabledExchangeCurrencies struct { - ExchangeName string `json:"exchangeName"` - ExchangeValues []ticker.TickerPrice `json:"exchangeValues"` + ExchangeName string `json:"exchangeName"` + ExchangeValues []ticker.Price `json:"exchangeValues"` } func GetAllActiveTickers() []EnabledExchangeCurrencies { @@ -61,16 +68,36 @@ func GetAllActiveTickers() []EnabledExchangeCurrencies { for _, individualBot := range bot.exchanges { if individualBot != nil && individualBot.IsEnabled() { var individualExchange EnabledExchangeCurrencies - individualExchange.ExchangeName = individualBot.GetName() + exchangeName := individualBot.GetName() + individualExchange.ExchangeName = exchangeName log.Println( - "Getting enabled currencies for '" + individualBot.GetName() + "'", + "Getting enabled currencies for '" + exchangeName + "'", ) currencies := individualBot.GetEnabledCurrencies() - for x := range currencies { - currency := currencies[x] + for _, x := range currencies { + currency := x + assetTypes, err := exchange.GetExchangeAssetTypes(exchangeName) + if err != nil { + log.Printf("failed to get %s exchange asset types. Error: %s", + exchangeName, err) + continue + } + var tickerPrice ticker.Price + if len(assetTypes) > 1 { + for y := range assetTypes { + tickerPrice, err = individualBot.UpdateTicker(currency, + assetTypes[y]) + } + } else { + tickerPrice, err = individualBot.UpdateTicker(currency, + assetTypes[0]) + } - tickerPrice, err := individualBot.GetTickerPrice(currency) if err != nil { + log.Printf("failed to get %s %s ticker. Error: %s", + currency.Pair().String(), + exchangeName, + err) continue } diff --git a/websocket.go b/websocket.go index ccdb449971d..3086216aef9 100644 --- a/websocket.go +++ b/websocket.go @@ -32,9 +32,10 @@ type WebsocketClient struct { } type WebsocketEvent struct { - Exchange string `json:"exchange,omitempty"` - Event string - Data interface{} + Exchange string `json:"exchange,omitempty"` + AssetType string `json:"assetType,omitempty"` + Event string + Data interface{} } type WebsocketEventResponse struct { @@ -44,8 +45,9 @@ type WebsocketEventResponse struct { } type WebsocketTickerRequest struct { - Exchange string `json:"exchangeName"` - Currency string `json:"currency"` + Exchange string `json:"exchangeName"` + Currency string `json:"currency"` + AssetType string `json:"assetType"` } var WebsocketClientHub []WebsocketClient @@ -243,7 +245,7 @@ func WebsocketHandler() { } data, err := GetSpecificTicker(tickerReq.Currency, - tickerReq.Exchange) + tickerReq.Exchange, tickerReq.AssetType) if err != nil { wsResp.Error = err.Error()