fhqvst / avanza

A JavaScript client for the unofficial Avanza API
MIT License
229 stars 59 forks source link

"Inactive order is on the way to market" #67

Open JakobWestergarden opened 2 years ago

JakobWestergarden commented 2 years ago

Sometimes, albeit very rarely, when my program sends a buy or sell order to Avanza, it will have the message "inaktiverad order är påväg till marknaden ("inactive order is on the way to market"). My bot works by switching states between buying or selling and therefore this is an issue, since an inactive order doesnt give an error message. Do you have any idea what causes this?

I have used the subscribe function for orders at accounts, but the only messages i have seen are "ACTIVE" and "DELETED". Since i do not know how to recreate the inactive order issue, i wonder if the subscribe to order also have an "INACTIVE" state aswell which i in that case can use accordingly to check if my buy or sell state should be updated?

JakobWestergarden commented 2 years ago

I have no idea how to recreate the issue, so i dont know either if there is a specific reply from the orderfunction when it is placed that lets us know it is inactive.

fhqvst commented 2 years ago

Hm, interesting. I'd suggest adding some simple logging of the raw JSON messages you send and receive (good to have either way), and perhaps we can figure it out that way.

JakobWestergarden commented 2 years ago

Hm, interesting. I'd suggest adding some simple logging of the raw JSON messages you send and receive (good to have either way), and perhaps we can figure it out that way.

Alright, i will start logging and see if i can recreate it, it only has happened once or twice in 2 weeks, so I wondered if someone here knew why it happened in order for me to recreate it and test it. Thanks anyways, i will get back if i figure out the problem!

ausrasul commented 2 years ago

Not a solution to your specific question, but there are situations where errors happens and cannot be predicted, like change in API or exchange disturbance. I suggest generalizing the problem instead of looking for each individual error. In your case, I would subscribe for orders, place an order and see if it is fulfilled. After timeout or any error, I'd delete the order. Like an emulated fill and kill, you can do other variants.

JakobWestergarden commented 2 years ago

Not a solution to your specific question, but there are situations where errors happens and cannot be predicted, like change in API or exchange disturbance. I suggest generalizing the problem instead of looking for each individual error. In your case, I would subscribe for orders, place an order and see if it is fulfilled. After timeout or any error, I'd delete the order. Like an emulated fill and kill, you can do other variants.

This is basically what i have done. However, if my order instantly gets matched on market (i sell to the highest in orderbook for example), it will not ping from the subscribe function, because it doesnt create a new order, it just instantly sells the stock. Since i was unaware of this issue before, i havent logged the JSON-response, and thus i dont know if it would give me a "INACTIVE" message when this problem happens. id: REDACTED, accountId: REDACTED, orderbook: { id: '5507', name: 'RNB RETAIL AND BRANDS', tickerSymbol: 'RNBS', marketPlaceName: 'Stockholmsbörsen', countryCode: 'SE', instrumentType: 'Aktie', tradable: true, volumeFactor: 1, currencyCode: 'SEK', flagCode: 'SE', urlName: 'rnb-retail-and-brands' }, currentVolume: 8, openVolume: null, price: 3.67, validDate: '2021-08-11', type: 'Köp', state: { value: 'Marknaden', description: 'Din order befinner sig på marknaden.', name: 'ACTIVE' }, action: 'DELETED', modifiable: true, deletable: true, sum: 29.36, visibleDate: null, orderDateTime: 1628681180602 }

this is what i logged from my subscribe to orders when an order was matched. Can anyone confirm or deny if: state: { value: 'Marknaden', description: 'Din order befinner sig på marknaden.', name: 'INACTIVE' }, can happen if an issue with traffic happens? Because that is the only way i can see if a order has had the issue or not.